Bug 7996 – Refuse std.math.isnan() on not floating point values?
Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2012-04-27T04:52:00Z
Last change time
2016-12-08T16:23:25Z
Keywords
accepts-invalid, bootcamp
Assigned to
nobody
Creator
bearophile_hugs
Comments
Comment #0 by bearophile_hugs — 2012-04-27T04:52:46Z
std.math.sqrt() refuses an argument of type long (despite this is handy):
import std.math;
void main() {
long x;
sqrt(x);
}
With (dmd 2.060alpha):
test.d(4): Error: function std.math.sqrt called with argument types:
((long))
matches both:
std.math.sqrt(float x)
and:
std.math.sqrt(real x)
While this compiles with no errors:
import std.math;
void main() {
long x;
assert(!isnan(x));
}
Maybe isnan() has to statically refuse arguments that aren't built-in floating point (maybe with a std.traits.isFloatingPoint template constraint), this avoids some bugs (I have had a bug caused by this).
Comment #1 by razvan.nitu1305 — 2016-11-24T11:40:39Z
(In reply to bearophile_hugs from comment #0)
> std.math.sqrt() refuses an argument of type long (despite this is handy):
>
> import std.math;
> void main() {
> long x;
> sqrt(x);
> }
>
>
>
> With (dmd 2.060alpha):
>
> test.d(4): Error: function std.math.sqrt called with argument types:
> ((long))
> matches both:
> std.math.sqrt(float x)
> and:
> std.math.sqrt(real x)
>
>
>
> While this compiles with no errors:
>
> import std.math;
> void main() {
> long x;
> assert(!isnan(x));
> }
>
>
> Maybe isnan() has to statically refuse arguments that aren't built-in
> floating point (maybe with a std.traits.isFloatingPoint template
> constraint), this avoids some bugs (I have had a bug caused by this).
Actually, the function isnan is deprecated. Instead, the function isNaN has the constraint isFloatingPoint [1].
Maybe this should be closed?
[1] https://dlang.org/phobos/std_math#.isNaN