spec/mpfr/precision_roundmode_spec.rb in ruby-mpfr-0.0.7 vs spec/mpfr/precision_roundmode_spec.rb in ruby-mpfr-0.0.8
- old
+ new
@@ -1,16 +1,18 @@
-require File.dirname(__FILE__) + '/spec_helper.rb'
+require File.expand_path(File.dirname(__FILE__)) + '/spec_helper.rb'
def check_rnd(a)
MPFR.new(a).should == MPFR.new(a, MPFR.get_default_rounding_mode)
n = MPFR.new(a, MPFR::RNDN)
z = MPFR.new(a, MPFR::RNDZ)
u = MPFR.new(a, MPFR::RNDU)
d = MPFR.new(a, MPFR::RNDD)
+ a = MPFR.new(a, MPFR::RNDA)
(n > 0 ? d : u).should == z
[(a - z).abs, (a - u).abs, (a - d).abs].min.should >= (a - n).abs
(d <= u && (n == z || n == u || n == d)).should be_true
+ z.abs.should <= a.abs
end
def check_set_rnd(rnd1, rnd2)
MPFR.set_default_rounding_mode(rnd1)
MPFR.get_default_rounding_mode.should == rnd1
@@ -22,14 +24,14 @@
describe MPFR, 'when getting rounding mode' do
it "should return rounding mode" do
args = GenerateNumber.float(100)
args += [Math::PI, -Math::PI, Math::E, -Math::E, 0, 10, 27, -9, -293578]
args.each{ |a| check_rnd(a) }
- [MPFR::RNDN, MPFR::RNDZ, MPFR::RNDU, MPFR::RNDD].each{ |rnd| args.each{ |a| check_rnd(a) } }
+ [MPFR::RNDN, MPFR::RNDZ, MPFR::RNDU, MPFR::RNDD, MPFR::RNDA].each{ |rnd| args.each{ |a| check_rnd(a) } }
end
it "should be set rounding mode" do
- rnds = [MPFR::RNDN, MPFR::RNDZ, MPFR::RNDU, MPFR::RNDD]
+ rnds = [MPFR::RNDN, MPFR::RNDZ, MPFR::RNDU, MPFR::RNDD, MPFR::RNDA]
for i in 0...rnds.size
for j in (i+1)...rnds.size
check_set_rnd(rnds[i], rnds[j])
end
end