View source code
Display the source code in std/math/algebraic.d from which this
page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a
Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.
Requires a signed-in GitHub account. This works well for small changes.
If you'd like to make larger changes you may want to consider using
local clone.
Function std.math.algebraic.abs
Calculates the absolute value of a number.
auto abs(Num)
(
Num x
) pure nothrow @nogc
if (isIntegral!Num || is(typeof(Num .init >= 0)) && is(typeof(-Num .init)));
Parameters
Name | Description |
---|---|
Num | (template parameter) type of number |
x | real number value |
Returns
The absolute value of the number. If floating-point or integral, the return type will be the same as the input.
Limitations
When x is a signed integral equal to Num
the value of x will be returned instead.
Note for 2's complement; -Num
(= Num
) is not representable due to overflow.
Example
import std .math .traits : isIdentical, isNaN;
assert(isIdentical(abs(-0.0L), 0.0L));
assert(isNaN(abs(real .nan)));
writeln(abs(-real .infinity)); // real.infinity
writeln(abs(-56)); // 56
writeln(abs(2321312L)); // 2321312L
writeln(abs(23u)); // 23u
Authors
Walter Bright, Don Clugston, Conversion of CEPHES math library to D by Iain Buclaw and David Nadlinger
License
Copyright © 1999-2024 by the D Language Foundation | Page generated by ddox.