Commit Graph

525 Commits

Author SHA1 Message Date
Trevor Spiteri 5b7d05b775 docs: change wording from truncate to discard fractional bits
Truncation might be interpreted to mean rounding towards zero, which
is not what happens in negative two's-complement fixed-point numbers.
So "extra fractional bits are truncated" is better as "extra
fractional bits are discarded, which rounds towards −∞."
2020-05-10 18:43:22 +02:00
Trevor Spiteri 961d36aa2a update half dependency to 1.6 2020-05-10 10:49:09 +02:00
Trevor Spiteri c13ab2e324 add wrapping_next_power_of_two 2020-05-10 01:13:24 +02:00
Trevor Spiteri dfb59cefc0 add leading_ones and trailing_ones 2020-05-10 01:09:41 +02:00
Trevor Spiteri 609f75575f fmt nit in doc example 2020-05-08 15:55:49 +02:00
Trevor Spiteri 2b4e051ded add some tests 2020-05-08 15:43:01 +02:00
Trevor Spiteri e3fe9b7f9c implement LosslessTryFrom for lossless integer <-> float combinations 2020-05-08 15:19:09 +02:00
Trevor Spiteri c2847491cb implement LosslessTryFrom for lossless fixed <-> float combinations 2020-05-08 14:23:23 +02:00
Trevor Spiteri c196899bcc implement LosslessTryFrom for all fixed<U0> -> integer combinations 2020-05-08 13:31:50 +02:00
Trevor Spiteri 234dbfecdc implement LosslessTryFrom for all integer -> fixed combinations 2020-05-08 13:20:47 +02:00
Trevor Spiteri bc5e01120f add LosslessTry{From,Into} and immplement them for Fixed <-> Fixed 2020-05-08 12:41:35 +02:00
Trevor Spiteri f23ddc6616 improve first line of module docs 2020-05-08 00:51:56 +02:00
Trevor Spiteri eebb76e7b0 fix typos in tests and release notes 2020-05-08 00:37:14 +02:00
Trevor Spiteri 232decb692 add names to some constants 2020-05-07 23:48:48 +02:00
Trevor Spiteri 37167fddd0 add golden ratio and its conjugate to constants 2020-05-07 23:36:35 +02:00
Trevor Spiteri eb7e369775 document impl blocks 2020-05-03 17:56:04 +02:00
Trevor Spiteri ff0874a1f4 require rustc 1.43.0
Will probably bump requirement to 1.44.0 before releasing 1.0.0 so
that {from,to}_{le,be,ne}_bytes can be const fn.
2020-05-03 16:08:11 +02:00
Trevor Spiteri 48a763c01f tweak wording on version 2 plan 2020-05-02 21:22:46 +02:00
Trevor Spiteri eb51b85db5 remove reimplementation of wrapping_signum in Wrapping::signum 2020-05-02 21:19:44 +02:00
Trevor Spiteri 879861b875 remove deprecated items 2020-05-01 18:28:17 +02:00
Trevor Spiteri 079a13ca1b version 0.5.6 2020-05-01 18:15:40 +02:00
Trevor Spiteri 86b542e7f3 add Lossy{From,Into} to prelude 2020-05-01 17:40:53 +02:00
Trevor Spiteri 672973c99f Revert "remove deprecated items"
This reverts commit f67aed0078.
2020-04-18 19:13:08 +02:00
Trevor Spiteri 74f0e4f575 add checked versions of signum 2020-04-18 18:15:22 +02:00
Trevor Spiteri 339bd1f5aa specify version 2 when talking about const generics plan 2020-04-18 02:29:04 +02:00
Trevor Spiteri f67aed0078 remove deprecated items 2020-04-18 02:21:17 +02:00
Trevor Spiteri f8f9bd69ba add some coverage 2020-04-17 22:11:57 +02:00
Trevor Spiteri 8d8fde75c5 remove unused functions 2020-04-17 21:48:25 +02:00
Trevor Spiteri a47367fa6b make reasoning clearer in log10 2020-04-17 21:31:13 +02:00
Trevor Spiteri ed49d69e18 test constant LOG2_10 and LOG10_2 with f16 and bf16 2020-04-17 17:21:37 +02:00
Trevor Spiteri 800ed3a58c az::StaticCast is deprecated 2020-04-17 17:20:25 +02:00
Trevor Spiteri 9bb95c5a5c remove unused macro parameter 2020-04-17 00:01:00 +02:00
Trevor Spiteri 97d4e1a326 version 0.5.5 2020-04-16 23:29:50 +02:00
Trevor Spiteri 289f4b1697 add constants in consts module as associated constants 2020-04-16 23:08:29 +02:00
Trevor Spiteri 68c0fa6f8d include generator in consts.rs 2020-04-16 23:05:53 +02:00
Trevor Spiteri 5db3b17284 fix comparison of e.g. I0F16 with +0.5 2020-04-16 21:19:30 +02:00
Trevor Spiteri 4c25f002a1 update copyright date 2020-04-13 20:11:39 +02:00
Trevor Spiteri 36ef9cae03 use macro to avoid repetitions in log10 tests 2020-04-13 18:12:56 +02:00
Trevor Spiteri f038d17921 some log10 cleanups 2020-04-13 05:23:29 +02:00
Trevor Spiteri de69767a3c fmt 2020-04-13 04:28:23 +02:00
Trevor Spiteri b0f6deab9e some log10 optimizations 2020-04-13 04:27:36 +02:00
Trevor Spiteri a32b56ab43 add int_log10 and checked_int_log10 2020-04-13 03:17:21 +02:00
Trevor Spiteri 919519fea1 doc nits 2020-04-13 00:27:42 +02:00
Trevor Spiteri e8f3ff2c67 replace {min,max}_value() by {MIN,MAX} in examples
There are hidden import lines

    use std::primitive;

that should be removed once MIN and MAX are supported by the minimum
supported rustc.
2020-04-11 19:23:58 +02:00
Trevor Spiteri 47287ab98f replace {int,frac}_nbits() by {INT,FRAC}_NBITS 2020-04-11 18:50:26 +02:00
Trevor Spiteri e1febebb31 replace {min,max}_value() by {MIN,MAX} 2020-04-11 18:34:52 +02:00
Trevor Spiteri 91bd73bca4 add int_log2 and checked_int_log2 2020-04-11 17:44:09 +02:00
Trevor Spiteri 060b58af13 doc: use [`true`] instead of [`true`][`bool`]
This is because link markdown is not interpreted in search results, so
at least bool is not displayed.
2020-04-11 16:54:22 +02:00
Trevor Spiteri b41c726da5 test constant LOG2_10 and LOG10_2
Before this commit, the tests were skipped because the corresponding
standard library constants were unstable, but the values themselves
could easily be computed for the test. Once the minimum rustc
supported becomes 1.43.0, the tests should be changed to use the
constants instead of the computation.
2020-04-08 13:23:04 +02:00
Trevor Spiteri b035ae9dbe typo 2020-04-08 12:51:11 +02:00
Trevor Spiteri 8803e0786d docs: link to F::is_{finite,nan} in impl {To,From}Fixed for F
Before this commit, all links were to the f64 documentation, even for
implementations for f32, f16 and bf16.
2020-03-20 01:59:51 +01:00
Trevor Spiteri f86e59a204 document individual conversion traits 2020-03-05 15:30:08 +01:00
Trevor Spiteri aeac17c0d8 fix failing cmp_parse test
While with the actual string

    f ≤ string < f+Δ

we are using a parsed version, which could be actually larger than
string so that the test should only check

    f ≤ parsed ≤ f+Δ
2020-02-24 14:29:34 +01:00
Trevor Spiteri c6d8e14537 test that constants are truncated version of known correct strings 2020-02-24 14:16:23 +01:00
Trevor Spiteri 327bc05413 specify that <Err = PraseFixedError> in Fixed: FromStr constraint 2020-02-24 14:13:30 +01:00
Trevor Spiteri 524fc0c28f version 0.5.4 2020-02-21 16:34:27 +01:00
Trevor Spiteri 97fdf52ac6 silence clippy 2020-02-21 15:57:56 +01:00
Trevor Spiteri e0f3eb77b8 fix incorrect overflow handling for rem_euclid_int 2020-02-21 15:39:02 +01:00
Trevor Spiteri e8f5a8238e tweak Fixed doc 2020-02-13 15:57:12 +01:00
Trevor Spiteri 5ed4979048 version 0.5.3 2020-02-13 13:48:03 +01:00
Trevor Spiteri 4b889cbb1f reorganize {,checked} {,Euclidean} remainders {,by integers}
Now the main logic is in the checked functions, which fail only if rhs
is zero, and the other functions all .expect("division by zero").

checked_rem now uses % instead of core checked_rem.

checked_rem_euclid now uses core rem_euclid.

checked_rem_int uses checked_rem for the most common case.

checked_rem_euclid_int uses checked_rem_euclid for the most common
case.
2020-02-13 12:04:49 +01:00
Trevor Spiteri 68f72f8b56 some fixes and tests
* rem_euclid no longer uses rhs.abs() which could overflow.

  * Rem<Inner> and rem_euclid_int now allow for the signed case where
    rhs is equal to the absolute value of the minimum fixed value.

  * checked_rem_int, checked_rem_euclid and checked_rem_euclid_int now
    check for zero then defer to Rem<Inner>, rem_euclid and
    rem_euclid_int.
2020-02-13 01:39:02 +01:00
Trevor Spiteri be49c12e93 typo 2020-02-12 23:58:44 +01:00
Trevor Spiteri 137d8989e6 mention fixed-sqrt in top-level doc 2020-02-12 23:56:26 +01:00
Trevor Spiteri e3e17341f2 add {div,rem}_euclid_int to Wrapping 2020-02-12 23:51:31 +01:00
Trevor Spiteri 873bdfa128 fix bug in round_to_zero 2020-02-12 23:45:58 +01:00
Trevor Spiteri ddf69cdca0 some doc tweaks 2020-02-12 23:18:24 +01:00
Trevor Spiteri 3ee5811556 fix remaining checked {div,rem}_euclid_int methods
Closes https://gitlab.com/tspiteri/fixed/issues/13
2020-02-12 18:40:04 +01:00
Trevor Spiteri 97128d2b9f fix checked_rem_int and fix+deprecate {wrapping,overflowing}_rem_int
https://gitlab.com/tspiteri/fixed/issues/13
2020-02-12 17:32:34 +01:00
Trevor Spiteri 677ee97f6f add more arithmetic tests 2020-02-12 16:59:10 +01:00
Trevor Spiteri f8d2004c8f fix Rem<Inner> for Fixed
https://gitlab.com/tspiteri/fixed/issues/13
2020-02-12 16:58:21 +01:00
Trevor Spiteri f070f5e75a more of remove Frac constraints for trait impls that do not need it 2020-02-12 16:44:26 +01:00
Trevor Spiteri f6f4b9d174 add {div,rem}_euclid to Wrapping 2020-02-12 15:07:15 +01:00
Trevor Spiteri bf7c2024e1 add {saturating,wrapping,overflowing}_div_euclid 2020-02-12 14:48:10 +01:00
Trevor Spiteri 43926daa62 add checked_{div,rem}_euclid 2020-02-12 14:16:19 +01:00
Trevor Spiteri 96e922d287 remove Frac constraints for trait impls that do not need it 2020-02-12 13:57:20 +01:00
Trevor Spiteri 6e93affa0d add div_euclid and rem_euclid 2020-02-12 13:48:35 +01:00
Trevor Spiteri c2fa7448c2 implement Rem and RemAssign, and add checked_rem
Closes https://gitlab.com/tspiteri/fixed/issues/12
2020-02-12 13:15:23 +01:00
Trevor Spiteri 2f2b05e33f version 0.5.2 2020-02-02 21:02:14 +01:00
Shane Pearman b0e3828e79 re-use inner serde impls for Wrapping types 2020-02-01 03:01:11 -08:00
Shane Pearman 7aa5b0844f add serde impls for Wrapping types 2020-02-01 01:26:35 -08:00
Trevor Spiteri ab0aa534c7 version 0.5.1 2019-12-23 18:15:31 +01:00
Trevor Spiteri 823916346f add std feature 2019-12-23 17:39:41 +01:00
Trevor Spiteri 59bc0bfd26 link to core libs instead of std libs where possible 2019-12-23 17:22:21 +01:00
Trevor Spiteri be35c826da simplify overflow checks for multiplication and division 2019-12-07 22:40:09 +01:00
Trevor Spiteri 950f9051f7 version 0.5.0 2019-12-06 11:46:41 +01:00
Trevor Spiteri ae0b037bc5 fmt 2019-11-24 21:17:19 +01:00
Trevor Spiteri 68b2190a86 add conversions to/from {be,le,ne}_bytes 2019-11-24 20:13:26 +01:00
Trevor Spiteri aac0353bb1 cleaner is_power_of_two 2019-11-24 18:53:45 +01:00
Trevor Spiteri e46bf604f3 remove deprecated methods and modules 2019-11-24 18:53:07 +01:00
Trevor Spiteri 25510f1525 use std abs, wrapping_abs, overflowing_abs 2019-11-24 18:52:57 +01:00
Trevor Spiteri 221e7d22eb use std euclid operations 2019-11-24 18:47:39 +01:00
Trevor Spiteri 7b74e7333b require rustc 1.39.0 2019-11-24 18:47:06 +01:00
Trevor Spiteri 27380f19ca add Euclidean division/remainder by an integer to Fixed trait 2019-10-17 15:28:41 +02:00
Trevor Spiteri 9880f75c42 add Euclidean division/remainder by an integer 2019-10-17 15:00:37 +02:00
Trevor Spiteri 4ef5f192ed version 0.4.6 2019-10-16 12:08:30 +02:00
Trevor Spiteri a674c77051 add bf16 support 2019-10-16 11:32:53 +02:00
Trevor Spiteri 5e7473b7f5 make saturating ops const fn 2019-10-11 14:59:38 +02:00
Trevor Spiteri 0207311b6c fmt 2019-10-10 23:31:05 +02:00
Trevor Spiteri f3dc9cdb04 implement az casts from bool to fixed-point 2019-10-10 19:57:44 +02:00
Trevor Spiteri a99655c809 implement az casts with both source and destination as fixed-point 2019-10-10 19:28:42 +02:00
Trevor Spiteri b6c1974401 clippy 2019-10-10 17:19:10 +02:00
Trevor Spiteri cfe198f087 document and test az option 2019-10-10 17:13:36 +02:00
Trevor Spiteri d6c634c915 make az support optional 2019-10-10 17:13:27 +02:00
Trevor Spiteri 019c1eeb23 add az support 2019-10-10 16:47:10 +02:00
Trevor Spiteri 3248e354ba version 0.4.5 2019-08-30 22:32:17 +02:00
Trevor Spiteri 687a5521a7 Wrapping nits 2019-08-30 21:55:26 +02:00
Trevor Spiteri e5afe1d6a4 add more tests in {display,from_str}.rs 2019-08-30 21:30:40 +02:00
Trevor Spiteri 1960c702c6 remove unnecessary helper methods 2019-08-30 21:28:19 +02:00
Trevor Spiteri 55a58bf795 typos 2019-08-30 13:01:42 +02:00
Trevor Spiteri a4c3fdeeed add methods to Wrapping 2019-08-30 12:48:31 +02:00
Trevor Spiteri e31802dd23 some more display/from_str tests 2019-08-29 22:30:56 +02:00
Trevor Spiteri 24f197b930 remove unnecessary macros 2019-08-29 17:24:36 +02:00
Trevor Spiteri 75df9749ff add compare_frac17_float test 2019-08-29 14:20:56 +02:00
Trevor Spiteri 1a81cef6eb improve test for previous commit 2019-08-29 12:38:22 +02:00
Trevor Spiteri f314735cc9 bug fix: decimal display panics or includes leading zero 2019-08-29 11:50:18 +02:00
Trevor Spiteri de6ecb5782 add Wrapping::round_ties_to_even 2019-08-29 10:12:17 +02:00
Trevor Spiteri 0711850c26 doc nits 2019-08-26 11:10:07 +02:00
Trevor Spiteri 980804b1c7 do not use cfg_attr for clippy allows 2019-08-24 16:35:03 +02:00
Trevor Spiteri ee98c16b28 simplify ceil_log10_2_times 2019-08-24 16:32:28 +02:00
Trevor Spiteri 06af80c9ed nits 2019-08-24 14:52:32 +02:00
Trevor Spiteri 50ca556686 version 0.4.4 2019-08-24 13:15:28 +02:00
Trevor Spiteri 82c7781f0e update README and doc main page 2019-08-24 13:10:49 +02:00
Trevor Spiteri 97e57bad0e fix unused warning 2019-08-23 14:16:36 +02:00
Trevor Spiteri c6e0563257 clippy + fmt 2019-08-23 14:06:28 +02:00
Trevor Spiteri 72f619b757 do not use f16::from_{f32,f64} from half crate 2019-08-23 14:03:39 +02:00
Trevor Spiteri 348463d204 state aims at top of documentation 2019-08-23 10:03:59 +02:00
Trevor Spiteri e24a0963f6 add Frac type to Fixed trait 2019-08-22 19:30:52 +02:00
Trevor Spiteri 3292a2da26 some minor doc improvements 2019-08-22 14:26:08 +02:00
Trevor Spiteri 87d30cd8b1 reorder some methods 2019-08-22 14:03:32 +02:00
Trevor Spiteri 9e333d99c2 add round_to_zero 2019-08-22 13:39:51 +02:00
Trevor Spiteri 7d08654e0a cleaner rounding examples 2019-08-22 13:04:39 +02:00
Trevor Spiteri 0eade78071 add round_ties_to_even and checked variants 2019-08-22 13:01:28 +02:00
Trevor Spiteri b3796a46f0 make is_power_of_two a const fn 2019-08-21 22:15:36 +02:00
Trevor Spiteri 696361a8fa macro formatting 2019-08-21 16:57:52 +02:00
Trevor Spiteri 381af22e96 make {,wrapping_,overflowing_}abs const 2019-08-21 15:46:24 +02:00
Trevor Spiteri 895d59611d fix and expand rounding test 2019-08-21 15:45:55 +02:00
Trevor Spiteri ba594f24e1 document bug fix in release notes 2019-08-21 13:30:49 +02:00
Trevor Spiteri 08fc9881e5 make display code clearer 2019-08-21 13:02:43 +02:00
Trevor Spiteri 8176a36a95 version 0.4.3 2019-08-20 19:40:53 +02:00
Trevor Spiteri f423fe0159 impl {Shl,Shr}{,Assign}<all primitives> for Wrapping 2019-08-20 17:07:13 +02:00
Trevor Spiteri fa271a4a9d doc updates 2019-08-20 16:42:37 +02:00
Trevor Spiteri 46049bb7ac tweak consts example 2019-08-20 15:31:39 +02:00
Trevor Spiteri 0b4dac8d33 reorganize modules 2019-08-20 15:30:23 +02:00
Trevor Spiteri 96107159f5 some cleanups in tests inside display.rs 2019-08-20 01:18:22 +02:00
Trevor Spiteri daa600bb71 properly handle precision in Display 2019-08-19 23:53:43 +02:00
Trevor Spiteri 2d5a5c3ada properly handle precision in Binary, Octal, LowerHex, UpperHex 2019-08-19 18:49:40 +02:00
Trevor Spiteri 76a0abe468 relax some trait bounds in Wrapping
* Now bitwise and shifting operations do not require F: Fixed, only
    F: Op. For example

        impl BitAnd<Wrapping<F>> for Wrapping<F>

    is now bound by

        where F: BitAnd<F, Output = F>

    instead of

        where F: Fixed

  * Also multiplication and division by integers do not require Frac
    bounds. For example

        impl Mul<i8> for Wrapping<FixedI8<Frac>>

    now has no bounds on Frac, instead of being bound by

        where Frac: LeEqU8
2019-08-19 14:15:06 +02:00
Trevor Spiteri a501829cc6 change rhs type of Wrapping shift operators from usize to u32 2019-08-19 13:18:54 +02:00
Trevor Spiteri 960a782799 consolidate the trait impls for Wrapping 2019-08-19 02:02:06 +02:00