www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22527] New: Casting out-of-range floating point value to


          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 puremagic.com
          Reporter: snarwin+bugzilla 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. --
Nov 18 2021