1
2 /*
3 * variable typedef's
4 * Copyright (c) 2002-2006 by Mattias Hultgren <mattias_hultgren@tele2.se>
5 *
6 * See vartypes.h
7 */
8
9 #include "vartypes.h"
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <math.h>
13
uint64_to_char_rec(uint64 val,char * str,uint64 min_digits,uint32 digit)14 uint32 uint64_to_char_rec( uint64 val, char *str, uint64 min_digits, uint32 digit )
15 {
16 if( val != uint64(0) )
17 {
18 char tmp = '0' + char( val % uint64(10) );
19 uint32 pos = uint64_to_char_rec( val/uint64(10), str, min_digits, digit+1 );
20 str[pos] = tmp;
21 return pos+1;
22 }
23 else
24 {
25 if( digit >= min_digits )
26 return 0;
27
28 uint32 pos;
29 for( pos=0; pos < (min_digits-digit); pos++ )
30 str[pos] = '0';
31 return pos;
32 }
33 }
34
uint64_to_char(uint64 val,char * str,uint32 min_digits)35 void uint64_to_char( uint64 val, char *str, uint32 min_digits )
36 {
37 min_digits = min_digits ? min_digits : 1;
38 str[ uint64_to_char_rec( val, str, min_digits, 0 ) ] = '\0';
39 }
40
41 #ifdef DONT_HAVE_TRUNC
trunc(double value)42 double trunc(double value)
43 {
44 if( value < 0.0 )
45 return -floor( -value );
46 return floor( value );
47 }
48 #endif
49 #ifdef DONT_HAVE_LOG2
log2(double value)50 double log2(double value)
51 {
52 return ( log( value ) / log( 2.0 ) );
53 }
54 #endif
55
56 #if defined USE_FLOAT || USE_DOUBLE
57 extern const floatx PI = M_PI;
58 extern const floatx E = M_E;
59 #endif
60 #ifdef USE_LONG_DOUBLE
61 #ifdef M_PIl
62 const floatx PI = M_PIl;
63 #else
64 const floatx PI = M_PI;
65 #endif
66 #ifdef M_El
67 const floatx E = M_El;
68 #else
69 const floatx E = M_E;
70 #endif
71 #endif
72
73 class vartypes_check
74 {
75 public:
76 vartypes_check();
77
78 }check;
79
vartypes_check()80 vartypes_check::vartypes_check()
81 {
82 if(sizeof(int8) != 1)
83 {
84 printf("The int8 isn't 8 bits as it should, please correct it in file vartypes.h\n");
85 exit(-1);
86 }
87
88 if(sizeof(int16) != 2)
89 {
90 printf("The int16 isn't 16 bits as it should, please correct it in file vartypes.h\n");
91 exit(-1);
92 }
93
94 if(sizeof(int32) != 4)
95 {
96 printf("The int32 isn't 32 bits as it should, please correct it in file vartypes.h\n");
97 exit(-1);
98 }
99
100 if(sizeof(int64) != 8)
101 {
102 printf("The int64 isn't 64 bits as it should, please correct it in file vartypes.h\n");
103 exit(-1);
104 }
105 }
106