File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -1134,7 +1134,9 @@ $(GNAME CastExpression):
1134
1134
---
1135
1135
1136
1136
$(P Casting a floating point value to an integral type is the equivalent
1137
- of converting to an integer using truncation.)
1137
+ of converting to an integer using truncation. If the floating point
1138
+ value is outside the range of the integral type, the cast will produce
1139
+ an invalid result (this is also the case in C, C++).)
1138
1140
1139
1141
---
1140
1142
void main()
@@ -1145,6 +1147,18 @@ $(GNAME CastExpression):
1145
1147
assert(b == 1L);
1146
1148
long c = cast(long) -1.5;
1147
1149
assert(c == -1);
1150
+
1151
+ // if the float overflows, the cast returns the integer value of
1152
+ // 80000000_00000000H (64-bit operand) or 80000000H (32-bit operand)
1153
+ long d = cast(long) float.max;
1154
+ assert(d == long.min);
1155
+ int e = cast(int) (1234.5 + int.max);
1156
+ assert(e == int.min);
1157
+
1158
+ // for types represented on 16 or 8 bits, the result is the same as
1159
+ // 32-bit types, but the most significant bits are ignored
1160
+ short f = cast(short) float.max;
1161
+ assert(f == 0);
1148
1162
}
1149
1163
---
1150
1164
You can’t perform that action at this time.
0 commit comments