From: <sc...@op...> - 2015-02-13 18:10:54
|
changeset: 28288435bf7b in /home/euweb/scm/hg_repos/euphoria branch: default author: Matt Lewis url: http://scm.openeuphoria.org/hg/euphoria?cmd=changeset;node=28288435bf7b description: * ifdef out some 32-bit specific scientific notation tests * fix bug with leading zeroes in the significand resulting in infinity being returned diffstat: include/std/scinot.e | 13 +++++++++++++ tests/t_literals.e | 34 ++++++++++++++++++++-------------- 2 files changed, 33 insertions(+), 14 deletions(-) diffs (74 lines): diff -r 62135ad69afe -r 28288435bf7b include/std/scinot.e --- a/include/std/scinot.e Fri Feb 13 10:47:47 2015 -0500 +++ b/include/std/scinot.e Fri Feb 13 11:24:41 2015 -0500 @@ -386,6 +386,17 @@ -- We split the integral and fractional parts, because they have to be -- calculated differently. + + -- strip off leading zeroes on the significand + integer zx = 1 + while zx < length(s) and s[zx] = '0' do + zx += 1 + end while + if length(s) then + s = remove( s, 1, zx-1) + e -= zx-1 + end if + s = s[1..e-1] - '0' -- If LHS only consists of zeros, then return zero. @@ -399,6 +410,8 @@ if exp + length(s) - 1 > base10_ceiling then -- make inf or -inf + ? exp & length(s) & base10_ceiling + ? s atom inf = PINF if equal( sbits, {1} ) then inf = MINF diff -r 62135ad69afe -r 28288435bf7b tests/t_literals.e --- a/tests/t_literals.e Fri Feb 13 10:47:47 2015 -0500 +++ b/tests/t_literals.e Fri Feb 13 11:24:41 2015 -0500 @@ -186,20 +186,26 @@ test_equal( "Constant floating point with zero fraction", 0, doit() ) test_equal( "0b1.11111111e354", power(2,300)*(power(2,55)-2), scientific_to_atom("73391955711682284297474315980694609568598702834628673856666055528509030762550615149477994172850609602953216e0") ) -- the following four are equivalent. -test_equal( "0b1.11111111e1022 #1", power(2,968)*(power(2,55)-2), scientific_to_atom("0.89884656743115795e308") ) -test_equal( "0b1.11111111e1022 #2", power(2,968)*(power(2,55)-2), scientific_to_atom("898846567.43115795e299" ) ) -test_equal( "0b1.11111111e1022 #3", power(2,968)*(power(2,55)-2), scientific_to_atom("89884656743115795e291") ) -test_equal( "0b1.11111111e1022 #4", power(2,968)*(power(2,55)-2), scientific_to_atom("8.9884656743115795e307") ) -test_equal( "1E308 #1", power(10,308), scientific_to_atom("1e308") ) -test_equal( "1E308 #2", power(10,308), scientific_to_atom("0.001e311") ) -test_equal( "1E308 #3", power(10,308), scientific_to_atom("0.1e309") ) -test_equal( "1E308 #4", power(10,308), scientific_to_atom("10e307") ) -test_equal( "1E308 #5", power(10,308), scientific_to_atom("1000e305") ) -test_equal( "inf #1", 1e308*10, scientific_to_atom("1e309") ) -test_equal( "inf #2", 1e308*10, scientific_to_atom("0.001e312") ) -test_equal( "inf #3", 1e308*10, scientific_to_atom("0.1e310") ) -test_equal( "inf #4", 1e308*10, scientific_to_atom("10e308") ) -test_equal( "inf #5", 1e308*10, scientific_to_atom("1000e306") ) +ifdef BITS32 then + test_equal( "0b1.11111111e1022 #1", power(2,968)*(power(2,55)-2), scientific_to_atom("0.89884656743115795e308") ) + test_equal( "0b1.11111111e1022 #2", power(2,968)*(power(2,55)-2), scientific_to_atom("898846567.43115795e299" ) ) + test_equal( "0b1.11111111e1022 #3", power(2,968)*(power(2,55)-2), scientific_to_atom("89884656743115795e291") ) + test_equal( "0b1.11111111e1022 #4", power(2,968)*(power(2,55)-2), scientific_to_atom("8.9884656743115795e307") ) + + test_equal( "1E308 #1", power(10,308), scientific_to_atom("1e308") ) + test_equal( "1E308 #2", power(10,308), scientific_to_atom("0.001e311") ) + test_equal( "1E308 #3", power(10,308), scientific_to_atom("0.1e309") ) + test_equal( "1E308 #4", power(10,308), scientific_to_atom("10e307") ) + test_equal( "1E308 #5", power(10,308), scientific_to_atom("1000e305") ) + + test_equal( "inf #1", 1e308*10, scientific_to_atom("1e309") ) + test_equal( "inf #2", 1e308*10, scientific_to_atom("0.001e312") ) + test_equal( "inf #3", 1e308*10, scientific_to_atom("0.1e310") ) + test_equal( "inf #4", 1e308*10, scientific_to_atom("10e308") ) + test_equal( "inf #5", 1e308*10, scientific_to_atom("1000e306") ) + +end ifdef + test_equal( "42555", 42555, 4.2555e4 ) test_equal( "Plank", 6.62606957 * power(10,-34), 6.62606957e-34 ) test_equal( "Avagadro #1", 6.022141 * power(10,23), scientific_to_atom("6.022141e23") ) |