1 require File.dirname(__FILE__) + '/../../spec_helper'
4 describe "BigDecimal#frac" do
6 @zero = BigDecimal("0")
7 @mixed = BigDecimal("1.23456789")
8 @pos_int = BigDecimal("2E5555")
9 @neg_int = BigDecimal("-2E5555")
10 @pos_frac = BigDecimal("2E-9999")
11 @neg_frac = BigDecimal("-2E-9999")
13 @infinity = BigDecimal("Infinity")
14 @infinity_neg = BigDecimal("-Infinity")
15 @nan = BigDecimal("NaN")
16 @zero_pos = BigDecimal("+0")
17 @zero_neg = BigDecimal("-0")
20 it "returns a BigDecimal" do
21 @pos_int.frac.kind_of?(BigDecimal).should == true
22 @neg_int.frac.kind_of?(BigDecimal).should == true
23 @pos_frac.kind_of?(BigDecimal).should == true
24 @neg_frac.kind_of?(BigDecimal).should == true
27 it "returns the fractional part of the absolute value" do
28 @mixed.frac.should == BigDecimal("0.23456789")
29 @pos_frac.frac.should == @pos_frac
30 @neg_frac.frac.should == @neg_frac
33 it "returns 0 if the value is 0" do
34 @zero.frac.should == @zero
37 it "returns 0 if the value is an integer" do
38 @pos_int.frac.should == @zero
39 @neg_int.frac.should == @zero
42 it "correctly handles special values" do
43 @infinity.frac.should == @infinity
44 @infinity_neg.frac.should == @infinity_neg
45 @nan.frac.nan?.should == true