Contributors: @cuviper, @michaelciraci
- The new
Euclid::div_rem_euclid
andCheckedEuclid::checked_div_rem_euclid
methods compute and return the quotient and remainder at the same time. - The new
TotalOrder
trait implements the IEEE 754totalOrder
predicate. - The new
ConstZero
andConstOne
traits offered associated constants, extending the non-constZero
andOne
traits for types that have constant values.
Contributors: @andrewjradcliffe, @cuviper, @tarcieri, @tdelabro, @waywardmonkeys
Contributors: @robamu
- Upgrade to 2018 edition, MSRV 1.31
- The new
ToBytes
andFromBytes
traits convert to and from byte representations of a value, with little, big, and native-endian options. - The new
Float::is_subnormal
method checks for subnormal values, with a non-zero magnitude that is less than the normal minimum positive value. - Several other improvements to documentation and testing.
Contributors: @ctrlcctrlv, @cuviper, @flier, @GuillaumeGomez, @kaidokert, @rs017991, @vicsn
- The new
Euclid
trait calculates Euclidean division, where the remainder is always positive or zero. - The new
LowerBounded
andUpperBounded
traits separately describe types with lower and upper bounds. These traits are automatically implemented for all fully-Bounded
types. - The new
Float::copysign
method copies the sign of the argument to to the magnitude ofself
. - The new
PrimInt::leading_ones
andtrailing_ones
methods are the complement of the existing methods that count zero bits. - The new
PrimInt::reverse_bits
method reverses the order of all bits of a primitive integer. - Improved
Num::from_str_radix
for floats, also ignoring case. Float
andFloatCore
use more fromlibm
when that is enabled.
Contributors: @alion02, @clarfonthey, @cuviper, @ElectronicRU, @ibraheemdev, @SparrowLii, @sshilovsky, @tspiteri, @XAMPPRocky, @Xiretza
- Clarify the license specification as "MIT OR Apache-2.0".
Contributors: @cuviper
- The new
OverflowingAdd
,OverflowingSub
, andOverflowingMul
traits return a tuple with the operation result and abool
indicating overflow. - The "i128" feature now overrides compiler probes for that support.
This may fix scenarios where
autocfg
probing doesn't work properly. - Casts from large
f64
values tof32
now saturate to infinity. They previously returnedNone
because that was once thought to be undefined behavior, but rust#15536 resolved that such casts are fine. Num::from_str_radix
documents requirements for radix support, which are now more relaxed than previously implied. It is suggested to accept at least2..=36
without panicking, butErr
may be returned otherwise.
Contributors: @cuviper, @Enet4, @KaczuH, @martin-t, @newpavlov
- The new
WrappingNeg
trait will wrap the result if it exceeds the boundary of the type, e.g.i32::MIN.wrapping_neg() == i32::MIN
. - The new
SaturatingAdd
,SaturatingSub
, andSaturatingMul
traits will saturate at the numeric bounds if the operation would overflow. These soft-deprecate the existingSaturating
trait that only has addition and subtraction methods. - Added new constants for logarithms,
FloatConst::{LOG10_2, LOG2_10}
.
Contributors: @cuviper, @ocstl, @trepetti, @vallentin
Contributors: @cuviper, @m-ou-se
Contributors: @CryZe
- A new optional
libm
dependency enables theFloat
andReal
traits inno_std
builds. - The new
clamp_min
andclamp_max
limit minimum and maximum values while preserving inputNAN
s. - Fixed a panic in floating point
from_str_radix
on invalid signs. - Miscellaneous documentation updates.
Contributors: @cuviper, @dingelish, @HeroicKatora, @jturner314, @ocstl, @Shnatsel, @termoshtt, @waywardmonkeys, @yoanlcq
Contributors: @cuviper
- Documented when
CheckedShl
andCheckedShr
returnNone
. - The new
Zero::set_zero
andOne::set_one
will set values to their identities in place, possibly optimized better than direct assignment. - Documented general features and intentions of
PrimInt
.
Contributors: @cuviper, @dvdhrm, @ignatenkobrain, @lcnr, @samueltardieu
- Documented that
pow(0, 0)
returns1
. Mathematically, this is not strictly defined, but the current behavior is a pragmatic choice that has precedent in Rustcore
for the primitives and in many other languages. - The new
WrappingShl
andWrappingShr
traits will wrap the shift count if it exceeds the bit size of the type.
Contributors: @cuviper, @edmccard, @meltinglava
- Documentation for
mul_add
now clarifies that it's not always faster. - The default methods in
FromPrimitive
andToPrimitive
are more robust.
Contributors: @cuviper, @frewsxcv
- Support for 128-bit integers is now automatically detected and enabled.
Setting the
i128
crate feature now causes the build script to panic if such support is not detected.
Contributors: @cuviper
- The new
CheckedNeg
andCheckedRem
traits perform checkedNeg
andRem
, returningSome(output)
orNone
on overflow. - The
no_std
implementation ofFloatCore::to_degrees
forf32
now uses a constant for greater accuracy, mirroring rust#47919. (Withstd
it just calls the inherentf32::to_degrees
in the standard library.) - The new
MulAdd
andMulAddAssign
traits perform a fused multiply- add. For integer types this is just a convenience, but for floating point types this produces a more accurate result than the separate operations. - All applicable traits are now implemented for 128-bit integers starting
with Rust 1.26, enabled by the new
i128
crate feature. TheFromPrimitive
andToPrimitive
traits now also have corresponding 128-bit methods, which default to converting via 64-bit integers for compatibility.
Contributors: @cuviper, @LEXUGE, @regexident, @vks
- Casting from floating point to integers now returns
None
on overflow, avoiding rustc's undefined behavior. This applies to thecast
function and the traitsNumCast
,FromPrimitive
, andToPrimitive
.
Contributors: @apopiak, @cuviper, @dbarella
- The new
FloatCore
trait offers a subset ofFloat
for#![no_std]
use. This includes everything except the transcendental functions and FMA. - The new
Inv
trait returns the multiplicative inverse, or reciprocal. - The new
Pow
trait performs exponentiation, much like the existingpow
function, but with generic exponent types. - The new
One::is_one
method tests if a value equals 1. Implementers should override this method if there's a more efficient way to check for 1, rather than comparing with a temporaryone()
.
Contributors: @clarcharr, @cuviper, @vks
- breaking change: There is now a
std
feature, enabled by default, along with the implication that building without this feature makes this a#![no_std]
crate.- The
Float
andReal
traits are only available whenstd
is enabled. - Otherwise, the API is unchanged, and num-traits 0.1.43 now re-exports its items from num-traits 0.2 for compatibility (the semver-trick).
- The
Contributors: @cuviper, @termoshtt, @vks
- All items are now re-exported from num-traits 0.2 for compatibility.
- num-traits now has its own source repository at rust-num/num-traits.
ParseFloatError
now implementsDisplay
.- The new
AsPrimitive
trait implements generic casting with theas
operator. - The new
CheckedShl
andCheckedShr
traits implement generic support for thechecked_shl
andchecked_shr
methods on primitive integers. - The new
Real
trait offers a subset ofFloat
functionality that may be applicable to more types, with a blanket implementation for all existingT: Float
types.
Thanks to @cuviper, @Enet4, @fabianschuiki, @svartalf, and @yoanlcq for their contributions!
No prior release notes were kept. Thanks all the same to the many contributors that have made this crate what it is!