Comments (4)
I see, this is from src/libtest/stats.rs
.
I'm not sure about using an intermediate object like that. Can it just be an associated function?
trait Float {
...
fn stable_sum<I: IntoIterator<Item = Self>(iter: I) -> Self { ... }
}
from num-traits.
From @vks on June 29, 2017 7:52
It could be an associated function, but then it would be less general:
incremental calculations would not be possible.
On Thu, Jun 29, 2017, 03:30 Josh Stone [email protected] wrote:
I see, this is from src/libtest/stats.rs
https://github.com/rust-lang/rust/blob/69c65d29615c391c958ebf75dd65258ec23e175c/src/libtest/stats.rs#L164-L196
.I'm not sure about using an intermediate object like that. Can it just be
an associated function?trait Float {
...
fn stable_sum<I: IntoIterator<Item = Self>(iter: I) -> Self { ... }
}—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
rust-num/num#309 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AACCtIKZpUXsAvKzyGu7ZsffLK9fKU0kks5sIv4xgaJpZM4OGjrD
.
from num-traits.
I believe the proposed implementation will give incorrectly-rounded results on some inputs. The function
fn sum(&self) -> f64 {
self.partials.iter().fold(0., |p, q| p + *q)
}
sums the partials naively. Why this is a problem is explained here: https://code.activestate.com/recipes/393090/#c16
I've found a testcase that shows the difference: the vector [1e-16, 1.0, 1e16]
should sum to 1.0000000000000002e+16
, but instead sums to 1.0000000000000000e+16
. This error is masked somehow by the 10,000x looping. Is there a reason the current testcase does this?
I'm not familiar enough with Rust to suggest a fix with confidence, but Python's fsum
gives the correct result. Its source can be found here: https://hg.python.org/cpython/file/tip/Modules/mathmodule.c#l1112, with the interesting bit starting on line 1199 (The correct line number may change over time; I can't tell how to make a working permanent link.)
from num-traits.
A note about the N
times looping: for the [1e-16, 1, 1e16]
case, N <= 2048
correctly causes the assertion to fail, but N > 2048
doesn't. It's a little late in the evening for me to pin down why things change at that power of two. I suspect a rounding error somewhere.
from num-traits.
Related Issues (20)
- Why not make zero() and one() as const functions? HOT 2
- Add trigonometry functions HOT 1
- constifying traits in an nighlty branch or feature gate it? (with #[const_trait]) HOT 2
- `cargo doc` fails if they run it with nightly Rust HOT 2
- New nightly version broke `cargo-doc`, unintended use of unstable feature HOT 3
- Is there any hope of seeing a minor release anytime soon? HOT 1
- add a quotien_and_rem_euclid method to Euclid trait HOT 1
- Document and/or allow truncation/rounding when casting from float to int? HOT 4
- Feature request: OverflowingShl HOT 2
- Feature request: can we have a trait for checked_add_signed uX implementations?
- Add `BitOrAssign` etc. to `PrimInt` HOT 4
- Introduce derive macros HOT 1
- Adding {ilog, ilog2, ilog10} to PrimInt HOT 1
- Add `trait UnsignedAbs` HOT 3
- feat: ToPrimitive split into ToFloatPrimitive and ToIntegerPrimitive HOT 7
- Add `round_to_digit` method to `Float` trait. HOT 2
- `struct` built on top of `pub trait Num` can't compile if `pub trait Num` doesn't impl `Debug` HOT 4
- Add `Hash` as a trait bound for `PrimInt` HOT 2
- Add is_signed HOT 1
- [Build-script] unable to determine target details for custom target-spec HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from num-traits.