Bug 22414 – clamp(a, b, c) should always return typeof(a)
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2021-10-17T20:13:41Z
Last change time
2021-10-19T08:38:47Z
Keywords
pull
Assigned to
No Owner
Creator
Andrei Alexandrescu
Comments
Comment #0 by andrei — 2021-10-17T20:13:41Z
"I will now clamp this value between this limits" has the implied contract that you get the same type as that of the initial value.
Using min and max in the implementation of clamp is specious; in min and max there is no "preferred" type so they use a fair method of choosing the type of the result. In contrast, clamp is about a value that occasionally is forced to a limit.
Comment #1 by dlang-bot — 2021-10-17T20:15:27Z
@andralex created dlang/phobos pull request #8293 "Fix Issue 22414 - clamp(a, b, c) should always return typeof(a)" fixing this issue:
- Fix Issue 22414 - clamp(a, b, c) should always return typeof(a)
https://github.com/dlang/phobos/pull/8293
Comment #2 by dlang-bot — 2021-10-19T08:38:47Z
dlang/phobos pull request #8293 "Fix Issue 22414 - clamp(a, b, c) should always return typeof(a)" was merged into master:
- 3041b3768b7df8e370e59794fbc95e2ed69bc182 by Andrei Alexandrescu:
Fix Issue 22414 - clamp(a, b, c) should always return typeof(a)
https://github.com/dlang/phobos/pull/8293