bsteinb / accurate Goto Github PK
View Code? Open in Web Editor NEW(More or less) accurate floating point algorithms
Home Page: http://bsteinb.github.io/accurate/
License: Apache License 2.0
(More or less) accurate floating point algorithms
Home Page: http://bsteinb.github.io/accurate/
License: Apache License 2.0
I searched for Kahan, floating point precision, sum, ... and it did not pop up.
It might be worth it to expend some time doing some crates.io SEO, e.g., expanding the readme with more information, maybe mentioning which algorithms are implemented in this crate, etc.
Some unsafe code relies on RawExponent::raw_exponent() < FloatFormat::base_pow_exponent_digits()
to be sound. Currently a user could write a custom float type in safe rust and trigger UB by messing up the trait implementation.
Example:
https://github.com/bsteinb/accurate/blob/master/src/sum/onlineexactsum.rs#L63
Hi @bsteinb
thank you for this nice repository!
Could you maybe point me towards a resource on which algorithm to choose? I read the original papers, but of course every paper tries to sell their contribution and thus it is hard to gauge which algorithm is actually a good choice. If you would have any thoughts on this, or resources to point to, I would very much appreciate it.
Thank you
Lukas
Consider exactly representable f32
numbers 4194304.0
and 4194304.5
. Their sum is 8388608.5
, which is not exactly representable as an f32
, so it needs to be rounded to the nearest even mantissa, which is 8388608
. However accurate
doesn't do this correctly:
let a: f32 = 4194304.0;
let b: f32 = 4194304.5;
println!("a = {:.1}", a);
println!("b = {:.1}", b);
println!("a + b = {:.1}", a + b);
use accurate::traits::SumAccumulator;
let s1 = accurate::sum::OnlineExactSum::zero().absorb([a, b]).sum();
let s2 = accurate::sum::i_fast_sum_in_place(&mut [a, b]);
println!("OnlineExactSum: {:.1}", s1);
println!("i_fast_sum: {:.1}", s2);
The above prints:
a = 4194304.0
b = 4194304.5
a + b = 8388608.0
OnlineExactSum: 8388609.0
i_fast_sum: 8388609.0
error[E0034]: multiple applicable items in scope
--> /home/parrot/.cargo/registry/src/github.com-1ecc6299db9ec823/accurate-0.3.0/src/sum/ifastsum.rs:78:32
|
78 | sm = sm.max(st.abs());
| ^^^ multiple abs
found
|
note: candidate #1 is defined in the trait ieee754::Ieee754
--> /home/parrot/.cargo/registry/src/github.com-1ecc6299db9ec823/ieee754-0.2.6/src/traits.rs:472:5
|
472 | fn abs(self) -> Self;
| ^^^^^^^^^^^^^^^^^^^^^
note: candidate #2 is defined in the trait num::Float
--> /home/parrot/.cargo/registry/src/github.com-1ecc6299db9ec823/num-traits-0.2.12/src/float.rs:1191:5
|
1191 | fn abs(self) -> Self;
| ^^^^^^^^^^^^^^^^^^^^^
help: disambiguate the associated function for candidate #1
|
78 | sm = sm.max(ieee754::Ieee754::abs(st));
| ^^^^^^^^^^^^^^^^^^^^^^^^^
help: disambiguate the associated function for candidate #2
|
78 | sm = sm.max(num::Float::abs(st));
| ^^^^^^^^^^^^^^^^^^^
error: aborting due to previous error
For more information about this error, try rustc --explain E0034
.
error: could not compile accurate
.
To learn more, run the command again with --verbose.
warning: build failed, waiting for other jobs to finish...
error: build failed
Ubuntu 20.04
stable-x86_64-unknown-linux-gnu (default)
rustc 1.47.0 (18bf6b4f0 2020-10-07)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.