Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Branch: master
Fetching contributors…

Cannot retrieve contributors at this time

98 lines (87 sloc) 6.069 kB
use str2num;
use Test;
plan *;
isa_ok str2num("1"), Int, "1 is an Int";
is str2num("1"), 1, "1 is 1";
isa_ok str2num("+1"), Int, "+1 is an Int";
is str2num("+1"), 1, "+1 is 1";
isa_ok str2num("-1"), Int, "-1 is an Int";
is str2num("-1"), -1, "-1 is -1";
isa_ok str2num("10"), Int, "10 is an Int";
is str2num("10"), 10, "10 is 10";
isa_ok str2num("10."), Rat, "10. is an Rat";
is str2num("10."), 10, "10. is 10";
isa_ok str2num("10.0"), Rat, "10.0 is an Rat";
is str2num("10.0"), 10, "10.0 is 10";
isa_ok str2num("10.1"), Rat, "10.1 is an Rat";
is str2num("10.1"), 10.1, "10.1 is 10.1";
isa_ok str2num("100000000.1"), Rat, "100000000.1 is an Rat";
is str2num("100000000.1"), 100000000.1, "100000000.1 is 100000000.1";
isa_ok str2num("100000000.100000000000000000000000000000"), Rat, "100000000.100000000000000000000000000000 is an Rat";
is str2num("100000000.100000000000000000000000000000"), 100000000.1, "100000000.100000000000000000000000000000 is 100000000.100000000000000000000000000000";
is log10(str2num(".0001")), -4, "log10(.0001) is -4";
is log10(str2num(".00001")), -5, "log10(.00001) is -5";
is log10(str2num(".000001")), -6, "log10(.000001) is -6";
is log10(str2num(".0000001")), -7, "log10(.0000001) is -7";
is log10(str2num(".00000001")), -8, "log10(.00000001) is -8";
is log10(str2num(".000000001")), -9, "log10(.000000001) is -9";
is log10(str2num(".0000000001")), -10, "log10(.0000000001) is -10";
is log10(str2num(".00000000001")), -11, "log10(.00000000001) is -11";
is log10(str2num(".000000000001")), -12, "log10(.000000000001) is -12";
is log10(str2num(".0000000000001")), -13, "log10(.0000000000001) is -13";
is log10(str2num(".00000000000001")), -14, "log10(.00000000000001) is -14";
is log10(str2num(".000000000000001")), -15, "log10(.000000000000001) is -15";
is log10(str2num(".0000000000000001")), -16, "log10(.0000000000000001) is -16";
is log10(str2num(".00000000000000001")), -17, "log10(.00000000000000001) is -17";
is log10(str2num(".000000000000000001")), -18, "log10(.000000000000000001) is -18";
is log10(str2num(".0000000000000000001")), -19, "log10(.0000000000000000001) is -19";
is log10(str2num(".00000000000000000001")), -20, "log10(.00000000000000000001) is -20";
is log10(str2num(".0000000000000000000000001")), -25, "log10(.0000000000000000000000001) is -25";
is log10(str2num(".000000000000000000000000000001")), -30, "log10(.000000000000000000000000000001) is -30";
is log10(str2num(".000000000000000000000000000000000000000000000000000000000001")), -60, "log10(.000000000000000000000000000000000000000000000000000000000001) is -60";
is log10(str2num("10000")), 4, "log10(10000) is 4";
is log10(str2num("100000")), 5, "log10(100000) is 5";
is log10(str2num("1000000")), 6, "log10(1000000) is 6";
is log10(str2num("10000000")), 7, "log10(10000000) is 7";
is log10(str2num("100000000")), 8, "log10(100000000) is 8";
is log10(str2num("1000000000")), 9, "log10(1000000000) is 9";
is log10(str2num("10000000000")), 10, "log10(10000000000) is 10";
is log10(str2num("100000000000")), 11, "log10(100000000000) is 11";
is log10(str2num("1000000000000")), 12, "log10(1000000000000) is 12";
is log10(str2num("10000000000000")), 13, "log10(10000000000000) is 13";
is log10(str2num("100000000000000")), 14, "log10(100000000000000) is 14";
is log10(str2num("1000000000000000")), 15, "log10(1000000000000000) is 15";
is log10(str2num("10000000000000000")), 16, "log10(10000000000000000) is 16";
is log10(str2num("100000000000000000")), 17, "log10(100000000000000000) is 17";
is log10(str2num("1000000000000000000")), 18, "log10(1000000000000000000) is 18";
is log10(str2num("10000000000000000000")), 19, "log10(10000000000000000000) is 19";
is log10(str2num("100000000000000000000")), 20, "log10(100000000000000000000) is 20";
is log10(str2num("10000000000000000000000000")), 25, "log10(10000000000000000000000000) is 25";
is log10(str2num("1000000000000000000000000000000")), 30, "log10(1000000000000000000000000000000) is 30";
is log10(str2num("10000.0")), 4, "log10(10000.0) is 4";
is log10(str2num("100000.0")), 5, "log10(100000.0) is 5";
is log10(str2num("1000000.0")), 6, "log10(1000000.0) is 6";
is log10(str2num("10000000.0")), 7, "log10(10000000.0) is 7";
is log10(str2num("100000000.0")), 8, "log10(100000000.0) is 8";
is log10(str2num("1000000000.0")), 9, "log10(1000000000.0) is 9";
is log10(str2num("10000000000.0")), 10, "log10(10000000000.0) is 10";
is log10(str2num("100000000000.0")), 11, "log10(100000000000.0) is 11";
is log10(str2num("1000000000000.0")), 12, "log10(1000000000000.0) is 12";
is log10(str2num("10000000000000.0")), 13, "log10(10000000000000.0) is 13";
is log10(str2num("100000000000000.0")), 14, "log10(100000000000000.0) is 14";
is log10(str2num("1000000000000000.0")), 15, "log10(1000000000000000.0) is 15";
is log10(str2num("10000000000000000.0")), 16, "log10(10000000000000000.0) is 16";
is log10(str2num("100000000000000000.0")), 17, "log10(100000000000000000.0) is 17";
is log10(str2num("1000000000000000000.0")), 18, "log10(1000000000000000000.0) is 18";
is log10(str2num("10000000000000000000.0")), 19, "log10(10000000000000000000.0) is 19";
is log10(str2num("100000000000000000000.0")), 20, "log10(100000000000000000000.0) is 20";
is log10(str2num("10000000000000000000000000.0")), 25, "log10(10000000000000000000000000.0) is 25";
is log10(str2num("1000000000000000000000000000000.0")), 30, "log10(1000000000000000000000000000000.0) is 30";
is str2num("3.14159265358979323846264338327950288").substr(0,10), "3.14159265", "3.14159265358979323846264338327950288 produces a number whose first digits are 3.14159265";
is str2num("3.14159_26535_89793_23846_26433_83279_50288").substr(0,10), "3.14159265", "3.14159_26535_89793_23846_26433_83279_50288 produces a number whose first digits are 3.14159265";
is log10(str2num("1e30")), 30, "log10(1e30) is 30";
is log10(str2num("1.e30")), 30, "log10(1.e30) is 30";
is log10(str2num("1.0e30")), 30, "log10(1.0e30) is 30";
is log10(str2num("1e+30")), 30, "log10(1e+30) is 30";
is log10(str2num("1e-30")), -30, "log10(1e-30) is -30";
done_testing;
Jump to Line
Something went wrong with that request. Please try again.