source: golgotha/src/i4/math/num_type.hh

Last change on this file was 80, checked in by Sam Hocevar, 11 years ago
  • Adding the Golgotha source code. Not sure what's going to be interesting in there, but since it's all public domain, there's certainly stuff to pick up.
File size: 1.9 KB
Line 
1/********************************************************************** <BR>
2  This file is part of Crack dot Com's free source code release of
3  Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
4  information about compiling & licensing issues visit this URL</a>
5  <PRE> If that doesn't help, contact Jonathan Clark at
6  golgotha_source@usa.net (Subject should have "GOLG" in it)
7***********************************************************************/
8
9#ifndef __NUM_TYPE_HPP_
10#define __NUM_TYPE_HPP_
11
12#include "arch.hh"
13
14/*
15   Use i4_float instead of float so we can
16   substitute fixed point later on
17   */
18
19typedef float i4_float;
20typedef float i4_angle;   // stored in radians
21
22inline i4_float i4_fabs(const i4_float &x)
23{
24  if (x<0)
25    return -x;
26  else return x;
27}
28
29#ifdef WIN32
30inline sw32 i4_f_to_i(i4_float f)
31{
32  w16 i4_f_to_i_control_word_1;
33  w16 i4_f_to_i_control_word_2;
34  sw32 res;
35  __asm
36  {
37    fld f
38   
39    wait
40    fnstcw i4_f_to_i_control_word_1
41    wait
42
43    mov    ax,i4_f_to_i_control_word_1
44    or     ah,0xC
45    mov    word ptr i4_f_to_i_control_word_2,ax
46    fldcw  i4_f_to_i_control_word_2       
47    fistp  res
48    fldcw  i4_f_to_i_control_word_1
49  }
50  return res;
51}
52
53inline sw32 i4_s_to_i(double f)
54{
55  w16 i4_f_to_i_control_word_1;
56  w16 i4_f_to_i_control_word_2;
57  sw32 res;
58  __asm
59  {
60    fld qword ptr [f]
61   
62    fnstcw i4_f_to_i_control_word_1
63
64    mov    ax,i4_f_to_i_control_word_1
65    or     ah,0xC
66    mov    word ptr i4_f_to_i_control_word_2,ax
67    fldcw  i4_f_to_i_control_word_2       
68    fistp  res
69    fldcw  i4_f_to_i_control_word_1
70  }
71  return res;
72}
73
74#else
75
76#define i4_f_to_i(a) (sw32)(a)
77#define i4_d_to_i(a) (sw32)(a)
78
79#endif
80
81inline i4_float i4_interpolate(i4_float from, i4_float to, i4_float frac)
82{
83  return (to - from)*frac + from;
84}
85
86#endif
Note: See TracBrowser for help on using the repository browser.