Bug 16202 – Floating point types implicitly convert losing precision

Status
NEW
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2016-06-24T20:19:37Z
Last change time
2024-12-13T18:48:38Z
Assigned to
No Owner
Creator
joeyemmons
Moved to GitHub: dmd#19148 →

Comments

Comment #0 by joeyemmons — 2016-06-24T20:19:37Z
Floating point types implicitly convert to less precise types with no warning or error. real x = real.max; float y = x; Something like that should at least be a warning, right now it compiles with no problem... If I am using reals, I obviously needed the precision, I don't want to accidentally lose that precision somewhere. This could be dangerous in critical applications that rely on a certain level of precision.
Comment #1 by schveiguy — 2016-06-24T21:16:37Z
As the spec defines the implicit conversion behavior, this is an enhancement.
Comment #2 by joeyemmons — 2016-06-24T22:25:53Z
(In reply to Steven Schveighoffer from comment #1) > As the spec defines the implicit conversion behavior, this is an enhancement. Can you link where it says that? I was actually looking for it the other day and could not find where it explicitly defined this behavior. There is a section on implicit conversions, but it does not explicitly say this type of conversion is intended, seems to mostly talk about promotions.
Comment #3 by schveiguy — 2016-06-25T20:06:30Z
You are right, I can't find this explicitly stated anywhere. However, there is nothing that says it's not allowed, and all current implementations allow it. If we were to suddenly say "oh, actually, you can't do that", it would break too much code. So it's defacto part of the spec. This is still an enhancement.
Comment #4 by robert.schadek — 2024-12-13T18:48:38Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19148 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB