Open dlangBugzillaToGithub opened 6 years ago
`NaN` is not a template. Are you sure it should be on this list? :)
https://github.com/dlang/phobos/pull/6040
Note that currently I'm not touching abs() because the sig constraint is just too complex.
NaN assumes that you want to create a real nan;
The correct signature will be in my opinion:
NaN(F, T)(const T payload)
if (isFloatingPoint!T && isUnsigned!T)
This will allow to create float or double NaNs.
Ref abs: I don't understand exactly why we have abs and fabs. I think that dropping "fabs" and specializing "abs" for each numeric type is a better approach.
Huh. I'm surprised there's such a thing as fabs in std.math. :-P
I agree that we should just unify everything under abs(). This is not C, where we can't overload abs() for integer vs. float arguments. Of course, fabs can still be left as an alias to abs() for backward compatibility.
We should probably file a separate bug to track this issue.
W.r.t NaN, I agree it would be nice to be able to specify the exact type desired. I don't think the payload has to be a template parameter; it should just be ulong since all unsigned integral types will convert to ulong, and we can just take however many bits to fit into the payload of the requested type.
Again, I think this belongs in a separate issue so that it doesn't get lost amid the overloading issues.
Commits pushed to master at https://github.com/dlang/phobos
https://github.com/dlang/phobos/commit/113579ec6be26777198a2e13abe9913226a385e6
Fix issue 18244: Generic functions in std.math need to have proper sig constraints.
Not having any sig constraints causes needless conflicts with
user-defined numerical types, e.g.:
// myNumber.d module myNumber; struct MyNumber { ... } int signbit(T : MyNumber)(T num) { ... }
// usercode.d import myNumber; import std.math; MyNumber num; auto x = signbit(num); // tries to call std.math.signbit, and fails
Add sig constraints to:
* signbit
* isFinite.
* isNormal.
* isSubnormal
* sgn.
* nextafter.
https://github.com/dlang/phobos/commit/e4da79f10f52b1a9cae1143c28b8b3b520efaa10
Merge pull request #6040 from quickfur/signbit_sig
Issue 18244: std.math generic functions need to have sig constraints
merged-on-behalf-of: Sebastian Wilzbach <sebi.wilzbach@gmail.com>
Commits pushed to master at https://github.com/dlang/phobos
https://github.com/dlang/phobos/commit/a74271be4c93cf95905265597ac9bca426378f55
Revert "Issue 18244: std.math generic functions need to have sig constraints"
https://github.com/dlang/phobos/commit/230292aef0353efa25ba5e298c30cdf5ce6717b5
Merge pull request #6213 from dlang/revert-6040-signbit_sig
Revert "Issue 18244: std.math generic functions need to have sig constraints"
merged-on-behalf-of: Iain Buclaw <ibuclaw@gdcproject.org>
Before this can be fixed, the alias this problem mentioned in issue 18287 should be removed.
I think this issue has too high severity. You can define your own function if you really need overloads after all. Decreasing to major.
rumbu reported this on 2018-01-16T19:39:31Z
Transfered from https://issues.dlang.org/show_bug.cgi?id=18244
CC List
Description