Commit Graph

102 Commits

Author SHA1 Message Date
Josh Stone c4256bd4df Don't use libm at all with std 2019-09-27 10:53:17 -07:00
Yoan Lecoq 849e2a0b1b Always enable Real, feature gate Float - Real forwarding 2019-09-27 10:53:17 -07:00
Yoan Lecoq fec6c3610c Revive Float+Real in no_std with libm 2019-09-27 10:53:17 -07:00
Jim Turner 987ed8fd38 Split clamp panicking test into separate tests 2019-09-23 22:21:33 -04:00
Jim Turner d02f166765 Restrict panic testing to when std is enabled 2019-09-23 22:14:03 -04:00
Jim Turner 33b74618b6 Debug-panic in clamp_min/max if min/max is NAN
This also improves the docs for `clamp`, `clamp_min`, and `clamp_max`.
2019-09-23 20:59:34 -04:00
bors[bot] 428f89a7d5
Merge #122
122: NAN preserving clamp_lower/upper r=cuviper a=termoshtt

`NAN` preserving lower- and upper-clamp.

Cc: https://github.com/rust-ndarray/ndarray/issues/470#issuecomment-521809782

Co-authored-by: Toshiki Teramura <toshiki.teramura@gmail.com>
2019-09-14 18:23:57 +00:00
Toshiki Teramura 0e7c2a4a00 s/less/greater/g 2019-09-14 15:59:10 +09:00
Toshiki Teramura 973ba72e4f Fix doc comment 2019-08-31 15:34:40 +09:00
Toshiki Teramura e7ba9b62dc Replace lower/upper to min/max 2019-08-31 15:31:30 +09:00
Toshiki Teramura 2fb8a6e8a9 Add NaN preserving test for clamp 2019-08-31 15:14:49 +09:00
Andreas Molzer cd0da1ae5e Fix num parsing for invalid multi-byte sign chars
Ensure that splitting the potential sign character from the remainder
respects UTF8 boundaries. This lets invalid characters fail correctly
with an error, instead of panicking.
2019-08-30 22:27:32 +02:00
Toshiki Teramura f20d74fce8 Use core::f32 instead of std::f32 2019-08-17 17:58:02 +09:00
Toshiki Teramura e8dce19146 Add clamp_{lower,upper} 2019-08-17 16:45:04 +09:00
Josh Stone c38b4b601d cargo fmt 2019-04-16 14:30:46 -07:00
Ed McCardell abb51f9a09 Add wrapping shifts
Add traits `WrappingShl` and `WrappingShr` corresponding to the
standard library `wrapping_shl` and `wrapping_shr` methods. Implement
the trait on all primitive integer types as well as on `Wrapping`.
2018-09-02 00:51:04 -04:00
Josh Stone d2bf4e04e4 Run cargo fmt 2018-07-12 17:09:22 -07:00
Josh Stone 51f6c57c4b Automatically detect support for i128/u128 2018-05-11 15:50:48 -07:00
Josh Stone f35cce229e Always use #![no_std], and declare std when enabled 2018-05-08 17:26:38 -07:00
Josh Stone 261efafe0b Merge branch 'master' into regexident-i128 2018-05-04 12:28:48 -07:00
bors[bot] a49013e338 Merge #59
59: Added `MulAdd` and `MulAddAssign` traits r=cuviper a=regexident

Both `f32` and `f64` implement fused multiply-add, which computes `(self * a) + b` with only one rounding error. This produces a more accurate result with better performance than a separate multiplication operation followed by an add:

```rust
fn mul_add(self, a: f32, b: f32) -> f32[src]
```

It is however not possible to make use of this in a generic context by abstracting over a trait.

My concrete use-case is machine learning, [gradient descent](https://en.wikipedia.org/wiki/Gradient_descent) to be specific,  
where the core operation of updating the gradient could make use of `mul_add` for both its `weights: Vector` as well as its `bias: f32`:

```rust
struct Perceptron {
  weights: Vector,
  bias: f32,
}

impl MulAdd<f32, Self> for Vector {
  // ...
}

impl Perceptron {
  fn learn(&mut self, example: Vector, expected: f32, learning_rate: f32) {
    let alpha = self.error(example, expected, learning_rate);
    self.weights = example.mul_add(alpha, self.weights);
    self.bias = self.bias.mul_add(alpha, self.bias)
  }
}
```

(The actual impl of `Vector` would be generic over its value type: `Vector<T>`, thus requiring the trait.)

Co-authored-by: Vincent Esche <regexident@gmail.com>
Co-authored-by: Josh Stone <cuviper@gmail.com>
2018-05-04 19:12:41 +00:00
Josh Stone aa21fba9fc re-export CheckedRem and CheckedNeg at the root 2018-04-13 14:14:49 -07:00
Vincent Esche 152b38e03f Added impls of `Num` for `i128` and `u128` 2018-04-10 10:39:54 +02:00
Vincent Esche 830363024b Added `MulAdd` and `MulAddAssign` traits 2018-04-10 10:08:55 +02:00
Josh Stone c848562fcf Use forwarding macros to implement Float and Real 2018-02-27 16:33:04 -08:00
Clar Charr ce3badca57 Move Pow to pow module. 2018-02-27 13:25:53 -05:00
Clar Charr c1f4118b4e Fix Inv trait, add Pow trait. 2018-02-27 13:25:53 -05:00
Clar Charr 5bdff3f0ff Add Inv trait. 2018-02-27 13:25:53 -05:00
bors[bot] bfd62d4638 Merge #32
32: Implement CoreFloat trait r=cuviper a=vks

This is a subset of the `Float` trait, but works with `no_std`.
Some code was simplified by using `CoreFloat`.
2018-02-07 22:26:47 +00:00
Vinzent Steinberg d115dadeb1 Don't re-export FloatCore
This avoids breaking `use num_traits::*`.
2018-02-07 12:42:30 +01:00
Vinzent Steinberg efad5329b4 Rename CoreFloat to FloatCore 2018-02-07 12:34:14 +01:00
Vinzent Steinberg 8a7f383eb1 Implement CoreFloat trait
This is a subset of the `Float` trait, but works with `no_std`.
Some code was simplified by using `CoreFloat`.
2018-02-02 19:48:25 +01:00
Josh Stone 47515a10e1 Add a min-rustc badge and document compatibility 2018-02-02 10:24:14 -08:00
Josh Stone 67f03391a1 Bump to 0.2 for the breaking feature change 2018-01-31 16:19:00 -08:00
Josh Stone 4fbc583eb9 Don't use wildcards for pub use 2018-01-31 16:05:43 -08:00
Josh Stone e6bb97b3ac Make `Float` and `Real` depend on the `std` feature
We don't have implementations for many of the methods in `no_std`.  It's
hostile to external implementors if some trait methods are conditional
on a feature, as that feature could be added by anyone in a dependency
tree.  Instead, let's just live without these traits for now.
2018-01-31 15:56:06 -08:00
Vinzent Steinberg a843027b56 Re-introduce the std feature
This is a port of @vks's rust-num/num#296, but without the feature-
toggled changes to `Float`.
2018-01-31 15:42:55 -08:00
bors[bot] 93be5dbff2 Merge #23
23: Add RealNum trait for real data types (Float, but without floating-point specific features) r=cuviper a=yoanlcq

This is supposed to fix [#19](https://github.com/rust-num/num-traits/issues/19); I assumed going ahead would be better than bumping the thread.  

In any case, I understand that it is a quite significant addition and won't mind too much if it doesn't make it.

This adds a new `RealNum` trait, along with a universal impl `impl<T: Float> RealNum for T { ... }`.  
Therefore, this shouldn't be a breaking change, except in places where both traits are imported (which obviously only happened in a few places in this crate).

The intent is that generic code may prefer to use `RealNum` instead of `Float` when floating-point isn't a requirement. In the future (next major version ?), I guess `Float` could be made to only provide floating-point-specific features on top of `RealNum`.

Most of the code+doc was copy-pasted from `Float`, but the doc comments should be up-to-date with the situation; `Float` only makes an appearance when talking about NaN and infinity.

Issues I've seen : 
- `RealNum` might not be the name we want;
- I've mentioned that `sqrt()` is allowed to panic if the input is negative and has no meaningful NaN representation;
- Should we do that too for e.g `log()` ? Like `sqrt()`, it's supposed to return Nan when `x < 0`.

Thanks for your time. :)
2018-01-19 01:39:13 +00:00
Yoan Lecoq ddd664ae2b RealNum -> Real 2018-01-06 15:51:10 +01:00
Yoan Lecoq 52c87dd410 Remove 2018-01-05 10:01:29 +01:00
Yoan Lecoq 5a6997c1c8 Add RealNum trait 2018-01-05 09:06:23 +01:00
svartalf 53ab360d94 std::fmt::Display implemented for ParseFloatError 2018-01-04 16:46:02 +03:00
Josh Stone 42a610d323 Move num-traits to its own repo
All the prior `num` history is kept, so old `num-traits` tags are still
valid, but future development here will be just for `num-traits`.
2017-12-18 17:35:41 -08:00
Jacob Kiesel f8dcec366b Made requested changes. 2017-02-07 13:02:32 -07:00
Jacob Kiesel 182e08a091 Add inline attribute 2017-02-07 10:49:28 -07:00
Jacob Kiesel b346f9c2df Add a new line for improved formatting. 2017-02-07 10:18:23 -07:00
Jacob Kiesel a5445b7619 Adding documentation comments 2017-02-07 10:18:23 -07:00
Jacob Kiesel 07ff5b62b9 Changing to >= and <= as it's a slight optimization 2017-02-07 09:52:23 -07:00
Jacob Kiesel 28633b7e6d Add clamp function 2017-02-07 09:48:34 -07:00
bluss ff2a350e98 Use the integer32 playground 2016-11-02 19:51:10 +01:00