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

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Nov 19 04:59:58 UTC 2021


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

          Issue ID: 22527
           Summary: Casting out-of-range floating point value to signed
                    integer overflows
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: snarwin+bugzilla at gmail.com

As of DMD 2.098.0, the following program fails to compile:

---
static assert(cast(int) float.max > 0);
---

The error message is:

---
Error: static assert:  `-2147483648 > 0` is false
---

According to the language spec:

> Casting a floating point value to an integral type is the equivalent of converting to an integer using truncation.

Since float.max is a positive number, truncation of its value should result in
a positive integer, not a negative integer.

--


More information about the Digitalmars-d-bugs mailing list