overload.t 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #!perl -T
  2. use strict;
  3. use warnings;
  4. use Test::More tests => 31;
  5. use Math::AnyNum qw(:overload);
  6. is(655870882787, Math::AnyNum->new("655870882787"));
  7. is(655870882787, Math::AnyNum->new(655870882787));
  8. is(655870882787 / 409205648497, "655870882787/409205648497");
  9. is(-660131804286 / 409205648497, "-660131804286/409205648497");
  10. is(-3147483648, "-3147483648");
  11. is(Math::AnyNum->new("-3147483648"), "-3147483648");
  12. is(Math::AnyNum->new("-1147483648"), "-1147483648");
  13. is(2**255, '578960446186580977117854925043439539266' . '34992332820282019728792003956564819968', '2 ** 255');
  14. is(ref(0xff), 'Math::AnyNum');
  15. is(ref(0123), 'Math::AnyNum');
  16. is(ref(0b101), 'Math::AnyNum');
  17. # hexadecimal constants
  18. is(0x123456ff, Math::AnyNum->new('123456ff', '16'), 'hexadecimal constant');
  19. # binary constants
  20. is(0b0101010001100, Math::AnyNum->new('0101010001100', '2'), 'binary constant');
  21. # octal constants
  22. is(01234567, Math::AnyNum->new('1234567', '8'), 'octal constant');
  23. my $x = 2 + 4.5; # AnyNum 6.5
  24. is("$x", "6.5");
  25. my $inf = Inf * Inf;
  26. like($inf, qr/^inf/i);
  27. my $ninf = Inf * -1;
  28. like($ninf, qr/^-inf/i);
  29. my $nan = 3 * NaN;
  30. is("$nan", "NaN");
  31. $nan = Inf / Inf;
  32. is("$nan", "NaN");
  33. $nan = NaN + 2;
  34. is("$nan", "NaN");
  35. $nan = NaN / 2;
  36. is("$nan", "NaN");
  37. is(.5, 0.5);
  38. is(1.23345e10, "12334500000");
  39. is(1.23445e-10, "0.000000000123445");
  40. is(100_000_000, "100000000");
  41. is(727, 0x2d7);
  42. is(727, 01327);
  43. is(727, 0b1011010111);
  44. is(atan2(0, 0), 0);
  45. like(atan2(0, -1), qr/^3.1415/);
  46. like(1.0 / 3.0, qr/^0.333333333/, '1.0 / 3.0 = 0.333333333...');