Skip to content

Commit

Permalink
Add stable i128_type support.
Browse files Browse the repository at this point in the history
Requires Rust >= 1.26.0.
  • Loading branch information
Rouven Spreckels committed May 10, 2018
1 parent 6a5bab2 commit 72794d8
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 52 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ language: rust
env: FEATURES=""
matrix:
include:
- rust: 1.17.0
- rust: 1.26.0
- rust: stable
- rust: beta
- rust: nightly
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "signifix"
version = "0.8.0"
version = "0.9.0"
authors = [
"Rouven Spreckels <n3vu0r@qu1x.org>",
]
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
[Documentation]: https://docs.rs/signifix/badge.svg
[License]: https://img.shields.io/crates/l/signifix.svg

**Works now on stable Rust**
**Works now on stable Rust (>= 1.26.0)**

Formats a given number in one of the three Signifix notations
[as defined below](#signifix-notations) by determining
Expand Down Expand Up @@ -92,19 +92,19 @@ used by adding `signifix` to the dependencies in your project's

```toml
[dependencies]
signifix = "0.8"
signifix = "0.9"

# Optionally enable `try_from` and `i128_type` support on nightly Rust.
# Optionally enable `try_from` support on nightly Rust.
#[dependencies.signifix]
#features = ["nightly"]
```

and this to your crate root:

```rust
// Optionally enable `try_from` and `i128_type` support on nightly Rust.
// Optionally enable `try_from` support on nightly Rust.
// Required if the `nightly` feature is enabled in your `Cargo.toml`.
//#![feature(try_from, i128_type)]
//#![feature(try_from)]

extern crate signifix;
```
Expand Down
4 changes: 4 additions & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Version 0.9.0 (2018-05-10)

* Added stable `i128_type` support requiring Rust `>= 1.26.0`.

# Version 0.8.0 (2017-11-26)

* Works now on stable Rust by reimplementing the `try_from` feature.
Expand Down
25 changes: 1 addition & 24 deletions src/binary.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2016, 2017 Rouven Spreckels <n3vu0r@qu1x.org>
// Copyright (c) 2016, 2017, 2018 Rouven Spreckels <n3vu0r@qu1x.org>
//
// Usage of the works is permitted provided that
// this instrument is retained with the works, so that
Expand Down Expand Up @@ -102,7 +102,6 @@ pub const SYMBOLS: [Option<&str>; 9] = [
Some("Pi"), Some("Ei"), Some("Zi"), Some("Yi"),
];

#[cfg(feature = "nightly")]
/// Binary prefix factors from `1 024 ^ 1` to `1 024 ^ 8` indexed from `1` to
/// `8`, or `1 024 ^ 0` indexed at `0`.
pub const FACTORS: [f64; 9] = [
Expand All @@ -113,21 +112,6 @@ pub const FACTORS: [f64; 9] = [
(1u128 << 70) as f64, (1u128 << 80) as f64,
];

#[cfg(not(feature = "nightly"))]
/// Binary prefix factors from `1 024 ^ 1` to `1 024 ^ 8` indexed from `1` to
/// `8`, or `1 024 ^ 0` indexed at `0`.
pub const FACTORS: [f64; 9] = [
1f64,
1024f64,
1048576f64,
1073741824f64,
1099511627776f64,
1125899906842624f64,
1152921504606847000f64,
1180591620717411300000f64,
1208925819614629200000000f64,
];

impl Signifix {
/// Signed significand normalized from `±1.000` over `±999.9` to `±1 023`.
pub fn significand(&self) -> f64 {
Expand Down Expand Up @@ -215,16 +199,9 @@ impl Display for Signifix {
}
}

#[cfg(feature = "nightly")]
try_from! { i8, i16, i32, i64, i128, isize }
#[cfg(feature = "nightly")]
try_from! { u8, u16, u32, u64, u128, usize }

#[cfg(not(feature = "nightly"))]
try_from! { i8, i16, i32, i64, isize }
#[cfg(not(feature = "nightly"))]
try_from! { u8, u16, u32, u64, usize }

try_from! { f32 }

impl TryFrom<f64> for Signifix {
Expand Down
26 changes: 13 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2016, 2017 Rouven Spreckels <n3vu0r@qu1x.org>
// Copyright (c) 2016, 2017, 2018 Rouven Spreckels <n3vu0r@qu1x.org>
//
// Usage of the works is permitted provided that
// this instrument is retained with the works, so that
Expand Down Expand Up @@ -82,19 +82,19 @@
//!
//! ```toml
//! [dependencies]
//! signifix = "0.8"
//! signifix = "0.9"
//!
//! # Optionally enable `try_from` and `i128_type` support on nightly Rust.
//! # Optionally enable `try_from` support on nightly Rust.
//! #[dependencies.signifix]
//! #features = ["nightly"]
//! ```
//!
//! and this to your crate root:
//!
//! ```
//! // Optionally enable `try_from` and `i128_type` support on nightly Rust.
//! // Optionally enable `try_from` support on nightly Rust.
//! // Required if the `nightly` feature is enabled in your `Cargo.toml`.
//! //#![feature(try_from, i128_type)]
//! //#![feature(try_from)]
//!
//! extern crate signifix;
//! ```
Expand All @@ -107,7 +107,7 @@
//! jumps to the left or right while making maximum use of their occupied space:
//!
//! ```
//! # #![cfg_attr(feature = "nightly", feature(try_from, i128_type))]
//! # #![cfg_attr(feature = "nightly", feature(try_from))]
//! use signifix::TryFrom; // Until stabilized.
//!
//! use signifix::{metric, binary, Result};
Expand Down Expand Up @@ -163,7 +163,7 @@
//! This is useful to smoothly refresh a transfer rate within a terminal:
//!
//! ```
//! # #![cfg_attr(feature = "nightly", feature(try_from, i128_type))]
//! # #![cfg_attr(feature = "nightly", feature(try_from))]
//! use signifix::TryFrom; // Until stabilized.
//!
//! use std::f64;
Expand Down Expand Up @@ -214,7 +214,7 @@
//! direction with positive numbers being padded to align with negative ones:
//!
//! ```
//! # #![cfg_attr(feature = "nightly", feature(try_from, i128_type))]
//! # #![cfg_attr(feature = "nightly", feature(try_from))]
//! use signifix::TryFrom; // Until stabilized.
//!
//! use signifix::metric::{Signifix, Result, DEF_MAX_LEN};
Expand All @@ -239,7 +239,7 @@
//! positive numbers:
//!
//! ```
//! # #![cfg_attr(feature = "nightly", feature(try_from, i128_type))]
//! # #![cfg_attr(feature = "nightly", feature(try_from))]
//! use signifix::TryFrom; // Until stabilized.
//!
//! use signifix::metric::{Signifix, Error, Result};
Expand All @@ -261,7 +261,7 @@
//! of powers of two, such as memory boundaries due to binary addressing:
//!
//! ```
//! # #![cfg_attr(feature = "nightly", feature(try_from, i128_type))]
//! # #![cfg_attr(feature = "nightly", feature(try_from))]
//! use signifix::TryFrom; // Until stabilized.
//!
//! use signifix::binary::{Signifix, Error, Result};
Expand Down Expand Up @@ -302,7 +302,7 @@
//! `Signifix::fmt()` method:
//!
//! ```
//! # #![cfg_attr(feature = "nightly", feature(try_from, i128_type))]
//! # #![cfg_attr(feature = "nightly", feature(try_from))]
//! use signifix::TryFrom; // Until stabilized.
//!
//! use signifix::binary::{Signifix, Result};
Expand Down Expand Up @@ -347,7 +347,7 @@
//! type via its methods:
//!
//! ```
//! # #![cfg_attr(feature = "nightly", feature(try_from, i128_type))]
//! # #![cfg_attr(feature = "nightly", feature(try_from))]
//! use signifix::TryFrom; // Until stabilized.
//!
//! use signifix::metric::{Signifix, Result};
Expand Down Expand Up @@ -390,7 +390,7 @@

#![deny(missing_docs)]

#![cfg_attr(feature = "nightly", feature(try_from, i128_type))]
#![cfg_attr(feature = "nightly", feature(try_from))]

use std::result;
use std::error;
Expand Down
9 changes: 1 addition & 8 deletions src/metric.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2016, 2017 Rouven Spreckels <n3vu0r@qu1x.org>
// Copyright (c) 2016, 2017, 2018 Rouven Spreckels <n3vu0r@qu1x.org>
//
// Usage of the works is permitted provided that
// this instrument is retained with the works, so that
Expand Down Expand Up @@ -210,16 +210,9 @@ impl Display for Signifix {
}
}

#[cfg(feature = "nightly")]
try_from! { i8, i16, i32, i64, i128, isize }
#[cfg(feature = "nightly")]
try_from! { u8, u16, u32, u64, u128, usize }

#[cfg(not(feature = "nightly"))]
try_from! { i8, i16, i32, i64, isize }
#[cfg(not(feature = "nightly"))]
try_from! { u8, u16, u32, u64, usize }

try_from! { f32 }

impl TryFrom<f64> for Signifix {
Expand Down

0 comments on commit 72794d8

Please sign in to comment.