Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
27
Task/Safe-addition/Hare/safe-addition.hare
Normal file
27
Task/Safe-addition/Hare/safe-addition.hare
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
use fmt;
|
||||
use math;
|
||||
|
||||
type interval = struct {a: f64, b: f64};
|
||||
|
||||
export fn main() void = {
|
||||
const a: [_](f64, f64) = [
|
||||
(1.0f64, 2.0f64),
|
||||
(0.1f64, 0.2f64),
|
||||
(1e100f64, 1e-100f64),
|
||||
(1e308f64, 1e308f64)];
|
||||
|
||||
for (let i = 0z; i < len(a); i += 1) {
|
||||
let res = safe_add(a[i].0, a[i].1);
|
||||
fmt::printfln("{} + {} is within ({}, {})", a[i].0, a[i].1, res.a, res.b)!;
|
||||
};
|
||||
};
|
||||
|
||||
fn safe_add(a: f64, b: f64) interval = {
|
||||
let orig = math::getround();
|
||||
math::setround(math::fround::DOWNWARD);
|
||||
let r0 = a + b;
|
||||
math::setround(math::fround::UPWARD);
|
||||
let r1 = a + b;
|
||||
math::setround(orig);
|
||||
return interval{a = r0, b = r1};
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue