Merge branch 'edition_2018' into 'master'

Move to edition 2018

See merge request tspiteri/fixed!1
This commit is contained in:
Trevor Spiteri 2019-08-02 23:15:29 +00:00
commit 62457d201d
18 changed files with 135 additions and 103 deletions

View File

@ -22,7 +22,7 @@ install:
- curl -sSf -o rustup-init.exe https://win.rustup.rs
- rustup-init.exe -y --default-host %TARGET% --default-toolchain none --no-modify-path
- rustup --version
- rustup install beta-%TARGET% 1.28.0-%TARGET%
- rustup install beta-%TARGET% 1.31.1-%TARGET%
- rustup component add --toolchain beta-%TARGET% rustfmt clippy
build: false
@ -37,7 +37,7 @@ test_script:
- cargo +beta-%TARGET% check --all-targets --features fail-on-warnings
- cargo +beta-%TARGET% test --release --features "fail-on-warnings f16 serde"
- cargo +beta-%TARGET% fmt -- --check
- cargo +1.28.0-%TARGET% test --features "fail-on-warnings f16 serde"
- cargo +1.31.1-%TARGET% test --features "fail-on-warnings f16 serde"
after_test:
- C:\msys64\usr\bin\bash -c "if [ -d ""$USERPROFILE/.cargo/registry/cache"" ]; then cd ""$USERPROFILE/.cargo/registry""; /c/msys64/usr/bin/find cache -name \*.crate; fi"

View File

@ -8,7 +8,7 @@
before_script:
- getconf LONG_BIT
- rustup --version
- rustup install beta-$TARGET 1.28.0-$TARGET
- rustup install beta-$TARGET 1.31.1-$TARGET
- rustup component add --toolchain beta-$TARGET rustfmt clippy
- if [ -d cargo/registry/cache ]; then rm -rf $CARGO_HOME/registry/cache; mkdir -p $CARGO_HOME/registry; cp -R cargo/registry/cache $CARGO_HOME/registry/; echo Copied registry/cache; fi
- if [ -d $CARGO_HOME/registry/cache ]; then (cd $CARGO_HOME/registry; find cache -name \*.crate) fi
@ -35,8 +35,8 @@ x86_64-gnulinux:
- cargo +beta-$TARGET test --features "fail-on-warnings f16 serde"
- cargo +beta-$TARGET test --release --features "fail-on-warnings f16 serde"
- cargo +beta-$TARGET fmt -- --check
- cargo +1.28.0-$TARGET test --features "fail-on-warnings f16 serde"
- cargo +1.28.0-$TARGET test --release --features "fail-on-warnings f16 serde"
- cargo +1.31.1-$TARGET test --features "fail-on-warnings f16 serde"
- cargo +1.31.1-$TARGET test --release --features "fail-on-warnings f16 serde"
i686-gnulinux:
image: i386/rust:1
@ -54,5 +54,5 @@ i686-gnulinux:
- cargo +beta-$TARGET test --features "fail-on-warnings f16 serde"
- cargo +beta-$TARGET test --release --features "fail-on-warnings f16 serde"
- cargo +beta-$TARGET fmt -- --check
- cargo +1.28.0-$TARGET test --features "fail-on-warnings f16 serde"
- cargo +1.28.0-$TARGET test --release --features "fail-on-warnings f16 serde"
- cargo +1.31.1-$TARGET test --features "fail-on-warnings f16 serde"
- cargo +1.31.1-$TARGET test --release --features "fail-on-warnings f16 serde"

View File

@ -16,6 +16,7 @@ readme = "README.md"
keywords = ["mathematics", "numerics"]
categories = ["algorithms", "data-structures", "no-std", "science"]
license = "MIT/Apache-2.0"
edition = "2018"
[features]
f16 = ["half"]

View File

@ -200,7 +200,7 @@ adding this to your crate root (usually *lib.rs* or *main.rs*):
extern crate fixed;
```
The *fixed* crate requires rustc version 1.28.0 or later.
The *fixed* crate requires rustc version 1.31.1 or later.
## Optional features

View File

@ -13,18 +13,23 @@
// <https://www.apache.org/licenses/LICENSE-2.0> and
// <https://opensource.org/licenses/MIT>.
use core::cmp::Ordering;
use core::iter::{Product, Sum};
use core::ops::{
Add, AddAssign, BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign, Div, DivAssign,
Mul, MulAssign, Neg, Not, Rem, RemAssign, Shl, ShlAssign, Shr, ShrAssign, Sub, SubAssign,
};
use frac::{IsLessOrEqual, True, Unsigned, U128, U16, U32, U64, U8};
use sealed::{SealedFixed, SealedInt};
use wide_div::WideDivRem;
use {
FixedI128, FixedI16, FixedI32, FixedI64, FixedI8, FixedU128, FixedU16, FixedU32, FixedU64,
FixedU8,
crate::{
frac::{IsLessOrEqual, True, Unsigned, U128, U16, U32, U64, U8},
sealed::{SealedFixed, SealedInt},
wide_div::WideDivRem,
FixedI128, FixedI16, FixedI32, FixedI64, FixedI8, FixedU128, FixedU16, FixedU32, FixedU64,
FixedU8,
},
core::{
cmp::Ordering,
iter::{Product, Sum},
ops::{
Add, AddAssign, BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign, Div,
DivAssign, Mul, MulAssign, Neg, Not, Rem, RemAssign, Shl, ShlAssign, Shr, ShrAssign,
Sub, SubAssign,
},
},
};
macro_rules! refs {
@ -846,11 +851,11 @@ mul_div_fallback! { i128, u128, Signed }
#[cfg(test)]
mod tests {
use *;
use crate::*;
#[test]
fn fixed_u16() {
use frac::U7 as Frac;
use crate::frac::U7 as Frac;
let frac = Frac::U32;
let a = 12;
let b = 4;
@ -870,7 +875,7 @@ mod tests {
#[test]
fn fixed_i16() {
use frac::U7 as Frac;
use crate::frac::U7 as Frac;
let frac = Frac::U32;
let a = 12;
let b = 4;
@ -894,7 +899,7 @@ mod tests {
#[test]
fn fixed_u128() {
use frac::U7 as Frac;
use crate::frac::U7 as Frac;
let frac = Frac::U32;
let a = 0x0003_4567_89ab_cdef_0123_4567_89ab_cdef_u128;
let b = 5;
@ -916,7 +921,7 @@ mod tests {
#[test]
fn fixed_i128() {
use frac::U7 as Frac;
use crate::frac::U7 as Frac;
let frac = Frac::U32;
let a = 0x0003_4567_89ab_cdef_0123_4567_89ab_cdef_i128;
let b = 5;

View File

@ -13,14 +13,16 @@
// <https://www.apache.org/licenses/LICENSE-2.0> and
// <https://opensource.org/licenses/MIT>.
use core::cmp::Ordering;
use frac::{IsLessOrEqual, True, Unsigned, U128, U16, U32, U64, U8};
#[cfg(feature = "f16")]
use half::f16;
use sealed::{SealedFixed, SealedFloat, SealedInt, Widest};
use {
FixedI128, FixedI16, FixedI32, FixedI64, FixedI8, FixedU128, FixedU16, FixedU32, FixedU64,
FixedU8,
crate::{
frac::{IsLessOrEqual, True, Unsigned, U128, U16, U32, U64, U8},
sealed::{SealedFixed, SealedFloat, SealedInt, Widest},
FixedI128, FixedI16, FixedI32, FixedI64, FixedI8, FixedU128, FixedU16, FixedU32, FixedU64,
FixedU8,
},
core::cmp::Ordering,
};
macro_rules! fixed_cmp_fixed {
@ -437,7 +439,7 @@ fixed_cmp! { FixedI128(i128, U128, 128) }
#[cfg_attr(feature = "cargo-clippy", allow(clippy::float_cmp))]
#[cfg_attr(feature = "cargo-clippy", allow(clippy::cognitive_complexity))]
mod tests {
use *;
use crate::*;
#[test]
fn cmp_signed() {

View File

@ -13,15 +13,19 @@
// <https://www.apache.org/licenses/LICENSE-2.0> and
// <https://opensource.org/licenses/MIT>.
use core::ops::{Add, Sub};
use frac::{IsGreaterOrEqual, IsLessOrEqual, True, Unsigned, U0, U1, U128, U16, U2, U32, U64, U8};
#[cfg(feature = "f16")]
use half::f16;
use sealed::SealedInt;
use traits::{FromFixed, LossyFrom};
use {
FixedI128, FixedI16, FixedI32, FixedI64, FixedI8, FixedU128, FixedU16, FixedU32, FixedU64,
FixedU8,
crate::{
frac::{
IsGreaterOrEqual, IsLessOrEqual, True, Unsigned, U0, U1, U128, U16, U2, U32, U64, U8,
},
sealed::SealedInt,
traits::{FromFixed, LossyFrom},
FixedI128, FixedI16, FixedI32, FixedI64, FixedI8, FixedU128, FixedU16, FixedU32, FixedU64,
FixedU8,
},
core::ops::{Add, Sub},
};
macro_rules! convert {
@ -627,7 +631,7 @@ impl LossyFrom<f64> for f64 {
#[cfg_attr(feature = "cargo-clippy", allow(clippy::float_cmp))]
#[cfg(test)]
mod tests {
use *;
use crate::*;
#[test]
fn expanding_from_unsigned() {

View File

@ -13,16 +13,18 @@
// <https://www.apache.org/licenses/LICENSE-2.0> and
// <https://opensource.org/licenses/MIT>.
use core::cmp::Ordering;
use core::fmt::{
Binary, Debug, Display, Formatter, LowerHex, Octal, Result as FmtResult, UpperHex,
};
use core::str;
use frac::{IsLessOrEqual, True, Unsigned, U128, U16, U32, U64, U8};
use sealed::{SealedFixed, SealedInt};
use {
FixedI128, FixedI16, FixedI32, FixedI64, FixedI8, FixedU128, FixedU16, FixedU32, FixedU64,
FixedU8,
crate::{
frac::{IsLessOrEqual, True, Unsigned, U128, U16, U32, U64, U8},
sealed::{SealedFixed, SealedInt},
FixedI128, FixedI16, FixedI32, FixedI64, FixedI8, FixedU128, FixedU16, FixedU32, FixedU64,
FixedU8,
},
core::{
cmp::Ordering,
fmt::{Binary, Debug, Display, Formatter, LowerHex, Octal, Result as FmtResult, UpperHex},
str,
},
};
trait Radix2 {
@ -375,9 +377,9 @@ where
#[cfg(test)]
mod tests {
use crate::*;
use core::fmt::{Debug, Error as FmtError, Formatter, Result as FmtResult, Write};
use core::mem;
use *;
struct Buf([u8; 256]);
impl Buf {
@ -441,7 +443,7 @@ mod tests {
#[test]
fn hex() {
use frac::U7 as Frac;
use crate::frac::U7 as Frac;
let frac = Frac::U32;
for i in 0..(1 << frac) {
let p = 0x1234_5678_9abc_def0u64 ^ i as u64;
@ -458,7 +460,7 @@ mod tests {
#[test]
fn dec() {
use frac::U7 as Frac;
use crate::frac::U7 as Frac;
let frac = Frac::U32;
for i in 0..(1 << frac) {
let bits = !0u32 ^ i;

View File

@ -189,12 +189,6 @@ additional terms or conditions.
#![doc(test(attr(deny(warnings))))]
#![cfg_attr(feature = "fail-on-warnings", deny(warnings))]
#[cfg(feature = "f16")]
extern crate half;
#[cfg(feature = "serde")]
extern crate serde;
extern crate typenum;
#[macro_use]
mod macros;
@ -214,15 +208,21 @@ pub mod types;
mod wide_div;
mod wrapping;
use arith::MulDivDir;
use core::cmp::Ordering;
use core::hash::{Hash, Hasher};
use core::marker::PhantomData;
use frac::{IsLessOrEqual, True, Unsigned, U128, U16, U32, U64, U8};
pub use crate::wrapping::Wrapping;
#[cfg(feature = "f16")]
use half::f16;
use sealed::{Fixed, Float, Int, SealedFixed, SealedFloat, SealedInt, Widest};
pub use wrapping::Wrapping;
use {
crate::{
arith::MulDivDir,
frac::{IsLessOrEqual, True, Unsigned, U128, U16, U32, U64, U8},
sealed::{Fixed, Float, Int, SealedFixed, SealedFloat, SealedInt, Widest},
},
core::{
cmp::Ordering,
hash::{Hash, Hasher},
marker::PhantomData,
},
};
#[macro_use]
mod macros_from_to;
@ -694,12 +694,12 @@ fixed! { "A 128-bit fixed-point signed integer", FixedI128(i128, U128, "128"), S
#[cfg(test)]
mod tests {
use *;
use crate::*;
#[cfg_attr(feature = "cargo-clippy", allow(clippy::cognitive_complexity))]
#[test]
fn rounding() {
use frac::{U16, U32};
use crate::frac::{U16, U32};
type I0F32 = FixedI32<U32>;

View File

@ -17,17 +17,19 @@
This module contains sealed traits.
*/
use frac::{IsLessOrEqual, True, Unsigned, U128, U16, U32, U64, U8};
#[cfg(feature = "f16")]
use half::f16;
pub(crate) use sealed_fixed::{SealedFixed, Widest};
pub(crate) use sealed_float::SealedFloat;
pub(crate) use sealed_int::SealedInt;
use traits::{FromFixed, ToFixed};
use {
use crate::{
frac::{IsLessOrEqual, True, Unsigned, U128, U16, U32, U64, U8},
traits::{FromFixed, ToFixed},
FixedI128, FixedI16, FixedI32, FixedI64, FixedI8, FixedU128, FixedU16, FixedU32, FixedU64,
FixedU8,
};
pub(crate) use crate::{
sealed_fixed::{SealedFixed, Widest},
sealed_float::SealedFloat,
sealed_int::SealedInt,
};
#[cfg(feature = "f16")]
use half::f16;
/// This trait is implemented for all the primitive integer types.
///

View File

@ -13,13 +13,17 @@
// <https://www.apache.org/licenses/LICENSE-2.0> and
// <https://opensource.org/licenses/MIT>.
use core::fmt::{Debug, Display};
use core::hash::Hash;
use frac::{IsLessOrEqual, True, Unsigned, U128, U16, U32, U64, U8};
use sealed::{Fixed, Float, SealedInt};
use {
FixedI128, FixedI16, FixedI32, FixedI64, FixedI8, FixedU128, FixedU16, FixedU32, FixedU64,
FixedU8,
crate::{
frac::{IsLessOrEqual, True, Unsigned, U128, U16, U32, U64, U8},
sealed::{Fixed, Float, SealedInt},
FixedI128, FixedI16, FixedI32, FixedI64, FixedI8, FixedU128, FixedU16, FixedU32, FixedU64,
FixedU8,
},
core::{
fmt::{Debug, Display},
hash::Hash,
},
};
// Unsigned can have 0 ≤ x < 2↑128, that is its msb can be 0 or 1.

View File

@ -13,11 +13,15 @@
// <https://www.apache.org/licenses/LICENSE-2.0> and
// <https://opensource.org/licenses/MIT>.
use core::cmp::Ordering;
use core::fmt::{Debug, Display};
#[cfg(feature = "f16")]
use half::f16;
use sealed::{Fixed, SealedInt, Widest};
use {
crate::sealed::{Fixed, SealedInt, Widest},
core::{
cmp::Ordering,
fmt::{Debug, Display},
},
};
pub trait SealedFloat: Copy + Debug + Display {
type Bits: SealedInt;

View File

@ -13,13 +13,17 @@
// <https://www.apache.org/licenses/LICENSE-2.0> and
// <https://opensource.org/licenses/MIT>.
use core::cmp::Ordering;
use core::fmt::{Debug, Display};
use frac::{Bit, False, True, Unsigned, U0, U128, U16, U32, U64, U8};
use sealed::{Fixed, SealedFixed, Widest};
use {
FixedI128, FixedI16, FixedI32, FixedI64, FixedI8, FixedU128, FixedU16, FixedU32, FixedU64,
FixedU8,
crate::{
frac::{Bit, False, True, Unsigned, U0, U128, U16, U32, U64, U8},
sealed::{Fixed, SealedFixed, Widest},
FixedI128, FixedI16, FixedI32, FixedI64, FixedI8, FixedU128, FixedU16, FixedU32, FixedU64,
FixedU8,
},
core::{
cmp::Ordering,
fmt::{Debug, Display},
},
};
pub trait SealedInt: Copy + Ord + Debug + Display {

View File

@ -13,13 +13,17 @@
// <https://www.apache.org/licenses/LICENSE-2.0> and
// <https://opensource.org/licenses/MIT>.
use core::fmt::{Formatter, Result as FmtResult};
use frac::{IsLessOrEqual, True, Unsigned, U128, U16, U32, U64, U8};
use serde::de::{self, Deserialize, Deserializer, MapAccess, SeqAccess, Visitor};
use serde::ser::{Serialize, SerializeStruct, Serializer};
use {
FixedI128, FixedI16, FixedI32, FixedI64, FixedI8, FixedU128, FixedU16, FixedU32, FixedU64,
FixedU8,
crate::{
frac::{IsLessOrEqual, True, Unsigned, U128, U16, U32, U64, U8},
FixedI128, FixedI16, FixedI32, FixedI64, FixedI8, FixedU128, FixedU16, FixedU32, FixedU64,
FixedU8,
},
core::fmt::{Formatter, Result as FmtResult},
serde::{
de::{self, Deserialize, Deserializer, MapAccess, SeqAccess, Visitor},
ser::{Serialize, SerializeStruct, Serializer},
},
};
macro_rules! serde_fixed {

View File

@ -17,7 +17,7 @@
This module contains traits.
*/
use sealed::Fixed;
use crate::sealed::Fixed;
/// This trait provides infallible conversions that might be lossy.
///

View File

@ -18,8 +18,8 @@ This module provides type aliases for all supported fixed-point
numbers.
*/
use frac;
use {
use crate::frac;
use crate::{
FixedI128, FixedI16, FixedI32, FixedI64, FixedI8, FixedU128, FixedU16, FixedU32, FixedU64,
FixedU8,
};

View File

@ -13,7 +13,7 @@
// <https://www.apache.org/licenses/LICENSE-2.0> and
// <https://opensource.org/licenses/MIT>.
use sealed::SealedInt;
use crate::sealed::SealedInt;
trait DivHalf: Copy {
fn hi(self) -> Self;

View File

@ -13,6 +13,12 @@
// <https://www.apache.org/licenses/LICENSE-2.0> and
// <https://opensource.org/licenses/MIT>.
use crate::frac::{IsLessOrEqual, True, Unsigned, U128, U16, U32, U64, U8};
use crate::sealed::{Fixed, SealedFixed};
use crate::{
FixedI128, FixedI16, FixedI32, FixedI64, FixedI8, FixedU128, FixedU16, FixedU32, FixedU64,
FixedU8,
};
use core::cmp::Ordering;
use core::default::Default;
use core::fmt::{Debug, Display, Formatter, Result as FmtResult};
@ -23,12 +29,6 @@ use core::ops::{
Add, AddAssign, BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign, Div, DivAssign,
Mul, MulAssign, Neg, Not, Rem, RemAssign, Shl, ShlAssign, Shr, ShrAssign, Sub, SubAssign,
};
use frac::{IsLessOrEqual, True, Unsigned, U128, U16, U32, U64, U8};
use sealed::{Fixed, SealedFixed};
use {
FixedI128, FixedI16, FixedI32, FixedI64, FixedI8, FixedU128, FixedU16, FixedU32, FixedU64,
FixedU8,
};
/// Provides intentionally wrapped arithmetic on fixed-point numbers.
///