1 require File.dirname(__FILE__) + '/../../spec_helper'
4 describe "BigDecimal#split" do
7 @arr = BigDecimal("0.314159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593014782083152134043E1").split
8 @arr_neg = BigDecimal("-0.314159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593014782083152134043E1").split
9 @digits = "922337203685477580810101333333333333333333333333333"
10 @arr_big = BigDecimal("00#{@digits}000").split
11 @arr_big_neg = BigDecimal("-00#{@digits}000").split
12 @huge = BigDecimal('100000000000000000000000000000000000000000001E90000000').split
14 @infinity = BigDecimal("Infinity")
15 @infinity_neg = BigDecimal("-Infinity")
16 @nan = BigDecimal("NaN")
17 @zero = BigDecimal("0")
18 @zero_neg = BigDecimal("-0")
21 it "splits BigDecimal in an array with four values" do
25 it "First value: 1 for numbers > 0" do
27 @arr_big[0].should == 1
28 @zero.split[0].should == 1
30 BigDecimal("+0").split[0].should == 1
31 BigDecimal("1E400").split[0].should == 1
32 @infinity.split[0].should == 1
35 it "First value: -1 for numbers < 0" do
36 @arr_neg[0].should == -1
37 @arr_big_neg[0].should == -1
38 @zero_neg.split[0].should == -1
39 BigDecimal("-1E400").split[0].should == -1
40 @infinity_neg.split[0].should == -1
43 it "First value: 0 if BigDecimal is NaN" do
44 BigDecimal("NaN").split[0].should == 0
47 it "Second value: a string with the significant digits" do
48 string = "314159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593014782083152134043"
49 @arr[1].should == string
50 @arr_big[1].should == @digits
51 @arr_big_neg[1].should == @digits
52 @huge[1].should == "100000000000000000000000000000000000000000001"
53 @infinity.split[1].should == @infinity.to_s
54 @nan.split[1].should == @nan.to_s
55 @infinity_neg.split[1].should == @infinity.to_s
56 @zero.split[1].should == "0"
57 BigDecimal("-0").split[1].should == "0"
60 it "Third value: the base (currently always ten)" do
62 @arr_neg[2].should == 10
63 @arr_big[2].should == 10
64 @arr_big_neg[2].should == 10
66 @infinity.split[2].should == 10
67 @nan.split[2].should == 10
68 @infinity_neg.split[2].should == 10
69 @zero.split[2].should == 10
70 @zero_neg.split[2].should == 10
73 it "Fourth value: The exponent" do
75 @arr_neg[3].should == 1
76 @arr_big[3].should == 54
77 @arr_big_neg[3].should == 54
78 @huge[3].should == 90000045
79 @infinity.split[3].should == 0
80 @nan.split[3].should == 0
81 @infinity_neg.split[3].should == 0
82 @zero.split[3].should == 0
83 @zero_neg.split[3].should == 0