1# -*- mode: perl; -*- 2 3############################################################################### 4 5use strict; 6use warnings; 7 8use Test::More tests => 17; 9 10use bigfloat; 11 12############################################################################### 13# general tests 14 15my $x = 5; 16is(ref($x), 'Math::BigFloat', '$x = 5 makes $x a Math::BigFloat'); 17 18$x = 2 + 3.5; 19is($x, 5.5, '2 + 3.5 = 5.5'); 20is(ref($x), 'Math::BigFloat', '$x = 2 + 3.5 makes $x a Math::BigFloat'); 21 22$x = 2 ** 255; 23is(ref($x), 'Math::BigFloat', '$x = 2 ** 255 makes $x a Math::BigFloat'); 24 25is(sqrt(12), '3.464101615137754587054892683011744733886', 26 'sqrt(12)'); 27 28is(2/3, "0.6666666666666666666666666666666666666667", '2/3'); 29 30#is(2 ** 0.5, 'NaN'); # should be sqrt(2); 31 32is(12->bfac(), 479001600, '12->bfac() = 479001600'); 33 34# see if Math::BigFloat constant works 35 36# 0123456789 0123456789 <- default 40 37# 0123456789 0123456789 38is(1/3, '0.3333333333333333333333333333333333333333', '1/3'); 39 40############################################################################### 41# accuracy and precision 42 43is(bigfloat->accuracy(), undef, 'get accuracy'); 44bigfloat->accuracy(12); 45is(bigfloat->accuracy(), 12, 'get accuracy again'); 46bigfloat->accuracy(undef); 47is(bigfloat->accuracy(), undef, 'get accuracy again'); 48 49is(bigfloat->precision(), undef, 'get precision'); 50bigfloat->precision(12); 51is(bigfloat->precision(), 12, 'get precision again'); 52bigfloat->precision(undef); 53is(bigfloat->precision(), undef, 'get precision again'); 54 55is(bigfloat->round_mode(), 'even', 'get round mode'); 56bigfloat->round_mode('odd'); 57is(bigfloat->round_mode(), 'odd', 'get round mode again'); 58bigfloat->round_mode('even'); 59is(bigfloat->round_mode(), 'even', 'get round mode again'); 60