[Issue 22527] Casting out-of-range floating point value to signed integer overflows

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Dec 10 23:16:11 UTC 2021


https://issues.dlang.org/show_bug.cgi?id=22527

SorinM <sorin.mateescu at stud.acs.upb.ro> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |sorin.mateescu at stud.acs.upb
                   |                            |.ro

--- Comment #2 from SorinM <sorin.mateescu at stud.acs.upb.ro> ---
Compiling this example in C:

```
#include <float.h>

int main()
{
    float f = FLT_MAX;
    int i = (int)f;

    return 0;
}
```

and then looking into the assembly, you can see the cvttss2si instruction is
used to perform the cast. Reading from the second paragraph of
https://www.felixcloutier.com/x86/cvttss2si#description we can find the answer:
80000000H (or INT_MIN) is the result in case of floating-point invalid
exception. As this is defined directly in the x86 ISA and is the default
behavior in C, this will also be the case for D.

--


More information about the Digitalmars-d-bugs mailing list