Bug 23845 – std.math.traits.copysign returns the wrong value

Status
RESOLVED
Resolution
INVALID
Severity
major
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2023-04-19T08:48:48Z
Last change time
2023-04-19T09:30:00Z
Assigned to
No Owner
Creator
[email protected]

Comments

Comment #0 by grylliade — 2023-04-19T08:48:48Z
As written, the function simply returns its first parameter. Should likely return cast(R) *pto, though my pointer syntax is rusty—surely doing all that work with pto should have *some* point (no pun intended). I’d honestly bump this up to critical, but if no one’s noticed this yet, maybe it shouldn’t be—except copysign() can be called from cbrt(), at the very least. It keeps cbrt() from being inferred pure on the MS runtime, I think; if I’m wrong, that’s a separate bug.
Comment #1 by grylliade — 2023-04-19T09:10:24Z
Did this slip through because unit tests are run at compile time? Because the unit tests sure as hell should’ve caught this. I’d also recommend keeping template parameter order consistent between the versions of copysign(); it’s not a bug, but it could damned easily cause one if someone’s not paying attention.
Comment #2 by grylliade — 2023-04-19T09:29:24Z
My pointer syntax is much rustier than I’d realized, so…ignore this. cbrt() should still be pure, though; a cube root function *not* being pure is…surprising, at the least.