Struct half::f16 [] [src]

pub struct f16(_);

The 16-bit floating point type.

Methods

impl f16
[src]

[src]

Constructs a 16-bit floating point value from the raw bits.

[src]

Constructs a 16-bit floating point value from a 32-bit floating point value.

If the 32-bit value is to large to fit in 16-bits, +/- infinity will result. NaN values are preserved. 32-bit subnormal values are too tiny to be represented in 16-bits and result in +/- 0. Exponents that underflow the minimum 16-bit exponent will result in 16-bit subnormals or +/- 0. All other values are truncated and rounded to the nearest representable 16-bit value.

[src]

Constructs a 16-bit floating point value from a 64-bit floating point value.

If the 64-bit value is to large to fit in 16-bits, +/- infinity will result. NaN values are preserved. 64-bit subnormal values are too tiny to be represented in 16-bits and result in +/- 0. Exponents that underflow the minimum 16-bit exponent will result in 16-bit subnormals or +/- 0. All other values are truncated and rounded to the nearest representable 16-bit value.

[src]

Converts an f16 into the underlying bit representation.

[src]

Returns true if this value is NaN and false otherwise.

Examples

use half::f16;

let nan = half::consts::NAN;
let f = f16::from_f32(7.0_f32);

assert!(nan.is_nan());
assert!(!f.is_nan());

[src]

Returns true if this value is positive infinity or negative infinity and false otherwise.

Examples

use half::f16;

let f = f16::from_f32(7.0f32);
let inf = half::consts::INFINITY;
let neg_inf = half::consts::NEG_INFINITY;
let nan = half::consts::NAN;

assert!(!f.is_infinite());
assert!(!nan.is_infinite());

assert!(inf.is_infinite());
assert!(neg_inf.is_infinite());

[src]

Returns true if this number is neither infinite nor NaN.

Examples

use half::f16;

let f = f16::from_f32(7.0f32);
let inf = half::consts::INFINITY;
let neg_inf = half::consts::NEG_INFINITY;
let nan = half::consts::NAN;

assert!(f.is_finite());

assert!(!nan.is_finite());
assert!(!inf.is_finite());
assert!(!neg_inf.is_finite());

[src]

Returns true if the number is neither zero, infinite, subnormal, or NaN.

Examples

use half::f16;

let min = half::consts::MIN_POSITIVE;
let max = half::consts::MAX;
let lower_than_min = f16::from_f32(1.0e-10_f32);
let zero = f16::from_f32(0.0_f32);

assert!(min.is_normal());
assert!(max.is_normal());

assert!(!zero.is_normal());
assert!(!half::consts::NAN.is_normal());
assert!(!half::consts::INFINITY.is_normal());
// Values between `0` and `min` are Subnormal.
assert!(!lower_than_min.is_normal());

[src]

Returns the floating point category of the number.

If only one property is going to be tested, it is generally faster to use the specific predicate instead.

Examples

use std::num::FpCategory;
use half::f16;

let num = f16::from_f32(12.4_f32);
let inf = half::consts::INFINITY;

assert_eq!(num.classify(), FpCategory::Normal);
assert_eq!(inf.classify(), FpCategory::Infinite);

[src]

Returns a number that represents the sign of self.

  • 1.0 if the number is positive, +0.0 or INFINITY
  • -1.0 if the number is negative, -0.0 or NEG_INFINITY
  • NAN if the number is NAN

Examples

use half::f16;

let f = f16::from_f32(3.5_f32);

assert_eq!(f.signum(), f16::from_f32(1.0));
assert_eq!(half::consts::NEG_INFINITY.signum(), f16::from_f32(-1.0));

assert!(half::consts::NAN.signum().is_nan());

[src]

Returns true if self's sign bit is positive, including +0.0 and INFINITY.

Examples

use half::f16;

let nan = half::consts::NAN;
let f = f16::from_f32(7.0_f32);
let g = f16::from_f32(-7.0_f32);

assert!(f.is_sign_positive());
assert!(!g.is_sign_positive());
// Requires both tests to determine if is `NaN`
assert!(!nan.is_sign_positive() && !nan.is_sign_negative());

[src]

Returns true if self's sign is negative, including -0.0 and NEG_INFINITY.

Examples

use half::f16;

let nan = half::consts::NAN;
let f = f16::from_f32(7.0f32);
let g = f16::from_f32(-7.0f32);

assert!(!f.is_sign_negative());
assert!(g.is_sign_negative());
// Requires both tests to determine if is `NaN`.
assert!(!nan.is_sign_positive() && !nan.is_sign_negative());

Trait Implementations

impl Clone for f16
[src]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

impl Copy for f16
[src]

impl Default for f16
[src]

[src]

Returns the "default value" for a type. Read more

impl From<i8> for f16
[src]

[src]

Performs the conversion.

impl From<u8> for f16
[src]

[src]

Performs the conversion.

impl PartialEq for f16
[src]

[src]

This method tests for self and other values to be equal, and is used by ==. Read more

1.0.0
[src]

This method tests for !=.

impl PartialOrd for f16
[src]

[src]

This method returns an ordering between self and other values if one exists. Read more

[src]

This method tests less than (for self and other) and is used by the < operator. Read more

[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

[src]

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl FromStr for f16
[src]

The associated error which can be returned from parsing.

[src]

Parses a string s to return a value of this type. Read more

impl Debug for f16
[src]

[src]

Formats the value using the given formatter.

impl Display for f16
[src]

[src]

Formats the value using the given formatter. Read more

impl LowerExp for f16
[src]

[src]

Formats the value using the given formatter.

impl UpperExp for f16
[src]

[src]

Formats the value using the given formatter.