diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-07-23 12:46:33 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-07-23 12:46:33 -0300 |
commit | 7f5c31cdcac5388b3c48a26112dfb6d2cadb7321 (patch) | |
tree | 91012526a941414f1d09e5640d34bee5ccfd240f /testes | |
parent | 9e6807c3c9d5036e999f636f936df07b72284442 (diff) | |
download | lua-7f5c31cdcac5388b3c48a26112dfb6d2cadb7321.tar.gz lua-7f5c31cdcac5388b3c48a26112dfb6d2cadb7321.tar.bz2 lua-7f5c31cdcac5388b3c48a26112dfb6d2cadb7321.zip |
Fixed bug in 'string.format' with option '%f'
As an example, 'print(string.format("%.99f", 1e70))' may have a
lot of garbage after the number.
The old test to ensure that 'string.format("%.99f", n)' was not too
large, 'fabs(n) < 1e100', assumes that the number will fit in the 99
bytes; but the 99 is not the space for the number, it is the added
extra zeros. The option worked for smaller numbers because of the
extra space added to MAX_ITEM.
Diffstat (limited to 'testes')
-rw-r--r-- | testes/strings.lua | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/testes/strings.lua b/testes/strings.lua index 2540fdef..0e7874bf 100644 --- a/testes/strings.lua +++ b/testes/strings.lua | |||
@@ -255,6 +255,12 @@ do -- longest number that can be formatted | |||
255 | local s = string.format('%.99f', -(10^i)) | 255 | local s = string.format('%.99f', -(10^i)) |
256 | assert(string.len(s) >= i + 101) | 256 | assert(string.len(s) >= i + 101) |
257 | assert(tonumber(s) == -(10^i)) | 257 | assert(tonumber(s) == -(10^i)) |
258 | |||
259 | -- limit for floats | ||
260 | assert(10^38 < math.huge) | ||
261 | local s = string.format('%.99f', -(10^38)) | ||
262 | assert(string.len(s) >= 38 + 101) | ||
263 | assert(tonumber(s) == -(10^38)) | ||
258 | end | 264 | end |
259 | 265 | ||
260 | 266 | ||