4 /* Begin borrowing from MRI 1.8.6 stable */
5 #if defined(__FreeBSD__) && __FreeBSD__ < 4
6 #include <floatingpoint.h>
17 #include "shotgun/lib/shotgun.h"
18 #include "shotgun/lib/string.h"
19 #include "shotgun/lib/array.h"
20 #include "shotgun/lib/bignum.h"
21 #include "shotgun/lib/float.h"
23 int float_radix() { return FLT_RADIX
; }
24 int float_rounds() { return FLT_ROUNDS
; }
25 double float_min() { return DBL_MIN
; }
26 double float_max() { return DBL_MAX
; }
27 int float_min_exp() { return DBL_MIN_EXP
; }
28 int float_max_exp() { return DBL_MAX_EXP
; }
29 int float_min_10_exp() { return DBL_MIN_10_EXP
; }
30 int float_max_10_exp() { return DBL_MAX_10_EXP
; }
31 int float_dig() { return DBL_DIG
; }
32 int float_mant_dig() { return DBL_MANT_DIG
; }
33 double float_epsilon() { return DBL_EPSILON
; }
35 OBJECT
float_new(STATE
, double dbl
) {
38 o
= object_memory_new_opaque(state
, BASIC_CLASS(floatpoint
), sizeof(double));
39 value
= (double *)BYTES_OF(o
);
44 /* This functions is only used when unmarshalling.
45 * The assumptions made here are therefore safe.
46 * String#to_f uses string_to_double
48 OBJECT
float_from_string(STATE
, char *str
) {
51 d
= ruby_strtod(str
, &endp
);
52 if (str
!= endp
&& *endp
== '\0') {
53 return float_new(state
, d
);
58 void float_into_string(STATE
, OBJECT self
, char *buf
, int sz
) {
59 snprintf(buf
, sz
, "%+.17e", FLOAT_TO_DOUBLE(self
));
62 OBJECT
float_compare(STATE
, double a
, double b
) {
71 OBJECT
float_coerce(STATE
, OBJECT value
) {
73 return float_new(state
, (double)N2I(value
));
74 } else if(BIGNUM_P(value
)) {
75 return float_new(state
, bignum_to_double(state
, value
));