mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-23 19:19:32 +01:00
Workaround Python's idiocy with float -> str -> float conversions
This commit is contained in:
parent
0bc16641b9
commit
62897a9663
@ -1,5 +1,6 @@
|
|||||||
###
|
###
|
||||||
# Copyright (c) 2002-2004, Jeremiah Fincher
|
# Copyright (c) 2002-2004, Jeremiah Fincher
|
||||||
|
# Copyright (c) 2008, James Vega
|
||||||
# All rights reserved.
|
# All rights reserved.
|
||||||
#
|
#
|
||||||
# Redistribution and use in source and binary forms, with or without
|
# Redistribution and use in source and binary forms, with or without
|
||||||
@ -181,6 +182,11 @@ class Math(callbacks.Plugin):
|
|||||||
x = complex(i)
|
x = complex(i)
|
||||||
if x == abs(x):
|
if x == abs(x):
|
||||||
x = abs(x)
|
x = abs(x)
|
||||||
|
# Need to use string-formatting here instead of str() because
|
||||||
|
# use of str() on large numbers loses information:
|
||||||
|
# str(float(33333333333333)) => '3.33333333333e+13'
|
||||||
|
# float('3.33333333333e+13') => 33333333333300.0
|
||||||
|
return '%f' % x
|
||||||
return str(x)
|
return str(x)
|
||||||
text = self._mathRe.sub(handleMatch, text)
|
text = self._mathRe.sub(handleMatch, text)
|
||||||
try:
|
try:
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
###
|
###
|
||||||
# Copyright (c) 2002-2004, Jeremiah Fincher
|
# Copyright (c) 2002-2004, Jeremiah Fincher
|
||||||
|
# Copyright (c) 2008, James Vega
|
||||||
# All rights reserved.
|
# All rights reserved.
|
||||||
#
|
#
|
||||||
# Redistribution and use in source and binary forms, with or without
|
# Redistribution and use in source and binary forms, with or without
|
||||||
@ -126,6 +127,9 @@ class MathTestCase(PluginTestCase):
|
|||||||
self.assertResponse('calc max(1,2)', '2')
|
self.assertResponse('calc max(1,2)', '2')
|
||||||
self.assertResponse('calc min(1,2)', '1')
|
self.assertResponse('calc min(1,2)', '1')
|
||||||
|
|
||||||
|
def testCalcStrFloat(self):
|
||||||
|
self.assertResponse('calc 3+33333333333333', '33333333333336')
|
||||||
|
|
||||||
def testICalc(self):
|
def testICalc(self):
|
||||||
self.assertResponse('icalc 1^1', '0')
|
self.assertResponse('icalc 1^1', '0')
|
||||||
self.assertResponse('icalc 10**24', '1' + '0'*24)
|
self.assertResponse('icalc 10**24', '1' + '0'*24)
|
||||||
|
Loading…
Reference in New Issue
Block a user