June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
16
Task/Safe-addition/D/safe-addition.d
Normal file
16
Task/Safe-addition/D/safe-addition.d
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
import std.traits;
|
||||
auto safeAdd(T)(T a, T b)
|
||||
if (isFloatingPoint!T) {
|
||||
import std.math; // nexDown, nextUp
|
||||
import std.typecons; // tuple
|
||||
return tuple!("d", "u")(nextDown(a+b), nextUp(a+b));
|
||||
}
|
||||
|
||||
import std.stdio;
|
||||
void main() {
|
||||
auto a = 1.2;
|
||||
auto b = 0.03;
|
||||
|
||||
auto r = safeAdd(a, b);
|
||||
writefln("(%s + %s) is in the range %0.16f .. %0.16f", a, b, r.d, r.u);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue