[][src]Trait pbrt::core::geometry::Number

pub trait Number where
    Self: Sized + Copy + Display + PartialOrd + Add<Output = Self> + Div<Output = Self> + Mul<Output = Self> + Sub<Output = Self>, 
{ fn is_nan(self) -> bool;
fn min_value() -> Self;
fn max_value() -> Self;
fn max(self, other: Self) -> Self;
fn min(self, other: Self) -> Self; }

Trait for ensuring methods present on only {float} or {integer} types have appropriate implementations as necessary for this crate.

Required methods

fn is_nan(self) -> bool

Returns true if this value is NaN.

Examples

use pbrt::core::geometry::Number;
use pbrt::float::NAN;
use pbrt::Float;

let i: isize = 1;
let f1: Float = 1.;
let f2 = NAN;
assert_eq!(Number::is_nan(f1), false);
assert_eq!(Number::is_nan(f2), true);
assert_eq!(Number::is_nan(i), false);

fn min_value() -> Self

Returns the smallest value this type can hold.

Examples

use pbrt::core::geometry::Number;
use pbrt::Float;

#[cfg(not(feature = "float-as-double"))]
assert_eq!(<Float as Number>::min_value(), -3.4028235e+38);
#[cfg(feature = "float-as-double")]
assert_eq!(<Float as Number>::min_value(), -1.7976931348623157e+308);
assert_eq!(<isize as Number>::min_value(), -9223372036854775808);

fn max_value() -> Self

Returns the largest value this type can hold.

Examples

use pbrt::core::geometry::Number;
use pbrt::Float;

#[cfg(not(feature = "float-as-double"))]
assert_eq!(<Float as Number>::max_value(), 3.4028235e+38);
#[cfg(feature = "float-as-double")]
assert_eq!(<Float as Number>::max_value(), 1.7976931348623157e+308);
assert_eq!(<isize as Number>::max_value(), 9223372036854775807);

fn max(self, other: Self) -> Self

Returns the maximum of self or other. No special care is taken for NaN and infinity.

Examples

use pbrt::core::geometry::Number;
use pbrt::Float;

let x: Float = 1.;
let y: Float = 2.;

assert_eq!(Number::max(x, y), y);
assert_eq!(Number::max(x, y), y);

let a: isize = 1;
let b: isize = 2;

assert_eq!(Number::max(a, b), b);
assert_eq!(Number::max(a, b), b);

fn bigger<T>(m: T, n: T) -> T
where
    T: Number,
{
    m.max(n)
}
assert_eq!(bigger(a, b), b)

fn min(self, other: Self) -> Self

Returns the minimum of self or other. No special care is taken for NaN and infinity.

Examples

use pbrt::core::geometry::Number;
use pbrt::Float;

let x: Float = 1.;
let y: Float = 2.;

assert_eq!(Number::min(x, y), x);
assert_eq!(Number::min(x, y), x);

let a: isize = 1;
let b: isize = 2;

assert_eq!(Number::min(a, b), a);
assert_eq!(Number::min(a, b), a);

fn smaller<T>(m: T, n: T) -> T
where
    T: Number,
{
    m.min(n)
}
assert_eq!(smaller(a, b), a)
Loading content...

Implementations on Foreign Types

impl Number for isize[src]

Loading content...

Implementors

impl Number for Float[src]

Loading content...