Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 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