static public Method

Math.frexp(p1)

Math.frexp(numeric)     [ fraction, exponent ]

Returns a two-element array containing the normalized fraction (a Float) and exponent (a Fixnum) of numeric.

fraction, exponent = Math.frexp(1234)   #=> [0.6025390625, 11]
fraction * 2**exponent                  #=> 1234.0

Source Code

/*
*  call-seq:
*     Math.frexp(numeric)    => [ fraction, exponent ]
*  
*  Returns a two-element array containing the normalized fraction (a
*  <code>Float</code>) and exponent (a <code>Fixnum</code>) of
*  <i>numeric</i>.
*     
*     fraction, exponent = Math.frexp(1234)   #=> [0.6025390625, 11]
*     fraction * 2**exponent                  #=> 1234.0
*/

static VALUE
math_frexp(obj, x)
   VALUE obj, x;
{
   double d;
   int exp;

   Need_Float(x);

   d = frexp(RFLOAT(x)->value, &exp);
   return rb_assoc_new(rb_float_new(d), INT2NUM(exp));
}
Comments

Have your say
Please use Textile formatting (click here for a cheat sheet). Use <code/> and <pre/> for code samples.
Click here to login with OpenID to to post comments.