rust-num / num-traits

Numeric traits for generic mathematics in Rust
Apache License 2.0
732 stars 135 forks source link

Document cast traits about possible precision loss and truncation #176

Closed Enet4 closed 4 years ago

Enet4 commented 4 years ago

Resolves #175. Document the traits ToPrimitive, FromPrimitive and NumCast that value can be represented by the target type when they are within the range admitted by the target type, and so truncation or precision loss may happen.

One question worth reflecting on is whether this documentation be normalized somewhere at module level, and whether it should be replicated to all methods or simply stay at each trait. I would also be open to adding examples with doctests if deemed useful.

cuviper commented 4 years ago

This looks good to me, thanks!

bors r+

One question worth reflecting on is whether this documentation be normalized somewhere at module level,

While it could go on the cast module, these traits are also re-exported at the root, so I don't know how often folks would even see the module-level documentation.

and whether it should be replicated to all methods or simply stay at each trait.

I think that would be overkill. The trait-level docs are already on the same page as all the methods.

I would also be open to adding examples with doctests if deemed useful.

It's clear enough to me what is meant by precision loss and truncation, but if you'd like to follow up with some examples, that would be fine.

bors[bot] commented 4 years ago

Build succeeded: