Use ///
doc-comment form instead of /** */
This commit is contained in:
parent
ad0b337036
commit
dbc2e99693
7 changed files with 658 additions and 659 deletions
|
@ -304,13 +304,13 @@ impl Signed for f32 {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn abs(&self) -> f32 { abs(*self) }
|
fn abs(&self) -> f32 { abs(*self) }
|
||||||
|
|
||||||
/**
|
///
|
||||||
* # Returns
|
/// # Returns
|
||||||
*
|
///
|
||||||
* - `1.0` if the number is positive, `+0.0` or `infinity`
|
/// - `1.0` if the number is positive, `+0.0` or `infinity`
|
||||||
* - `-1.0` if the number is negative, `-0.0` or `neg_infinity`
|
/// - `-1.0` if the number is negative, `-0.0` or `neg_infinity`
|
||||||
* - `NaN` if the number is `NaN`
|
/// - `NaN` if the number is NaN
|
||||||
*/
|
///
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn signum(&self) -> f32 {
|
fn signum(&self) -> f32 {
|
||||||
if is_NaN(*self) { NaN } else { copysign(1.0, *self) }
|
if is_NaN(*self) { NaN } else { copysign(1.0, *self) }
|
||||||
|
@ -509,17 +509,17 @@ impl Real for f32 {
|
||||||
fn tanh(&self) -> f32 { tanh(*self) }
|
fn tanh(&self) -> f32 { tanh(*self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
//
|
||||||
* Section: String Conversions
|
// Section: String Conversions
|
||||||
*/
|
//
|
||||||
|
|
||||||
/**
|
///
|
||||||
* Converts a float to a string
|
/// Converts a float to a string
|
||||||
*
|
///
|
||||||
* # Arguments
|
/// # Arguments
|
||||||
*
|
///
|
||||||
* * num - The float value
|
/// * num - The float value
|
||||||
*/
|
///
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn to_str(num: f32) -> ~str {
|
pub fn to_str(num: f32) -> ~str {
|
||||||
let (r, _) = strconv::to_str_common(
|
let (r, _) = strconv::to_str_common(
|
||||||
|
@ -527,13 +527,13 @@ pub fn to_str(num: f32) -> ~str {
|
||||||
r
|
r
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
///
|
||||||
* Converts a float to a string in hexadecimal format
|
/// Converts a float to a string in hexadecimal format
|
||||||
*
|
///
|
||||||
* # Arguments
|
/// # Arguments
|
||||||
*
|
///
|
||||||
* * num - The float value
|
/// * num - The float value
|
||||||
*/
|
///
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn to_str_hex(num: f32) -> ~str {
|
pub fn to_str_hex(num: f32) -> ~str {
|
||||||
let (r, _) = strconv::to_str_common(
|
let (r, _) = strconv::to_str_common(
|
||||||
|
@ -541,20 +541,20 @@ pub fn to_str_hex(num: f32) -> ~str {
|
||||||
r
|
r
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
///
|
||||||
* Converts a float to a string in a given radix
|
/// Converts a float to a string in a given radix
|
||||||
*
|
///
|
||||||
* # Arguments
|
/// # Arguments
|
||||||
*
|
///
|
||||||
* * num - The float value
|
/// * num - The float value
|
||||||
* * radix - The base to use
|
/// * radix - The base to use
|
||||||
*
|
///
|
||||||
* # Failure
|
/// # Failure
|
||||||
*
|
///
|
||||||
* Fails if called on a special value like `inf`, `-inf` or `NaN` due to
|
/// Fails if called on a special value like `inf`, `-inf` or `NaN` due to
|
||||||
* possible misinterpretation of the result at higher bases. If those values
|
/// possible misinterpretation of the result at higher bases. If those values
|
||||||
* are expected, use `to_str_radix_special()` instead.
|
/// are expected, use `to_str_radix_special()` instead.
|
||||||
*/
|
///
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn to_str_radix(num: f32, rdx: uint) -> ~str {
|
pub fn to_str_radix(num: f32, rdx: uint) -> ~str {
|
||||||
let (r, special) = strconv::to_str_common(
|
let (r, special) = strconv::to_str_common(
|
||||||
|
@ -564,30 +564,30 @@ pub fn to_str_radix(num: f32, rdx: uint) -> ~str {
|
||||||
r
|
r
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
///
|
||||||
* Converts a float to a string in a given radix, and a flag indicating
|
/// Converts a float to a string in a given radix, and a flag indicating
|
||||||
* whether it's a special value
|
/// whether it's a special value
|
||||||
*
|
///
|
||||||
* # Arguments
|
/// # Arguments
|
||||||
*
|
///
|
||||||
* * num - The float value
|
/// * num - The float value
|
||||||
* * radix - The base to use
|
/// * radix - The base to use
|
||||||
*/
|
///
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn to_str_radix_special(num: f32, rdx: uint) -> (~str, bool) {
|
pub fn to_str_radix_special(num: f32, rdx: uint) -> (~str, bool) {
|
||||||
strconv::to_str_common(&num, rdx, true,
|
strconv::to_str_common(&num, rdx, true,
|
||||||
strconv::SignNeg, strconv::DigAll)
|
strconv::SignNeg, strconv::DigAll)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
///
|
||||||
* Converts a float to a string with exactly the number of
|
/// Converts a float to a string with exactly the number of
|
||||||
* provided significant digits
|
/// provided significant digits
|
||||||
*
|
///
|
||||||
* # Arguments
|
/// # Arguments
|
||||||
*
|
///
|
||||||
* * num - The float value
|
/// * num - The float value
|
||||||
* * digits - The number of significant digits
|
/// * digits - The number of significant digits
|
||||||
*/
|
///
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn to_str_exact(num: f32, dig: uint) -> ~str {
|
pub fn to_str_exact(num: f32, dig: uint) -> ~str {
|
||||||
let (r, _) = strconv::to_str_common(
|
let (r, _) = strconv::to_str_common(
|
||||||
|
@ -595,15 +595,15 @@ pub fn to_str_exact(num: f32, dig: uint) -> ~str {
|
||||||
r
|
r
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
///
|
||||||
* Converts a float to a string with a maximum number of
|
/// Converts a float to a string with a maximum number of
|
||||||
* significant digits
|
/// significant digits
|
||||||
*
|
///
|
||||||
* # Arguments
|
/// # Arguments
|
||||||
*
|
///
|
||||||
* * num - The float value
|
/// * num - The float value
|
||||||
* * digits - The number of significant digits
|
/// * digits - The number of significant digits
|
||||||
*/
|
///
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn to_str_digits(num: f32, dig: uint) -> ~str {
|
pub fn to_str_digits(num: f32, dig: uint) -> ~str {
|
||||||
let (r, _) = strconv::to_str_common(
|
let (r, _) = strconv::to_str_common(
|
||||||
|
@ -623,91 +623,91 @@ impl num::ToStrRadix for f32 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
///
|
||||||
* Convert a string in base 10 to a float.
|
/// Convert a string in base 10 to a float.
|
||||||
* Accepts a optional decimal exponent.
|
/// Accepts a optional decimal exponent.
|
||||||
*
|
///
|
||||||
* This function accepts strings such as
|
/// This function accepts strings such as
|
||||||
*
|
///
|
||||||
* * '3.14'
|
/// * '3.14'
|
||||||
* * '+3.14', equivalent to '3.14'
|
/// * '+3.14', equivalent to '3.14'
|
||||||
* * '-3.14'
|
/// * '-3.14'
|
||||||
* * '2.5E10', or equivalently, '2.5e10'
|
/// * '2.5E10', or equivalently, '2.5e10'
|
||||||
* * '2.5E-10'
|
/// * '2.5E-10'
|
||||||
* * '.' (understood as 0)
|
/// * '.' (understood as 0)
|
||||||
* * '5.'
|
/// * '5.'
|
||||||
* * '.5', or, equivalently, '0.5'
|
/// * '.5', or, equivalently, '0.5'
|
||||||
* * '+inf', 'inf', '-inf', 'NaN'
|
/// * '+inf', 'inf', '-inf', 'NaN'
|
||||||
*
|
///
|
||||||
* Leading and trailing whitespace represent an error.
|
/// Leading and trailing whitespace represent an error.
|
||||||
*
|
///
|
||||||
* # Arguments
|
/// # Arguments
|
||||||
*
|
///
|
||||||
* * num - A string
|
/// * num - A string
|
||||||
*
|
///
|
||||||
* # Return value
|
/// # Return value
|
||||||
*
|
///
|
||||||
* `none` if the string did not represent a valid number. Otherwise,
|
/// `none` if the string did not represent a valid number. Otherwise,
|
||||||
* `Some(n)` where `n` is the floating-point number represented by `num`.
|
/// `Some(n)` where `n` is the floating-point number represented by `num`.
|
||||||
*/
|
///
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn from_str(num: &str) -> Option<f32> {
|
pub fn from_str(num: &str) -> Option<f32> {
|
||||||
strconv::from_str_common(num, 10u, true, true, true,
|
strconv::from_str_common(num, 10u, true, true, true,
|
||||||
strconv::ExpDec, false, false)
|
strconv::ExpDec, false, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
///
|
||||||
* Convert a string in base 16 to a float.
|
/// Convert a string in base 16 to a float.
|
||||||
* Accepts a optional binary exponent.
|
/// Accepts a optional binary exponent.
|
||||||
*
|
///
|
||||||
* This function accepts strings such as
|
/// This function accepts strings such as
|
||||||
*
|
///
|
||||||
* * 'a4.fe'
|
/// * 'a4.fe'
|
||||||
* * '+a4.fe', equivalent to 'a4.fe'
|
/// * '+a4.fe', equivalent to 'a4.fe'
|
||||||
* * '-a4.fe'
|
/// * '-a4.fe'
|
||||||
* * '2b.aP128', or equivalently, '2b.ap128'
|
/// * '2b.aP128', or equivalently, '2b.ap128'
|
||||||
* * '2b.aP-128'
|
/// * '2b.aP-128'
|
||||||
* * '.' (understood as 0)
|
/// * '.' (understood as 0)
|
||||||
* * 'c.'
|
/// * 'c.'
|
||||||
* * '.c', or, equivalently, '0.c'
|
/// * '.c', or, equivalently, '0.c'
|
||||||
* * '+inf', 'inf', '-inf', 'NaN'
|
/// * '+inf', 'inf', '-inf', 'NaN'
|
||||||
*
|
///
|
||||||
* Leading and trailing whitespace represent an error.
|
/// Leading and trailing whitespace represent an error.
|
||||||
*
|
///
|
||||||
* # Arguments
|
/// # Arguments
|
||||||
*
|
///
|
||||||
* * num - A string
|
/// * num - A string
|
||||||
*
|
///
|
||||||
* # Return value
|
/// # Return value
|
||||||
*
|
///
|
||||||
* `none` if the string did not represent a valid number. Otherwise,
|
/// `none` if the string did not represent a valid number. Otherwise,
|
||||||
* `Some(n)` where `n` is the floating-point number represented by `[num]`.
|
/// `Some(n)` where `n` is the floating-point number represented by `[num]`.
|
||||||
*/
|
///
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn from_str_hex(num: &str) -> Option<f32> {
|
pub fn from_str_hex(num: &str) -> Option<f32> {
|
||||||
strconv::from_str_common(num, 16u, true, true, true,
|
strconv::from_str_common(num, 16u, true, true, true,
|
||||||
strconv::ExpBin, false, false)
|
strconv::ExpBin, false, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
///
|
||||||
* Convert a string in an given base to a float.
|
/// Convert a string in an given base to a float.
|
||||||
*
|
///
|
||||||
* Due to possible conflicts, this function does **not** accept
|
/// Due to possible conflicts, this function does **not** accept
|
||||||
* the special values `inf`, `-inf`, `+inf` and `NaN`, **nor**
|
/// the special values `inf`, `-inf`, `+inf` and `NaN`, **nor**
|
||||||
* does it recognize exponents of any kind.
|
/// does it recognize exponents of any kind.
|
||||||
*
|
///
|
||||||
* Leading and trailing whitespace represent an error.
|
/// Leading and trailing whitespace represent an error.
|
||||||
*
|
///
|
||||||
* # Arguments
|
/// # Arguments
|
||||||
*
|
///
|
||||||
* * num - A string
|
/// * num - A string
|
||||||
* * radix - The base to use. Must lie in the range [2 .. 36]
|
/// * radix - The base to use. Must lie in the range [2 .. 36]
|
||||||
*
|
///
|
||||||
* # Return value
|
/// # Return value
|
||||||
*
|
///
|
||||||
* `none` if the string did not represent a valid number. Otherwise,
|
/// `none` if the string did not represent a valid number. Otherwise,
|
||||||
* `Some(n)` where `n` is the floating-point number represented by `num`.
|
/// `Some(n)` where `n` is the floating-point number represented by `num`.
|
||||||
*/
|
///
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn from_str_radix(num: &str, rdx: uint) -> Option<f32> {
|
pub fn from_str_radix(num: &str, rdx: uint) -> Option<f32> {
|
||||||
strconv::from_str_common(num, rdx, true, true, false,
|
strconv::from_str_common(num, rdx, true, true, false,
|
||||||
|
|
|
@ -314,13 +314,13 @@ impl Signed for f64 {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn abs(&self) -> f64 { abs(*self) }
|
fn abs(&self) -> f64 { abs(*self) }
|
||||||
|
|
||||||
/**
|
///
|
||||||
* # Returns
|
/// # Returns
|
||||||
*
|
///
|
||||||
* - `1.0` if the number is positive, `+0.0` or `infinity`
|
/// - `1.0` if the number is positive, `+0.0` or `infinity`
|
||||||
* - `-1.0` if the number is negative, `-0.0` or `neg_infinity`
|
/// - `-1.0` if the number is negative, `-0.0` or `neg_infinity`
|
||||||
* - `NaN` if the number is `NaN`
|
/// - `NaN` if the number is NaN
|
||||||
*/
|
///
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn signum(&self) -> f64 {
|
fn signum(&self) -> f64 {
|
||||||
if is_NaN(*self) { NaN } else { copysign(1.0, *self) }
|
if is_NaN(*self) { NaN } else { copysign(1.0, *self) }
|
||||||
|
@ -549,17 +549,17 @@ impl RealExt for f64 {
|
||||||
fn yn(&self, n: int) -> f64 { yn(n as c_int, *self) }
|
fn yn(&self, n: int) -> f64 { yn(n as c_int, *self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
//
|
||||||
* Section: String Conversions
|
// Section: String Conversions
|
||||||
*/
|
//
|
||||||
|
|
||||||
/**
|
///
|
||||||
* Converts a float to a string
|
/// Converts a float to a string
|
||||||
*
|
///
|
||||||
* # Arguments
|
/// # Arguments
|
||||||
*
|
///
|
||||||
* * num - The float value
|
/// * num - The float value
|
||||||
*/
|
///
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn to_str(num: f64) -> ~str {
|
pub fn to_str(num: f64) -> ~str {
|
||||||
let (r, _) = strconv::to_str_common(
|
let (r, _) = strconv::to_str_common(
|
||||||
|
@ -567,13 +567,13 @@ pub fn to_str(num: f64) -> ~str {
|
||||||
r
|
r
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
///
|
||||||
* Converts a float to a string in hexadecimal format
|
/// Converts a float to a string in hexadecimal format
|
||||||
*
|
///
|
||||||
* # Arguments
|
/// # Arguments
|
||||||
*
|
///
|
||||||
* * num - The float value
|
/// * num - The float value
|
||||||
*/
|
///
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn to_str_hex(num: f64) -> ~str {
|
pub fn to_str_hex(num: f64) -> ~str {
|
||||||
let (r, _) = strconv::to_str_common(
|
let (r, _) = strconv::to_str_common(
|
||||||
|
@ -581,20 +581,20 @@ pub fn to_str_hex(num: f64) -> ~str {
|
||||||
r
|
r
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
///
|
||||||
* Converts a float to a string in a given radix
|
/// Converts a float to a string in a given radix
|
||||||
*
|
///
|
||||||
* # Arguments
|
/// # Arguments
|
||||||
*
|
///
|
||||||
* * num - The float value
|
/// * num - The float value
|
||||||
* * radix - The base to use
|
/// * radix - The base to use
|
||||||
*
|
///
|
||||||
* # Failure
|
/// # Failure
|
||||||
*
|
///
|
||||||
* Fails if called on a special value like `inf`, `-inf` or `NaN` due to
|
/// Fails if called on a special value like `inf`, `-inf` or `NaN` due to
|
||||||
* possible misinterpretation of the result at higher bases. If those values
|
/// possible misinterpretation of the result at higher bases. If those values
|
||||||
* are expected, use `to_str_radix_special()` instead.
|
/// are expected, use `to_str_radix_special()` instead.
|
||||||
*/
|
///
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn to_str_radix(num: f64, rdx: uint) -> ~str {
|
pub fn to_str_radix(num: f64, rdx: uint) -> ~str {
|
||||||
let (r, special) = strconv::to_str_common(
|
let (r, special) = strconv::to_str_common(
|
||||||
|
@ -604,30 +604,30 @@ pub fn to_str_radix(num: f64, rdx: uint) -> ~str {
|
||||||
r
|
r
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
///
|
||||||
* Converts a float to a string in a given radix, and a flag indicating
|
/// Converts a float to a string in a given radix, and a flag indicating
|
||||||
* whether it's a special value
|
/// whether it's a special value
|
||||||
*
|
///
|
||||||
* # Arguments
|
/// # Arguments
|
||||||
*
|
///
|
||||||
* * num - The float value
|
/// * num - The float value
|
||||||
* * radix - The base to use
|
/// * radix - The base to use
|
||||||
*/
|
///
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn to_str_radix_special(num: f64, rdx: uint) -> (~str, bool) {
|
pub fn to_str_radix_special(num: f64, rdx: uint) -> (~str, bool) {
|
||||||
strconv::to_str_common(&num, rdx, true,
|
strconv::to_str_common(&num, rdx, true,
|
||||||
strconv::SignNeg, strconv::DigAll)
|
strconv::SignNeg, strconv::DigAll)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
///
|
||||||
* Converts a float to a string with exactly the number of
|
/// Converts a float to a string with exactly the number of
|
||||||
* provided significant digits
|
/// provided significant digits
|
||||||
*
|
///
|
||||||
* # Arguments
|
/// # Arguments
|
||||||
*
|
///
|
||||||
* * num - The float value
|
/// * num - The float value
|
||||||
* * digits - The number of significant digits
|
/// * digits - The number of significant digits
|
||||||
*/
|
///
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn to_str_exact(num: f64, dig: uint) -> ~str {
|
pub fn to_str_exact(num: f64, dig: uint) -> ~str {
|
||||||
let (r, _) = strconv::to_str_common(
|
let (r, _) = strconv::to_str_common(
|
||||||
|
@ -635,15 +635,15 @@ pub fn to_str_exact(num: f64, dig: uint) -> ~str {
|
||||||
r
|
r
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
///
|
||||||
* Converts a float to a string with a maximum number of
|
/// Converts a float to a string with a maximum number of
|
||||||
* significant digits
|
/// significant digits
|
||||||
*
|
///
|
||||||
* # Arguments
|
/// # Arguments
|
||||||
*
|
///
|
||||||
* * num - The float value
|
/// * num - The float value
|
||||||
* * digits - The number of significant digits
|
/// * digits - The number of significant digits
|
||||||
*/
|
///
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn to_str_digits(num: f64, dig: uint) -> ~str {
|
pub fn to_str_digits(num: f64, dig: uint) -> ~str {
|
||||||
let (r, _) = strconv::to_str_common(
|
let (r, _) = strconv::to_str_common(
|
||||||
|
@ -663,91 +663,91 @@ impl num::ToStrRadix for f64 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
///
|
||||||
* Convert a string in base 10 to a float.
|
/// Convert a string in base 10 to a float.
|
||||||
* Accepts a optional decimal exponent.
|
/// Accepts a optional decimal exponent.
|
||||||
*
|
///
|
||||||
* This function accepts strings such as
|
/// This function accepts strings such as
|
||||||
*
|
///
|
||||||
* * '3.14'
|
/// * '3.14'
|
||||||
* * '+3.14', equivalent to '3.14'
|
/// * '+3.14', equivalent to '3.14'
|
||||||
* * '-3.14'
|
/// * '-3.14'
|
||||||
* * '2.5E10', or equivalently, '2.5e10'
|
/// * '2.5E10', or equivalently, '2.5e10'
|
||||||
* * '2.5E-10'
|
/// * '2.5E-10'
|
||||||
* * '.' (understood as 0)
|
/// * '.' (understood as 0)
|
||||||
* * '5.'
|
/// * '5.'
|
||||||
* * '.5', or, equivalently, '0.5'
|
/// * '.5', or, equivalently, '0.5'
|
||||||
* * '+inf', 'inf', '-inf', 'NaN'
|
/// * '+inf', 'inf', '-inf', 'NaN'
|
||||||
*
|
///
|
||||||
* Leading and trailing whitespace represent an error.
|
/// Leading and trailing whitespace represent an error.
|
||||||
*
|
///
|
||||||
* # Arguments
|
/// # Arguments
|
||||||
*
|
///
|
||||||
* * num - A string
|
/// * num - A string
|
||||||
*
|
///
|
||||||
* # Return value
|
/// # Return value
|
||||||
*
|
///
|
||||||
* `none` if the string did not represent a valid number. Otherwise,
|
/// `none` if the string did not represent a valid number. Otherwise,
|
||||||
* `Some(n)` where `n` is the floating-point number represented by `num`.
|
/// `Some(n)` where `n` is the floating-point number represented by `num`.
|
||||||
*/
|
///
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn from_str(num: &str) -> Option<f64> {
|
pub fn from_str(num: &str) -> Option<f64> {
|
||||||
strconv::from_str_common(num, 10u, true, true, true,
|
strconv::from_str_common(num, 10u, true, true, true,
|
||||||
strconv::ExpDec, false, false)
|
strconv::ExpDec, false, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
///
|
||||||
* Convert a string in base 16 to a float.
|
/// Convert a string in base 16 to a float.
|
||||||
* Accepts a optional binary exponent.
|
/// Accepts a optional binary exponent.
|
||||||
*
|
///
|
||||||
* This function accepts strings such as
|
/// This function accepts strings such as
|
||||||
*
|
///
|
||||||
* * 'a4.fe'
|
/// * 'a4.fe'
|
||||||
* * '+a4.fe', equivalent to 'a4.fe'
|
/// * '+a4.fe', equivalent to 'a4.fe'
|
||||||
* * '-a4.fe'
|
/// * '-a4.fe'
|
||||||
* * '2b.aP128', or equivalently, '2b.ap128'
|
/// * '2b.aP128', or equivalently, '2b.ap128'
|
||||||
* * '2b.aP-128'
|
/// * '2b.aP-128'
|
||||||
* * '.' (understood as 0)
|
/// * '.' (understood as 0)
|
||||||
* * 'c.'
|
/// * 'c.'
|
||||||
* * '.c', or, equivalently, '0.c'
|
/// * '.c', or, equivalently, '0.c'
|
||||||
* * '+inf', 'inf', '-inf', 'NaN'
|
/// * '+inf', 'inf', '-inf', 'NaN'
|
||||||
*
|
///
|
||||||
* Leading and trailing whitespace represent an error.
|
/// Leading and trailing whitespace represent an error.
|
||||||
*
|
///
|
||||||
* # Arguments
|
/// # Arguments
|
||||||
*
|
///
|
||||||
* * num - A string
|
/// * num - A string
|
||||||
*
|
///
|
||||||
* # Return value
|
/// # Return value
|
||||||
*
|
///
|
||||||
* `none` if the string did not represent a valid number. Otherwise,
|
/// `none` if the string did not represent a valid number. Otherwise,
|
||||||
* `Some(n)` where `n` is the floating-point number represented by `[num]`.
|
/// `Some(n)` where `n` is the floating-point number represented by `[num]`.
|
||||||
*/
|
///
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn from_str_hex(num: &str) -> Option<f64> {
|
pub fn from_str_hex(num: &str) -> Option<f64> {
|
||||||
strconv::from_str_common(num, 16u, true, true, true,
|
strconv::from_str_common(num, 16u, true, true, true,
|
||||||
strconv::ExpBin, false, false)
|
strconv::ExpBin, false, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
///
|
||||||
* Convert a string in an given base to a float.
|
/// Convert a string in an given base to a float.
|
||||||
*
|
///
|
||||||
* Due to possible conflicts, this function does **not** accept
|
/// Due to possible conflicts, this function does **not** accept
|
||||||
* the special values `inf`, `-inf`, `+inf` and `NaN`, **nor**
|
/// the special values `inf`, `-inf`, `+inf` and `NaN`, **nor**
|
||||||
* does it recognize exponents of any kind.
|
/// does it recognize exponents of any kind.
|
||||||
*
|
///
|
||||||
* Leading and trailing whitespace represent an error.
|
/// Leading and trailing whitespace represent an error.
|
||||||
*
|
///
|
||||||
* # Arguments
|
/// # Arguments
|
||||||
*
|
///
|
||||||
* * num - A string
|
/// * num - A string
|
||||||
* * radix - The base to use. Must lie in the range [2 .. 36]
|
/// * radix - The base to use. Must lie in the range [2 .. 36]
|
||||||
*
|
///
|
||||||
* # Return value
|
/// # Return value
|
||||||
*
|
///
|
||||||
* `none` if the string did not represent a valid number. Otherwise,
|
/// `none` if the string did not represent a valid number. Otherwise,
|
||||||
* `Some(n)` where `n` is the floating-point number represented by `num`.
|
/// `Some(n)` where `n` is the floating-point number represented by `num`.
|
||||||
*/
|
///
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn from_str_radix(num: &str, rdx: uint) -> Option<f64> {
|
pub fn from_str_radix(num: &str, rdx: uint) -> Option<f64> {
|
||||||
strconv::from_str_common(num, rdx, true, true, false,
|
strconv::from_str_common(num, rdx, true, true, false,
|
||||||
|
|
|
@ -84,17 +84,17 @@ pub mod consts {
|
||||||
pub static ln_10: float = 2.30258509299404568401799145468436421;
|
pub static ln_10: float = 2.30258509299404568401799145468436421;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
//
|
||||||
* Section: String Conversions
|
// Section: String Conversions
|
||||||
*/
|
//
|
||||||
|
|
||||||
/**
|
///
|
||||||
* Converts a float to a string
|
/// Converts a float to a string
|
||||||
*
|
///
|
||||||
* # Arguments
|
/// # Arguments
|
||||||
*
|
///
|
||||||
* * num - The float value
|
/// * num - The float value
|
||||||
*/
|
///
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn to_str(num: float) -> ~str {
|
pub fn to_str(num: float) -> ~str {
|
||||||
let (r, _) = strconv::to_str_common(
|
let (r, _) = strconv::to_str_common(
|
||||||
|
@ -102,13 +102,13 @@ pub fn to_str(num: float) -> ~str {
|
||||||
r
|
r
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
///
|
||||||
* Converts a float to a string in hexadecimal format
|
/// Converts a float to a string in hexadecimal format
|
||||||
*
|
///
|
||||||
* # Arguments
|
/// # Arguments
|
||||||
*
|
///
|
||||||
* * num - The float value
|
/// * num - The float value
|
||||||
*/
|
///
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn to_str_hex(num: float) -> ~str {
|
pub fn to_str_hex(num: float) -> ~str {
|
||||||
let (r, _) = strconv::to_str_common(
|
let (r, _) = strconv::to_str_common(
|
||||||
|
@ -116,20 +116,20 @@ pub fn to_str_hex(num: float) -> ~str {
|
||||||
r
|
r
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
///
|
||||||
* Converts a float to a string in a given radix
|
/// Converts a float to a string in a given radix
|
||||||
*
|
///
|
||||||
* # Arguments
|
/// # Arguments
|
||||||
*
|
///
|
||||||
* * num - The float value
|
/// * num - The float value
|
||||||
* * radix - The base to use
|
/// * radix - The base to use
|
||||||
*
|
///
|
||||||
* # Failure
|
/// # Failure
|
||||||
*
|
///
|
||||||
* Fails if called on a special value like `inf`, `-inf` or `NaN` due to
|
/// Fails if called on a special value like `inf`, `-inf` or `NaN` due to
|
||||||
* possible misinterpretation of the result at higher bases. If those values
|
/// possible misinterpretation of the result at higher bases. If those values
|
||||||
* are expected, use `to_str_radix_special()` instead.
|
/// are expected, use `to_str_radix_special()` instead.
|
||||||
*/
|
///
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn to_str_radix(num: float, radix: uint) -> ~str {
|
pub fn to_str_radix(num: float, radix: uint) -> ~str {
|
||||||
let (r, special) = strconv::to_str_common(
|
let (r, special) = strconv::to_str_common(
|
||||||
|
@ -139,30 +139,30 @@ pub fn to_str_radix(num: float, radix: uint) -> ~str {
|
||||||
r
|
r
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
///
|
||||||
* Converts a float to a string in a given radix, and a flag indicating
|
/// Converts a float to a string in a given radix, and a flag indicating
|
||||||
* whether it's a special value
|
/// whether it's a special value
|
||||||
*
|
///
|
||||||
* # Arguments
|
/// # Arguments
|
||||||
*
|
///
|
||||||
* * num - The float value
|
/// * num - The float value
|
||||||
* * radix - The base to use
|
/// * radix - The base to use
|
||||||
*/
|
///
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn to_str_radix_special(num: float, radix: uint) -> (~str, bool) {
|
pub fn to_str_radix_special(num: float, radix: uint) -> (~str, bool) {
|
||||||
strconv::to_str_common(&num, radix, true,
|
strconv::to_str_common(&num, radix, true,
|
||||||
strconv::SignNeg, strconv::DigAll)
|
strconv::SignNeg, strconv::DigAll)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
///
|
||||||
* Converts a float to a string with exactly the number of
|
/// Converts a float to a string with exactly the number of
|
||||||
* provided significant digits
|
/// provided significant digits
|
||||||
*
|
///
|
||||||
* # Arguments
|
/// # Arguments
|
||||||
*
|
///
|
||||||
* * num - The float value
|
/// * num - The float value
|
||||||
* * digits - The number of significant digits
|
/// * digits - The number of significant digits
|
||||||
*/
|
///
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn to_str_exact(num: float, digits: uint) -> ~str {
|
pub fn to_str_exact(num: float, digits: uint) -> ~str {
|
||||||
let (r, _) = strconv::to_str_common(
|
let (r, _) = strconv::to_str_common(
|
||||||
|
@ -170,15 +170,15 @@ pub fn to_str_exact(num: float, digits: uint) -> ~str {
|
||||||
r
|
r
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
///
|
||||||
* Converts a float to a string with a maximum number of
|
/// Converts a float to a string with a maximum number of
|
||||||
* significant digits
|
/// significant digits
|
||||||
*
|
///
|
||||||
* # Arguments
|
/// # Arguments
|
||||||
*
|
///
|
||||||
* * num - The float value
|
/// * num - The float value
|
||||||
* * digits - The number of significant digits
|
/// * digits - The number of significant digits
|
||||||
*/
|
///
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn to_str_digits(num: float, digits: uint) -> ~str {
|
pub fn to_str_digits(num: float, digits: uint) -> ~str {
|
||||||
let (r, _) = strconv::to_str_common(
|
let (r, _) = strconv::to_str_common(
|
||||||
|
@ -198,91 +198,91 @@ impl num::ToStrRadix for float {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
///
|
||||||
* Convert a string in base 10 to a float.
|
/// Convert a string in base 10 to a float.
|
||||||
* Accepts a optional decimal exponent.
|
/// Accepts a optional decimal exponent.
|
||||||
*
|
///
|
||||||
* This function accepts strings such as
|
/// This function accepts strings such as
|
||||||
*
|
///
|
||||||
* * '3.14'
|
/// * '3.14'
|
||||||
* * '+3.14', equivalent to '3.14'
|
/// * '+3.14', equivalent to '3.14'
|
||||||
* * '-3.14'
|
/// * '-3.14'
|
||||||
* * '2.5E10', or equivalently, '2.5e10'
|
/// * '2.5E10', or equivalently, '2.5e10'
|
||||||
* * '2.5E-10'
|
/// * '2.5E-10'
|
||||||
* * '.' (understood as 0)
|
/// * '.' (understood as 0)
|
||||||
* * '5.'
|
/// * '5.'
|
||||||
* * '.5', or, equivalently, '0.5'
|
/// * '.5', or, equivalently, '0.5'
|
||||||
* * '+inf', 'inf', '-inf', 'NaN'
|
/// * '+inf', 'inf', '-inf', 'NaN'
|
||||||
*
|
///
|
||||||
* Leading and trailing whitespace represent an error.
|
/// Leading and trailing whitespace represent an error.
|
||||||
*
|
///
|
||||||
* # Arguments
|
/// # Arguments
|
||||||
*
|
///
|
||||||
* * num - A string
|
/// * num - A string
|
||||||
*
|
///
|
||||||
* # Return value
|
/// # Return value
|
||||||
*
|
///
|
||||||
* `none` if the string did not represent a valid number. Otherwise,
|
/// `none` if the string did not represent a valid number. Otherwise,
|
||||||
* `Some(n)` where `n` is the floating-point number represented by `num`.
|
/// `Some(n)` where `n` is the floating-point number represented by `num`.
|
||||||
*/
|
///
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn from_str(num: &str) -> Option<float> {
|
pub fn from_str(num: &str) -> Option<float> {
|
||||||
strconv::from_str_common(num, 10u, true, true, true,
|
strconv::from_str_common(num, 10u, true, true, true,
|
||||||
strconv::ExpDec, false, false)
|
strconv::ExpDec, false, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
///
|
||||||
* Convert a string in base 16 to a float.
|
/// Convert a string in base 16 to a float.
|
||||||
* Accepts a optional binary exponent.
|
/// Accepts a optional binary exponent.
|
||||||
*
|
///
|
||||||
* This function accepts strings such as
|
/// This function accepts strings such as
|
||||||
*
|
///
|
||||||
* * 'a4.fe'
|
/// * 'a4.fe'
|
||||||
* * '+a4.fe', equivalent to 'a4.fe'
|
/// * '+a4.fe', equivalent to 'a4.fe'
|
||||||
* * '-a4.fe'
|
/// * '-a4.fe'
|
||||||
* * '2b.aP128', or equivalently, '2b.ap128'
|
/// * '2b.aP128', or equivalently, '2b.ap128'
|
||||||
* * '2b.aP-128'
|
/// * '2b.aP-128'
|
||||||
* * '.' (understood as 0)
|
/// * '.' (understood as 0)
|
||||||
* * 'c.'
|
/// * 'c.'
|
||||||
* * '.c', or, equivalently, '0.c'
|
/// * '.c', or, equivalently, '0.c'
|
||||||
* * '+inf', 'inf', '-inf', 'NaN'
|
/// * '+inf', 'inf', '-inf', 'NaN'
|
||||||
*
|
///
|
||||||
* Leading and trailing whitespace represent an error.
|
/// Leading and trailing whitespace represent an error.
|
||||||
*
|
///
|
||||||
* # Arguments
|
/// # Arguments
|
||||||
*
|
///
|
||||||
* * num - A string
|
/// * num - A string
|
||||||
*
|
///
|
||||||
* # Return value
|
/// # Return value
|
||||||
*
|
///
|
||||||
* `none` if the string did not represent a valid number. Otherwise,
|
/// `none` if the string did not represent a valid number. Otherwise,
|
||||||
* `Some(n)` where `n` is the floating-point number represented by `[num]`.
|
/// `Some(n)` where `n` is the floating-point number represented by `[num]`.
|
||||||
*/
|
///
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn from_str_hex(num: &str) -> Option<float> {
|
pub fn from_str_hex(num: &str) -> Option<float> {
|
||||||
strconv::from_str_common(num, 16u, true, true, true,
|
strconv::from_str_common(num, 16u, true, true, true,
|
||||||
strconv::ExpBin, false, false)
|
strconv::ExpBin, false, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
///
|
||||||
* Convert a string in an given base to a float.
|
/// Convert a string in an given base to a float.
|
||||||
*
|
///
|
||||||
* Due to possible conflicts, this function does **not** accept
|
/// Due to possible conflicts, this function does **not** accept
|
||||||
* the special values `inf`, `-inf`, `+inf` and `NaN`, **nor**
|
/// the special values `inf`, `-inf`, `+inf` and `NaN`, **nor**
|
||||||
* does it recognize exponents of any kind.
|
/// does it recognize exponents of any kind.
|
||||||
*
|
///
|
||||||
* Leading and trailing whitespace represent an error.
|
/// Leading and trailing whitespace represent an error.
|
||||||
*
|
///
|
||||||
* # Arguments
|
/// # Arguments
|
||||||
*
|
///
|
||||||
* * num - A string
|
/// * num - A string
|
||||||
* * radix - The base to use. Must lie in the range [2 .. 36]
|
/// * radix - The base to use. Must lie in the range [2 .. 36]
|
||||||
*
|
///
|
||||||
* # Return value
|
/// # Return value
|
||||||
*
|
///
|
||||||
* `none` if the string did not represent a valid number. Otherwise,
|
/// `none` if the string did not represent a valid number. Otherwise,
|
||||||
* `Some(n)` where `n` is the floating-point number represented by `num`.
|
/// `Some(n)` where `n` is the floating-point number represented by `num`.
|
||||||
*/
|
///
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn from_str_radix(num: &str, radix: uint) -> Option<float> {
|
pub fn from_str_radix(num: &str, radix: uint) -> Option<float> {
|
||||||
strconv::from_str_common(num, radix, true, true, false,
|
strconv::from_str_common(num, radix, true, true, false,
|
||||||
|
@ -301,22 +301,22 @@ impl num::FromStrRadix for float {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
//
|
||||||
* Section: Arithmetics
|
// Section: Arithmetics
|
||||||
*/
|
//
|
||||||
|
|
||||||
/**
|
///
|
||||||
* Compute the exponentiation of an integer by another integer as a float
|
/// Compute the exponentiation of an integer by another integer as a float
|
||||||
*
|
///
|
||||||
* # Arguments
|
/// # Arguments
|
||||||
*
|
///
|
||||||
* * x - The base
|
/// * x - The base
|
||||||
* * pow - The exponent
|
/// * pow - The exponent
|
||||||
*
|
///
|
||||||
* # Return value
|
/// # Return value
|
||||||
*
|
///
|
||||||
* `NaN` if both `x` and `pow` are `0u`, otherwise `x^pow`
|
/// `NaN` if both `x` and `pow` are `0u`, otherwise `x^pow`
|
||||||
*/
|
///
|
||||||
pub fn pow_with_uint(base: uint, pow: uint) -> float {
|
pub fn pow_with_uint(base: uint, pow: uint) -> float {
|
||||||
if base == 0u {
|
if base == 0u {
|
||||||
if pow == 0u {
|
if pow == 0u {
|
||||||
|
@ -668,13 +668,13 @@ impl Signed for float {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn abs(&self) -> float { abs(*self) }
|
fn abs(&self) -> float { abs(*self) }
|
||||||
|
|
||||||
/**
|
///
|
||||||
* # Returns
|
/// # Returns
|
||||||
*
|
///
|
||||||
* - `1.0` if the number is positive, `+0.0` or `infinity`
|
/// - `1.0` if the number is positive, `+0.0` or `infinity`
|
||||||
* - `-1.0` if the number is negative, `-0.0` or `neg_infinity`
|
/// - `-1.0` if the number is negative, `-0.0` or `neg_infinity`
|
||||||
* - `NaN` if the number is NaN
|
/// - `NaN` if the number is NaN
|
||||||
*/
|
///
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn signum(&self) -> float {
|
fn signum(&self) -> float {
|
||||||
if is_NaN(*self) { NaN } else { f64::copysign(1.0, *self as f64) as float }
|
if is_NaN(*self) { NaN } else { f64::copysign(1.0, *self as f64) as float }
|
||||||
|
|
|
@ -32,26 +32,26 @@ pub fn mul(x: T, y: T) -> T { x * y }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn quot(x: T, y: T) -> T { x / y }
|
pub fn quot(x: T, y: T) -> T { x / y }
|
||||||
|
|
||||||
/**
|
///
|
||||||
* Returns the remainder of y / x.
|
/// Returns the remainder of y / x.
|
||||||
*
|
///
|
||||||
* # Examples
|
/// # Examples
|
||||||
* ~~~
|
/// ~~~
|
||||||
* assert!(int::rem(5 / 2) == 1);
|
/// assert!(int::rem(5 / 2) == 1);
|
||||||
* ~~~
|
/// ~~~
|
||||||
*
|
///
|
||||||
* When faced with negative numbers, the result copies the sign of the
|
/// When faced with negative numbers, the result copies the sign of the
|
||||||
* dividend.
|
/// dividend.
|
||||||
*
|
///
|
||||||
* ~~~
|
/// ~~~
|
||||||
* assert!(int::rem(2 / -3) == 2);
|
/// assert!(int::rem(2 / -3) == 2);
|
||||||
* ~~~
|
/// ~~~
|
||||||
*
|
///
|
||||||
* ~~~
|
/// ~~~
|
||||||
* assert!(int::rem(-2 / 3) == -2);
|
/// assert!(int::rem(-2 / 3) == -2);
|
||||||
* ~~~
|
/// ~~~
|
||||||
*
|
///
|
||||||
*/
|
///
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn rem(x: T, y: T) -> T { x % y }
|
pub fn rem(x: T, y: T) -> T { x % y }
|
||||||
|
|
||||||
|
@ -68,23 +68,23 @@ pub fn ge(x: T, y: T) -> bool { x >= y }
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn gt(x: T, y: T) -> bool { x > y }
|
pub fn gt(x: T, y: T) -> bool { x > y }
|
||||||
|
|
||||||
/**
|
///
|
||||||
* Iterate over the range [`lo`..`hi`)
|
/// Iterate over the range [`lo`..`hi`)
|
||||||
*
|
///
|
||||||
* # Arguments
|
/// # Arguments
|
||||||
*
|
///
|
||||||
* * `lo` - lower bound, inclusive
|
/// * `lo` - lower bound, inclusive
|
||||||
* * `hi` - higher bound, exclusive
|
/// * `hi` - higher bound, exclusive
|
||||||
*
|
///
|
||||||
* # Examples
|
/// # Examples
|
||||||
* ~~~
|
/// ~~~
|
||||||
* let mut sum = 0;
|
/// let mut sum = 0;
|
||||||
* for int::range(1, 5) |i| {
|
/// for int::range(1, 5) |i| {
|
||||||
* sum += i;
|
/// sum += i;
|
||||||
* }
|
/// }
|
||||||
* assert!(sum == 10);
|
/// assert!(sum == 10);
|
||||||
* ~~~
|
/// ~~~
|
||||||
*/
|
///
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
/// Iterate over the range [`start`,`start`+`step`..`stop`)
|
/// Iterate over the range [`start`,`start`+`step`..`stop`)
|
||||||
pub fn range_step(start: T, stop: T, step: T, it: &fn(T) -> bool) {
|
pub fn range_step(start: T, stop: T, step: T, it: &fn(T) -> bool) {
|
||||||
|
@ -190,24 +190,24 @@ impl Div<T,T> for T {
|
||||||
}
|
}
|
||||||
#[cfg(not(stage0),notest)]
|
#[cfg(not(stage0),notest)]
|
||||||
impl Quot<T,T> for T {
|
impl Quot<T,T> for T {
|
||||||
/**
|
///
|
||||||
* Returns the integer quotient, truncated towards 0. As this behaviour reflects
|
/// Returns the integer quotient, truncated towards 0. As this behaviour reflects
|
||||||
* the underlying machine implementation it is more efficient than `Natural::div`.
|
/// the underlying machine implementation it is more efficient than `Natural::div`.
|
||||||
*
|
///
|
||||||
* # Examples
|
/// # Examples
|
||||||
*
|
///
|
||||||
* ~~~
|
/// ~~~
|
||||||
* assert!( 8 / 3 == 2);
|
/// assert!( 8 / 3 == 2);
|
||||||
* assert!( 8 / -3 == -2);
|
/// assert!( 8 / -3 == -2);
|
||||||
* assert!(-8 / 3 == -2);
|
/// assert!(-8 / 3 == -2);
|
||||||
* assert!(-8 / -3 == 2);
|
/// assert!(-8 / -3 == 2);
|
||||||
|
|
||||||
* assert!( 1 / 2 == 0);
|
/// assert!( 1 / 2 == 0);
|
||||||
* assert!( 1 / -2 == 0);
|
/// assert!( 1 / -2 == 0);
|
||||||
* assert!(-1 / 2 == 0);
|
/// assert!(-1 / 2 == 0);
|
||||||
* assert!(-1 / -2 == 0);
|
/// assert!(-1 / -2 == 0);
|
||||||
* ~~~
|
/// ~~~
|
||||||
*/
|
///
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn quot(&self, other: &T) -> T { *self / *other }
|
fn quot(&self, other: &T) -> T { *self / *other }
|
||||||
}
|
}
|
||||||
|
@ -219,27 +219,27 @@ impl Modulo<T,T> for T {
|
||||||
}
|
}
|
||||||
#[cfg(not(stage0),notest)]
|
#[cfg(not(stage0),notest)]
|
||||||
impl Rem<T,T> for T {
|
impl Rem<T,T> for T {
|
||||||
/**
|
///
|
||||||
* Returns the integer remainder after division, satisfying:
|
/// Returns the integer remainder after division, satisfying:
|
||||||
*
|
///
|
||||||
* ~~~
|
/// ~~~
|
||||||
* assert!((n / d) * d + (n % d) == n)
|
/// assert!((n / d) * d + (n % d) == n)
|
||||||
* ~~~
|
/// ~~~
|
||||||
*
|
///
|
||||||
* # Examples
|
/// # Examples
|
||||||
*
|
///
|
||||||
* ~~~
|
/// ~~~
|
||||||
* assert!( 8 % 3 == 2);
|
/// assert!( 8 % 3 == 2);
|
||||||
* assert!( 8 % -3 == 2);
|
/// assert!( 8 % -3 == 2);
|
||||||
* assert!(-8 % 3 == -2);
|
/// assert!(-8 % 3 == -2);
|
||||||
* assert!(-8 % -3 == -2);
|
/// assert!(-8 % -3 == -2);
|
||||||
|
|
||||||
* assert!( 1 % 2 == 1);
|
/// assert!( 1 % 2 == 1);
|
||||||
* assert!( 1 % -2 == 1);
|
/// assert!( 1 % -2 == 1);
|
||||||
* assert!(-1 % 2 == -1);
|
/// assert!(-1 % 2 == -1);
|
||||||
* assert!(-1 % -2 == -1);
|
/// assert!(-1 % -2 == -1);
|
||||||
* ~~~
|
/// ~~~
|
||||||
*/
|
///
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn rem(&self, other: &T) -> T { *self % *other }
|
fn rem(&self, other: &T) -> T { *self % *other }
|
||||||
}
|
}
|
||||||
|
@ -257,13 +257,13 @@ impl Signed for T {
|
||||||
if self.is_negative() { -*self } else { *self }
|
if self.is_negative() { -*self } else { *self }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
///
|
||||||
* # Returns
|
/// # Returns
|
||||||
*
|
///
|
||||||
* - `0` if the number is zero
|
/// - `0` if the number is zero
|
||||||
* - `1` if the number is positive
|
/// - `1` if the number is positive
|
||||||
* - `-1` if the number is negative
|
/// - `-1` if the number is negative
|
||||||
*/
|
///
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn signum(&self) -> T {
|
fn signum(&self) -> T {
|
||||||
match *self {
|
match *self {
|
||||||
|
@ -283,23 +283,23 @@ impl Signed for T {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Integer for T {
|
impl Integer for T {
|
||||||
/**
|
///
|
||||||
* Floored integer division
|
/// Floored integer division
|
||||||
*
|
///
|
||||||
* # Examples
|
/// # Examples
|
||||||
*
|
///
|
||||||
* ~~~
|
/// ~~~
|
||||||
* assert!(( 8).div( 3) == 2);
|
/// assert!(( 8).div( 3) == 2);
|
||||||
* assert!(( 8).div(-3) == -3);
|
/// assert!(( 8).div(-3) == -3);
|
||||||
* assert!((-8).div( 3) == -3);
|
/// assert!((-8).div( 3) == -3);
|
||||||
* assert!((-8).div(-3) == 2);
|
/// assert!((-8).div(-3) == 2);
|
||||||
*
|
///
|
||||||
* assert!(( 1).div( 2) == 0);
|
/// assert!(( 1).div( 2) == 0);
|
||||||
* assert!(( 1).div(-2) == -1);
|
/// assert!(( 1).div(-2) == -1);
|
||||||
* assert!((-1).div( 2) == -1);
|
/// assert!((-1).div( 2) == -1);
|
||||||
* assert!((-1).div(-2) == 0);
|
/// assert!((-1).div(-2) == 0);
|
||||||
* ~~~
|
/// ~~~
|
||||||
*/
|
///
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn div(&self, other: &T) -> T {
|
fn div(&self, other: &T) -> T {
|
||||||
// Algorithm from [Daan Leijen. _Division and Modulus for Computer Scientists_,
|
// Algorithm from [Daan Leijen. _Division and Modulus for Computer Scientists_,
|
||||||
|
@ -311,27 +311,27 @@ impl Integer for T {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
///
|
||||||
* Integer modulo, satisfying:
|
/// Integer modulo, satisfying:
|
||||||
*
|
///
|
||||||
* ~~~
|
/// ~~~
|
||||||
* assert!(n.div(d) * d + n.modulo(d) == n)
|
/// assert!(n.div(d) * d + n.modulo(d) == n)
|
||||||
* ~~~
|
/// ~~~
|
||||||
*
|
///
|
||||||
* # Examples
|
/// # Examples
|
||||||
*
|
///
|
||||||
* ~~~
|
/// ~~~
|
||||||
* assert!(( 8).modulo( 3) == 2);
|
/// assert!(( 8).modulo( 3) == 2);
|
||||||
* assert!(( 8).modulo(-3) == -1);
|
/// assert!(( 8).modulo(-3) == -1);
|
||||||
* assert!((-8).modulo( 3) == 1);
|
/// assert!((-8).modulo( 3) == 1);
|
||||||
* assert!((-8).modulo(-3) == -2);
|
/// assert!((-8).modulo(-3) == -2);
|
||||||
*
|
///
|
||||||
* assert!(( 1).modulo( 2) == 1);
|
/// assert!(( 1).modulo( 2) == 1);
|
||||||
* assert!(( 1).modulo(-2) == -1);
|
/// assert!(( 1).modulo(-2) == -1);
|
||||||
* assert!((-1).modulo( 2) == 1);
|
/// assert!((-1).modulo( 2) == 1);
|
||||||
* assert!((-1).modulo(-2) == -1);
|
/// assert!((-1).modulo(-2) == -1);
|
||||||
* ~~~
|
/// ~~~
|
||||||
*/
|
///
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn modulo(&self, other: &T) -> T {
|
fn modulo(&self, other: &T) -> T {
|
||||||
// Algorithm from [Daan Leijen. _Division and Modulus for Computer Scientists_,
|
// Algorithm from [Daan Leijen. _Division and Modulus for Computer Scientists_,
|
||||||
|
@ -361,11 +361,11 @@ impl Integer for T {
|
||||||
(*self / *other, *self % *other)
|
(*self / *other, *self % *other)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
///
|
||||||
* Calculates the Greatest Common Divisor (GCD) of the number and `other`
|
/// Calculates the Greatest Common Divisor (GCD) of the number and `other`
|
||||||
*
|
///
|
||||||
* The result is always positive
|
/// The result is always positive
|
||||||
*/
|
///
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn gcd(&self, other: &T) -> T {
|
fn gcd(&self, other: &T) -> T {
|
||||||
// Use Euclid's algorithm
|
// Use Euclid's algorithm
|
||||||
|
@ -378,9 +378,9 @@ impl Integer for T {
|
||||||
n.abs()
|
n.abs()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
///
|
||||||
* Calculates the Lowest Common Multiple (LCM) of the number and `other`
|
/// Calculates the Lowest Common Multiple (LCM) of the number and `other`
|
||||||
*/
|
///
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn lcm(&self, other: &T) -> T {
|
fn lcm(&self, other: &T) -> T {
|
||||||
((*self * *other) / self.gcd(other)).abs() // should not have to recaluculate abs
|
((*self * *other) / self.gcd(other)).abs() // should not have to recaluculate abs
|
||||||
|
@ -545,13 +545,13 @@ mod tests {
|
||||||
assert!((-1 as T).is_negative());
|
assert!((-1 as T).is_negative());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
///
|
||||||
* Checks that the division rule holds for:
|
/// Checks that the division rule holds for:
|
||||||
*
|
///
|
||||||
* - `n`: numerator (dividend)
|
/// - `n`: numerator (dividend)
|
||||||
* - `d`: denominator (divisor)
|
/// - `d`: denominator (divisor)
|
||||||
* - `qr`: quotient and remainder
|
/// - `qr`: quotient and remainder
|
||||||
*/
|
///
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
fn test_division_rule(nd: (T,T), qr: (T,T)) {
|
fn test_division_rule(nd: (T,T), qr: (T,T)) {
|
||||||
let (n,d) = nd,
|
let (n,d) = nd,
|
||||||
|
|
|
@ -153,7 +153,9 @@ pub trait Real: Signed
|
||||||
fn tanh(&self) -> Self;
|
fn tanh(&self) -> Self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///
|
||||||
/// Methods that are harder to implement and not commonly used.
|
/// Methods that are harder to implement and not commonly used.
|
||||||
|
///
|
||||||
pub trait RealExt: Real {
|
pub trait RealExt: Real {
|
||||||
// FIXME (#5527): usages of `int` should be replaced with an associated
|
// FIXME (#5527): usages of `int` should be replaced with an associated
|
||||||
// integer type once these are implemented
|
// integer type once these are implemented
|
||||||
|
@ -171,24 +173,24 @@ pub trait RealExt: Real {
|
||||||
fn yn(&self, n: int) -> Self;
|
fn yn(&self, n: int) -> Self;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
///
|
||||||
* Cast from one machine scalar to another
|
/// Cast from one machine scalar to another
|
||||||
*
|
///
|
||||||
* # Example
|
/// # Example
|
||||||
*
|
///
|
||||||
* ~~~
|
/// ~~~
|
||||||
* let twenty: f32 = num::cast(0x14);
|
/// let twenty: f32 = num::cast(0x14);
|
||||||
* assert_eq!(twenty, 20f32);
|
/// assert_eq!(twenty, 20f32);
|
||||||
* ~~~
|
/// ~~~
|
||||||
*/
|
///
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn cast<T:NumCast,U:NumCast>(n: T) -> U {
|
pub fn cast<T:NumCast,U:NumCast>(n: T) -> U {
|
||||||
NumCast::from(n)
|
NumCast::from(n)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
///
|
||||||
* An interface for casting between machine scalars
|
/// An interface for casting between machine scalars
|
||||||
*/
|
///
|
||||||
pub trait NumCast {
|
pub trait NumCast {
|
||||||
fn from<T:NumCast>(n: T) -> Self;
|
fn from<T:NumCast>(n: T) -> Self;
|
||||||
|
|
||||||
|
@ -260,21 +262,19 @@ pub trait FromStrRadix {
|
||||||
pub fn from_str_radix(str: &str, radix: uint) -> Option<Self>;
|
pub fn from_str_radix(str: &str, radix: uint) -> Option<Self>;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generic math functions:
|
///
|
||||||
|
/// Calculates a power to a given radix, optimized for uint `pow` and `radix`.
|
||||||
/**
|
///
|
||||||
* Calculates a power to a given radix, optimized for uint `pow` and `radix`.
|
/// Returns `radix^pow` as `T`.
|
||||||
*
|
///
|
||||||
* Returns `radix^pow` as `T`.
|
/// Note:
|
||||||
*
|
/// Also returns `1` for `0^0`, despite that technically being an
|
||||||
* Note:
|
/// undefined number. The reason for this is twofold:
|
||||||
* Also returns `1` for `0^0`, despite that technically being an
|
/// - If code written to use this function cares about that special case, it's
|
||||||
* undefined number. The reason for this is twofold:
|
/// probably going to catch it before making the call.
|
||||||
* - If code written to use this function cares about that special case, it's
|
/// - If code written to use this function doesn't care about it, it's
|
||||||
* probably going to catch it before making the call.
|
/// probably assuming that `x^0` always equals `1`.
|
||||||
* - If code written to use this function doesn't care about it, it's
|
///
|
||||||
* probably assuming that `x^0` always equals `1`.
|
|
||||||
*/
|
|
||||||
pub fn pow_with_uint<T:NumCast+One+Zero+Copy+Quot<T,T>+Mul<T,T>>(
|
pub fn pow_with_uint<T:NumCast+One+Zero+Copy+Quot<T,T>+Mul<T,T>>(
|
||||||
radix: uint, pow: uint) -> T {
|
radix: uint, pow: uint) -> T {
|
||||||
let _0: T = Zero::zero();
|
let _0: T = Zero::zero();
|
||||||
|
|
|
@ -49,10 +49,9 @@ pub fn ge(x: T, y: T) -> bool { x >= y }
|
||||||
pub fn gt(x: T, y: T) -> bool { x > y }
|
pub fn gt(x: T, y: T) -> bool { x > y }
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
/**
|
///
|
||||||
* Iterate over the range [`start`,`start`+`step`..`stop`)
|
/// Iterate over the range [`start`,`start`+`step`..`stop`)
|
||||||
*
|
///
|
||||||
*/
|
|
||||||
pub fn range_step(start: T,
|
pub fn range_step(start: T,
|
||||||
stop: T,
|
stop: T,
|
||||||
step: T_SIGNED,
|
step: T_SIGNED,
|
||||||
|
|
|
@ -31,74 +31,74 @@ pub mod inst {
|
||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
pub static bits: uint = 64;
|
pub static bits: uint = 64;
|
||||||
|
|
||||||
/**
|
///
|
||||||
* Divide two numbers, return the result, rounded up.
|
/// Divide two numbers, return the result, rounded up.
|
||||||
*
|
///
|
||||||
* # Arguments
|
/// # Arguments
|
||||||
*
|
///
|
||||||
* * x - an integer
|
/// * x - an integer
|
||||||
* * y - an integer distinct from 0u
|
/// * y - an integer distinct from 0u
|
||||||
*
|
///
|
||||||
* # Return value
|
/// # Return value
|
||||||
*
|
///
|
||||||
* The smallest integer `q` such that `x/y <= q`.
|
/// The smallest integer `q` such that `x/y <= q`.
|
||||||
*/
|
///
|
||||||
pub fn div_ceil(x: uint, y: uint) -> uint {
|
pub fn div_ceil(x: uint, y: uint) -> uint {
|
||||||
let div = x / y;
|
let div = x / y;
|
||||||
if x % y == 0u { div }
|
if x % y == 0u { div }
|
||||||
else { div + 1u }
|
else { div + 1u }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
///
|
||||||
* Divide two numbers, return the result, rounded to the closest integer.
|
/// Divide two numbers, return the result, rounded to the closest integer.
|
||||||
*
|
///
|
||||||
* # Arguments
|
/// # Arguments
|
||||||
*
|
///
|
||||||
* * x - an integer
|
/// * x - an integer
|
||||||
* * y - an integer distinct from 0u
|
/// * y - an integer distinct from 0u
|
||||||
*
|
///
|
||||||
* # Return value
|
/// # Return value
|
||||||
*
|
///
|
||||||
* The integer `q` closest to `x/y`.
|
/// The integer `q` closest to `x/y`.
|
||||||
*/
|
///
|
||||||
pub fn div_round(x: uint, y: uint) -> uint {
|
pub fn div_round(x: uint, y: uint) -> uint {
|
||||||
let div = x / y;
|
let div = x / y;
|
||||||
if x % y * 2u < y { div }
|
if x % y * 2u < y { div }
|
||||||
else { div + 1u }
|
else { div + 1u }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
///
|
||||||
* Divide two numbers, return the result, rounded down.
|
/// Divide two numbers, return the result, rounded down.
|
||||||
*
|
///
|
||||||
* Note: This is the same function as `div`.
|
/// Note: This is the same function as `div`.
|
||||||
*
|
///
|
||||||
* # Arguments
|
/// # Arguments
|
||||||
*
|
///
|
||||||
* * x - an integer
|
/// * x - an integer
|
||||||
* * y - an integer distinct from 0u
|
/// * y - an integer distinct from 0u
|
||||||
*
|
///
|
||||||
* # Return value
|
/// # Return value
|
||||||
*
|
///
|
||||||
* The smallest integer `q` such that `x/y <= q`. This
|
/// The smallest integer `q` such that `x/y <= q`. This
|
||||||
* is either `x/y` or `x/y + 1`.
|
/// is either `x/y` or `x/y + 1`.
|
||||||
*/
|
///
|
||||||
pub fn div_floor(x: uint, y: uint) -> uint { return x / y; }
|
pub fn div_floor(x: uint, y: uint) -> uint { return x / y; }
|
||||||
|
|
||||||
/**
|
///
|
||||||
* Iterate over the range [`lo`..`hi`), or stop when requested
|
/// Iterate over the range [`lo`..`hi`), or stop when requested
|
||||||
*
|
///
|
||||||
* # Arguments
|
/// # Arguments
|
||||||
*
|
///
|
||||||
* * lo - The integer at which to start the loop (included)
|
/// * lo - The integer at which to start the loop (included)
|
||||||
* * hi - The integer at which to stop the loop (excluded)
|
/// * hi - The integer at which to stop the loop (excluded)
|
||||||
* * it - A block to execute with each consecutive integer of the range.
|
/// * it - A block to execute with each consecutive integer of the range.
|
||||||
* Return `true` to continue, `false` to stop.
|
/// Return `true` to continue, `false` to stop.
|
||||||
*
|
///
|
||||||
* # Return value
|
/// # Return value
|
||||||
*
|
///
|
||||||
* `true` If execution proceeded correctly, `false` if it was interrupted,
|
/// `true` If execution proceeded correctly, `false` if it was interrupted,
|
||||||
* that is if `it` returned `false` at any point.
|
/// that is if `it` returned `false` at any point.
|
||||||
*/
|
///
|
||||||
pub fn iterate(lo: uint, hi: uint, it: &fn(uint) -> bool) -> bool {
|
pub fn iterate(lo: uint, hi: uint, it: &fn(uint) -> bool) -> bool {
|
||||||
let mut i = lo;
|
let mut i = lo;
|
||||||
while i < hi {
|
while i < hi {
|
||||||
|
@ -110,16 +110,16 @@ pub mod inst {
|
||||||
|
|
||||||
impl iter::Times for uint {
|
impl iter::Times for uint {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
/**
|
///
|
||||||
* A convenience form for basic iteration. Given a uint `x`,
|
/// A convenience form for basic iteration. Given a uint `x`,
|
||||||
* `for x.times { ... }` executes the given block x times.
|
/// `for x.times { ... }` executes the given block x times.
|
||||||
*
|
///
|
||||||
* Equivalent to `for uint::range(0, x) |_| { ... }`.
|
/// Equivalent to `for uint::range(0, x) |_| { ... }`.
|
||||||
*
|
///
|
||||||
* Not defined on all integer types to permit unambiguous
|
/// Not defined on all integer types to permit unambiguous
|
||||||
* use with integer literals of inferred integer-type as
|
/// use with integer literals of inferred integer-type as
|
||||||
* the self-value (eg. `for 100.times { ... }`).
|
/// the self-value (eg. `for 100.times { ... }`).
|
||||||
*/
|
///
|
||||||
fn times(&self, it: &fn() -> bool) {
|
fn times(&self, it: &fn() -> bool) {
|
||||||
let mut i = *self;
|
let mut i = *self;
|
||||||
while i > 0 {
|
while i > 0 {
|
||||||
|
|
Loading…
Add table
Reference in a new issue