| Age | Commit message (Collapse) | Author | Lines |
|
|
|
|
|
Explicitly call out when it returns NaN, adhere to the panic doc
guidelines.
|
|
|
|
|
|
Clarify distinction between floor() and trunc()
`floor()` rounds towards `-INF`, `trunc()` rounds towards 0.
This PR clarifies this in the examples.
|
|
Add clamp for ranges. Implements #44095
Ready for merge
|
|
|
|
|
|
|
|
|
|
|
|
logic is written up in https://github.com/rust-lang/rust/issues/49048
Also, update the documentation slightly
|
|
`max` on floats returns the other argument if one of them is NaN, which
would be `0.0` in this case. This is unlike the C functions `fdim` and
`fdimf` which return NaN if either of their arguments is NaN.
https://doc.rust-lang.org/1.31.0/std/primitive.f32.html#method.max
https://en.cppreference.com/w/c/numeric/math/fdim
|
|
Thanks to @LukasKalbertodt for catching this. Addresses a comment
raised in #55169 after it was merged.
|
|
Added a #[must_use] annotation on copysign, per review feedback.
|
|
I improved the f32 version and made a copy-paste error for f64.
|
|
This patch adds a `copysign` function to the float primitive types.
It is an exceptionally useful function for writing efficient numeric
code, as it often avoids branches, is auto-vectorizable, and there
are efficient intrinsics for most platforms.
I think this might work as-is, as the relevant `copysign` intrinsic
is already used internally for the implementation of `signum`. It's
possible that an implementation might be needed in japaric/libm for
portability across all platforms, in which case I'll do that also.
Part of the work towards #55107
|
|
|
|
|
|
|
|
This is recommend by [RFC 0505] and as far as I know, the only primitive
types without this heading.
[RFC 0505]: https://github.com/rust-lang/rfcs/blob/c892139be692586e0846fbf934be6fceec17f329/text/0505-api-comment-conventions.md#using-markdown
|
|
Move "See also" disambiguation links for primitive types to top
Closes #50384.
<details>
<summary>Images</summary>


</details>
r? @steveklabnik
|
|
|
|
Fixes https://github.com/rust-lang/rust/issues/49842.
Other resources:
- https://users.rust-lang.org/t/why-does-the-mul-add-method-produce-a-more-accurate-result-with-better-performance/1626
- https://en.wikipedia.org/wiki/Multiply%E2%80%93accumulate_operation
|
|
Affected methods are `abs`, `signum`, and `powi`.
CC https://github.com/rust-lang/rust/issues/32110#issuecomment-379503183
|
|
… previously in the unstable core::num::Float trait.
Per https://github.com/rust-lang/rust/issues/32110#issuecomment-379503183,
the `abs`, `signum`, and `powi` methods are *not* included for now
since they rely on LLVM intrinsics and we haven’t determined yet whether
those instrinsics lower to calls to libm functions on any platform.
|
|
|
|
Tracking issue: #49048
|
|
and included that it returns radians
|
|
|
|
The current `f32|f64.to_degrees` implementation uses a division to calculate 180/π, which causes a loss of precision. Using a constant is still not perfect (implementing a maximally-precise algorithm would come with a high performance cost), but improves precision with a minimal change.
|
|
Expose float from_bits and to_bits in libcore.
These methods have no dependencies on libm and thus should be offered in libcore.
|
|
|
|
|
|
|
|
|
|
Make float::from_bits transmute
See commit message for details.
See also this discussion here: https://github.com/rust-lang/rust/issues/40470#issuecomment-343803381
(may require libs team discussion before merging)
|
|
The current implementation/documentation was made to avoid sNaN because of
potential safety issues implied by old/bad LLVM documentation. These issues
aren't real, so we can just make the implementation transmute (as permitted
by the existing documentation of this method).
Also the documentation didn't actually match the behaviour: it said we may
change sNaNs, but in fact we canonicalized *all* NaNs.
Also an example in the documentation was wrong: it said we *always* change
sNaNs, when the documentation was explicitly written to indicate it was
implementation-defined.
This makes to_bits and from_bits perfectly roundtrip cross-platform, except
for one caveat: although the 2008 edition of IEEE-754 specifies how to
interpet the signaling bit, earlier editions didn't. This lead to some platforms
picking the opposite interpretation, so all signaling NaNs on x86/ARM are quiet
on MIPS, and vice-versa.
NaN-boxing is a fairly important optimization, while we don't even guarantee
that float operations properly preserve signalingness. As such, this seems like
the more natural strategy to take (as opposed to trying to mangle the signaling
bit on a per-platform basis).
This implementation is also, of course, faster.
|
|
|
|
This commit adds a new target to the compiler: wasm32-unknown-unknown. This
target is a reimagining of what it looks like to generate WebAssembly code from
Rust. Instead of using Emscripten which can bring with it a weighty runtime this
instead is a target which uses only the LLVM backend for WebAssembly and a
"custom linker" for now which will hopefully one day be direct calls to lld.
Notable features of this target include:
* There is zero runtime footprint. The target assumes nothing exists other than
the wasm32 instruction set.
* There is zero toolchain footprint beyond adding the target. No custom linker
is needed, rustc contains everything.
* Very small wasm modules can be generated directly from Rust code using this
target.
* Most of the standard library is stubbed out to return an error, but anything
related to allocation works (aka `HashMap`, `Vec`, etc).
* Naturally, any `#[no_std]` crate should be 100% compatible with this new
target.
This target is currently somewhat janky due to how linking works. The "linking"
is currently unconditional whole program LTO (aka LLVM is being used as a
linker). Naturally that means compiling programs is pretty slow! Eventually
though this target should have a linker.
This target is also intended to be quite experimental. I'm hoping that this can
act as a catalyst for further experimentation in Rust with WebAssembly. Breaking
changes are very likely to land to this target, so it's not recommended to rely
on it in any critical capacity yet. We'll let you know when it's "production
ready".
---
Currently testing-wise this target is looking pretty good but isn't complete.
I've got almost the entire `run-pass` test suite working with this target (lots
of tests ignored, but many passing as well). The `core` test suite is still
getting LLVM bugs fixed to get that working and will take some time. Relatively
simple programs all seem to work though!
---
It's worth nothing that you may not immediately see the "smallest possible wasm
module" for the input you feed to rustc. For various reasons it's very difficult
to get rid of the final "bloat" in vanilla rustc (again, a real linker should
fix all this). For now what you'll have to do is:
cargo install --git https://github.com/alexcrichton/wasm-gc
wasm-gc foo.wasm bar.wasm
And then `bar.wasm` should be the smallest we can get it!
---
In any case for now I'd love feedback on this, particularly on the various
integration points if you've got better ideas of how to approach them!
|
|
This commit moves the `f32::cmath` and `f64::cmath` modules into the
`sys` module. Note that these are not publicly exported modules, simply
implementation details. These modules are already platform-specific with
shims on MSVC and this is mostly just a reflection of that reality. This
should also help cut down on `#[cfg]` traffic if platforms are brought on
which don't directly support these functions.
|
|
This reverts commit c589f867f89d4e6e48c6602aed8e878208d4822f.
|
|
This reverts commit f74c5d2e18e50c24de2cc1192bf2088cdaa61916.
|
|
This reverts commit 61f20f8df02e53ee60dc1719ce0e502eecebf8b4.
|
|
This reverts commit 2e34ff767113c6a15c5862b0646ca9ad7ffd81b1.
|
|
This reverts commit b762283e57ff71f6763effb9cfc7fc0c7967b6b0.
|
|
|
|
|
|
|