Added spec:commit task to commit changes to spec/ruby sources.
[rbx.git] / shotgun / lib / float.h
blobcc50d6cc30f9ad9cb7a9822270d59da957f88d94
1 #ifndef RBS_FLOAT_H
2 #define RBS_FLOAT_H
4 #include <math.h>
6 /* use IEEE 64bit values if not defined */
7 #ifndef FLT_RADIX
8 #define FLT_RADIX 2
9 #endif
10 #ifndef FLT_ROUNDS
11 #define FLT_ROUNDS 1
12 #endif
13 #ifndef DBL_MIN
14 #define DBL_MIN 2.2250738585072014e-308
15 #endif
16 #ifndef DBL_MAX
17 #define DBL_MAX 1.7976931348623157e+308
18 #endif
19 #ifndef DBL_MIN_EXP
20 #define DBL_MIN_EXP (-1021)
21 #endif
22 #ifndef DBL_MAX_EXP
23 #define DBL_MAX_EXP 1024
24 #endif
25 #ifndef DBL_MIN_10_EXP
26 #define DBL_MIN_10_EXP (-307)
27 #endif
28 #ifndef DBL_MAX_10_EXP
29 #define DBL_MAX_10_EXP 308
30 #endif
31 #ifndef DBL_DIG
32 #define DBL_DIG 15
33 #endif
34 #ifndef DBL_MANT_DIG
35 #define DBL_MANT_DIG 53
36 #endif
37 #ifndef DBL_EPSILON
38 #define DBL_EPSILON 2.2204460492503131e-16
39 #endif
40 /* End borrowing from MRI 1.8.6 stable */
42 OBJECT float_new(STATE, double dbl);
43 OBJECT float_from_string(STATE, char *str);
44 void float_into_string(STATE, OBJECT self, char *buf, int sz);
45 OBJECT float_coerce(STATE, OBJECT value);
46 OBJECT float_compare(STATE, double a, double b);
48 static inline int float_bounded_p(double value) {
49 if(value <= (double)FIXNUM_MAX && value >= (double)FIXNUM_MIN) {
50 return 1;
52 return 0;
55 static inline double float_truncate(double value) {
56 if(value > 0.0) {
57 return floor(value);
58 } else if(value < 0.0) {
59 return ceil(value);
61 return value;
64 #endif