rdrpenguin04 / mathy-notes

Do math in your text editor! Ctrl-Enter or Shift-Enter to evaluate. Mainly a personal project, do not expect stability from this.
1 stars 1 forks source link

Better precision #4

Open rdrpenguin04 opened 1 year ago

rdrpenguin04 commented 1 year ago

f64 has run into overlow/underflow errors with my homework; advising switching to Decimal128 at suggestion of an LC member.

rdrpenguin04 commented 1 year ago

The decimal crate's d128 looks like a promising candidate. It's missing a few things that mathy-notes needs, like trig, particularly inverse trig, mathematical constants, and sqrt and co (but pow exists).

The dec crate seems to very possibly use the same library, and it's maintained, but it's also woefully under-featured, missing all of the above, and some features are tucked away in strange places.

The fraction crate is impressive and could be useful in the future, but it doesn't solve the feature problem; rather, it makes the problem significantly worse by having to work around fractions being represented perfectly. The infrastructure is also incredibly bulky.

The best solution I see for now is to use f128 (uses GCC's libquadmath) and roll our own in the future.

rdrpenguin04 commented 1 year ago

Nevermind. f128 somehow has even less features.

Agh.

rdrpenguin04 commented 1 year ago

rust-lang/rfcs#2629

rdrpenguin04 commented 4 months ago

Nearly there: rust-lang/rust#127027

This will be a nightly feature, but I'm okay with that.

tgross35 commented 4 months ago

Nearly there: rust-lang/rust#127027

This will be a nightly feature, but I'm okay with that.

As a pretty important note, the math functions are completely broken on x86 due to LLVM bugs :( (LLVM incorrectly calls the long double functions on x86, which are x87 80-bit floats and not binary128).

Aarch64 works alright though!

(Just came across this since I saw it crosslinked in the PR).

tgross35 commented 4 months ago

That being said, depending on what your use case is and if you may need more than 128 bits of precision, something like an arbitrary-precision library may be a better fit https://docs.rs/rug/latest/rug/.

rdrpenguin04 commented 3 months ago

Ooh, that's actually a really good point; thank you! :D