Bug 22637 – std.conv `to!double` and `parse!double` dont throw on under/overflow
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
Linux
Creation time
2021-12-30T09:30:19Z
Last change time
2022-07-12T08:44:20Z
Keywords
pull
Assigned to
No Owner
Creator
Basile-z
Comments
Comment #0 by b2.temp — 2021-12-30T09:30:19Z
The documentation says:
""
* Throws:
* A $(LREF ConvException) if `source` is empty, if no number could be
* parsed, or if an overflow occurred.
""
The following float literal causes libc strtod to signal overflow inerrno:
"999123254986799969899949354352145897441435999878464164684643513213254364543545634563454199999999999999999999999433212313213119992313453124136468463543543543999999341534654646546464646541341353541999999999965157349999999999320135273486741354354731567431324134999999999999999999999999999999999999999999999135411.9"
But std.conv `to` and `parse` accept it without throwing
---
void main()
{
import std.conv;
auto src = "999123254986799969899949354352145897441435999878464164684643513213254364543545634563454199999999999999999999999433212313213119992313453124136468463543543543999999341534654646546464646541341353541999999999965157349999999999320135273486741354354731567431324134999999999999999999999999999999999999999999999135411.9";
auto cv1 = parse!double(src);
auto cv2 = to!double("999123254986799969899949354352145897441435999878464164684643513213254364543545634563454199999999999999999999999433212313213119992313453124136468463543543543999999341534654646546464646541341353541999999999965157349999999999320135273486741354354731567431324134999999999999999999999999999999999999999999999135411.9");
}
---
Comment #1 by grimmaple95 — 2022-07-08T16:19:46Z
I can't confirm this bug on my end. It throws `std.conv.ConvException@C:\LDC\bin\..\import\std\conv.d(3419): Range error` for me.
LDC - the LLVM D compiler (1.29.0):
based on DMD v2.099.1 and LLVM 13.0.1
Comment #2 by snarwin+bugzilla — 2022-07-08T16:38:46Z
I was able to reproduce the bug with DMD 2.100.0 and LDC 1.29.0 on Linux.
From the backslashes in the path, it appears that the failed reproduction attempt was on Windows, so it's possible this bug only occurs on Linux.
Comment #3 by dlang-bot — 2022-07-08T18:27:19Z
@GrimMaple created dlang/phobos pull request #8502 "Fix Issue 22637 - std.conv `to!double` and `parse!double` dont throw on under/overflow" fixing this issue:
- Fix Issue 22637 - std.conv `to!double` and `parse!double` dont throw on under/overflow
This happened because `parse` enforced on real.
And provided number actually fits real.
Changed to enforce on `Target` type instead
https://github.com/dlang/phobos/pull/8502
Comment #4 by dlang-bot — 2022-07-12T08:44:20Z
dlang/phobos pull request #8502 "Fix Issue 22637 - std.conv `to!double` and `parse!double` dont throw on under/overflow" was merged into master:
- 1c3903c2e644d55913708b6867e33aab1a076ac9 by Grim Maple:
Fix Issue 22637 - std.conv `to!double` and `parse!double` dont throw on under/overflow
This happened because `parse` enforced on real.
And provided number actually fits real.
Changed to enforce on `Target` type instead
https://github.com/dlang/phobos/pull/8502