summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-09-25 07:58:49 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-09-25 07:58:49 +0000
commitd700d340437a4cfba215e51b9045460900c62c3a (patch)
tree6eab445cde1fc6e53ff86ba9718180baaeb609e3 /include
parentb328a43fa6e9d07ee8cfce09aaf5fdf1da7203fd (diff)
internal.h: move inline functions
* internal.h (rb_float_value, rb_float_new): move inline functions from ruby/ruby.h. * numeric.c (rb_float_value, rb_float_new): define external functions for extension libraries. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43042 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'include')
-rw-r--r--include/ruby/ruby.h79
1 files changed, 2 insertions, 77 deletions
diff --git a/include/ruby/ruby.h b/include/ruby/ruby.h
index cb432538b1..7ab224639a 100644
--- a/include/ruby/ruby.h
+++ b/include/ruby/ruby.h
@@ -805,85 +805,10 @@ struct RFloat {
double float_value;
};
+double rb_float_value(VALUE);
+VALUE rb_float_new(double);
VALUE rb_float_new_in_heap(double);
-#if USE_FLONUM
-#define RUBY_BIT_ROTL(v, n) (((v) << (n)) | ((v) >> ((sizeof(v) * 8) - n)))
-#define RUBY_BIT_ROTR(v, n) (((v) >> (n)) | ((v) << ((sizeof(v) * 8) - n)))
-
-static inline double
-rb_float_value(VALUE v)
-{
- if (FLONUM_P(v)) {
- if (v != (VALUE)0x8000000000000002) { /* LIKELY */
- union {
- double d;
- VALUE v;
- } t;
-
- VALUE b63 = (v >> 63);
- /* e: xx1... -> 011... */
- /* xx0... -> 100... */
- /* ^b63 */
- t.v = RUBY_BIT_ROTR((2 - b63) | (v & ~0x03), 3);
- return t.d;
- }
- else {
- return 0.0;
- }
- }
- else {
- return ((struct RFloat *)v)->float_value;
- }
-}
-
-static inline VALUE
-rb_float_new(double d)
-{
- union {
- double d;
- VALUE v;
- } t;
- int bits;
-
- t.d = d;
- bits = (int)((VALUE)(t.v >> 60) & 0x7);
- /* bits contains 3 bits of b62..b60. */
- /* bits - 3 = */
- /* b011 -> b000 */
- /* b100 -> b001 */
-
- if (t.v != 0x3000000000000000 /* 1.72723e-77 */ &&
- !((bits-3) & ~0x01)) {
- return (RUBY_BIT_ROTL(t.v, 3) & ~(VALUE)0x01) | 0x02;
- }
- else {
- if (t.v == (VALUE)0) {
- /* +0.0 */
- return 0x8000000000000002;
- }
- else {
- /* out of range */
- return rb_float_new_in_heap(d);
- }
- }
-}
-
-#else /* USE_FLONUM */
-
-static inline double
-rb_float_value(VALUE v)
-{
- return ((struct RFloat *)v)->float_value;
-}
-
-static inline VALUE
-rb_float_new(double d)
-{
- return rb_float_new_in_heap(d);
-}
-#endif
-
#define RFLOAT_VALUE(v) rb_float_value(v)
#define DBL2NUM(dbl) rb_float_new(dbl)