aboutsummaryrefslogtreecommitdiff
path: root/ctr-std/src/f32.rs
diff options
context:
space:
mode:
Diffstat (limited to 'ctr-std/src/f32.rs')
-rw-r--r--ctr-std/src/f32.rs98
1 files changed, 83 insertions, 15 deletions
diff --git a/ctr-std/src/f32.rs b/ctr-std/src/f32.rs
index 26644c7..ae30321 100644
--- a/ctr-std/src/f32.rs
+++ b/ctr-std/src/f32.rs
@@ -11,22 +11,16 @@
//! This module provides constants which are specific to the implementation
//! of the `f32` floating point data type.
//!
-//! Mathematically significant numbers are provided in the `consts` sub-module.
-//!
//! *[See also the `f32` primitive type](../../std/primitive.f32.html).*
+//!
+//! Mathematically significant numbers are provided in the `consts` sub-module.
#![stable(feature = "rust1", since = "1.0.0")]
#![allow(missing_docs)]
#[cfg(not(test))]
-#[cfg(stage0)]
-use core::num::Float;
-#[cfg(not(test))]
use intrinsics;
#[cfg(not(test))]
-#[cfg(stage0)]
-use num::FpCategory;
-#[cfg(not(test))]
use sys::cmath;
#[stable(feature = "rust1", since = "1.0.0")]
@@ -41,14 +35,12 @@ pub use core::f32::{MIN, MIN_POSITIVE, MAX};
pub use core::f32::consts;
#[cfg(not(test))]
-#[cfg_attr(stage0, lang = "f32")]
-#[cfg_attr(not(stage0), lang = "f32_runtime")]
+#[lang = "f32_runtime"]
impl f32 {
- #[cfg(stage0)]
- f32_core_methods!();
-
/// Returns the largest integer less than or equal to a number.
///
+ /// # Examples
+ ///
/// ```
/// let f = 3.99_f32;
/// let g = 3.0_f32;
@@ -80,6 +72,8 @@ impl f32 {
/// Returns the smallest integer greater than or equal to a number.
///
+ /// # Examples
+ ///
/// ```
/// let f = 3.01_f32;
/// let g = 4.0_f32;
@@ -100,6 +94,8 @@ impl f32 {
/// Returns the nearest integer to a number. Round half-way cases away from
/// `0.0`.
///
+ /// # Examples
+ ///
/// ```
/// let f = 3.3_f32;
/// let g = -3.3_f32;
@@ -115,6 +111,8 @@ impl f32 {
/// Returns the integer part of a number.
///
+ /// # Examples
+ ///
/// ```
/// let f = 3.3_f32;
/// let g = -3.7_f32;
@@ -130,6 +128,8 @@ impl f32 {
/// Returns the fractional part of a number.
///
+ /// # Examples
+ ///
/// ```
/// use std::f32;
///
@@ -148,6 +148,8 @@ impl f32 {
/// Computes the absolute value of `self`. Returns `NAN` if the
/// number is `NAN`.
///
+ /// # Examples
+ ///
/// ```
/// use std::f32;
///
@@ -174,6 +176,8 @@ impl f32 {
/// - `-1.0` if the number is negative, `-0.0` or `NEG_INFINITY`
/// - `NAN` if the number is `NAN`
///
+ /// # Examples
+ ///
/// ```
/// use std::f32;
///
@@ -195,8 +199,12 @@ impl f32 {
}
/// Fused multiply-add. Computes `(self * a) + b` with only one rounding
- /// error. This produces a more accurate result with better performance than
- /// a separate multiplication operation followed by an add.
+ /// error, yielding a more accurate result than an unfused multiply-add.
+ ///
+ /// Using `mul_add` can be more performant than an unfused multiply-add if
+ /// the target architecture has a dedicated `fma` CPU instruction.
+ ///
+ /// # Examples
///
/// ```
/// use std::f32;
@@ -223,6 +231,8 @@ impl f32 {
/// In other words, the result is `self / rhs` rounded to the integer `n`
/// such that `self >= n * rhs`.
///
+ /// # Examples
+ ///
/// ```
/// #![feature(euclidean_division)]
/// let a: f32 = 7.0;
@@ -246,6 +256,8 @@ impl f32 {
///
/// In particular, the result `n` satisfies `0 <= n < rhs.abs()`.
///
+ /// # Examples
+ ///
/// ```
/// #![feature(euclidean_division)]
/// let a: f32 = 7.0;
@@ -271,6 +283,8 @@ impl f32 {
///
/// Using this function is generally faster than using `powf`
///
+ /// # Examples
+ ///
/// ```
/// use std::f32;
///
@@ -287,6 +301,8 @@ impl f32 {
/// Raises a number to a floating point power.
///
+ /// # Examples
+ ///
/// ```
/// use std::f32;
///
@@ -309,6 +325,8 @@ impl f32 {
///
/// Returns NaN if `self` is a negative number.
///
+ /// # Examples
+ ///
/// ```
/// use std::f32;
///
@@ -332,6 +350,8 @@ impl f32 {
/// Returns `e^(self)`, (the exponential function).
///
+ /// # Examples
+ ///
/// ```
/// use std::f32;
///
@@ -356,6 +376,8 @@ impl f32 {
/// Returns `2^(self)`.
///
+ /// # Examples
+ ///
/// ```
/// use std::f32;
///
@@ -374,6 +396,8 @@ impl f32 {
/// Returns the natural logarithm of the number.
///
+ /// # Examples
+ ///
/// ```
/// use std::f32;
///
@@ -402,6 +426,8 @@ impl f32 {
/// `self.log2()` can produce more accurate results for base 2, and
/// `self.log10()` can produce more accurate results for base 10.
///
+ /// # Examples
+ ///
/// ```
/// use std::f32;
///
@@ -418,6 +444,8 @@ impl f32 {
/// Returns the base 2 logarithm of the number.
///
+ /// # Examples
+ ///
/// ```
/// use std::f32;
///
@@ -439,6 +467,8 @@ impl f32 {
/// Returns the base 10 logarithm of the number.
///
+ /// # Examples
+ ///
/// ```
/// use std::f32;
///
@@ -464,6 +494,8 @@ impl f32 {
/// * If `self <= other`: `0:0`
/// * Else: `self - other`
///
+ /// # Examples
+ ///
/// ```
/// use std::f32;
///
@@ -491,6 +523,8 @@ impl f32 {
/// Takes the cubic root of a number.
///
+ /// # Examples
+ ///
/// ```
/// use std::f32;
///
@@ -510,6 +544,8 @@ impl f32 {
/// Calculates the length of the hypotenuse of a right-angle triangle given
/// legs of length `x` and `y`.
///
+ /// # Examples
+ ///
/// ```
/// use std::f32;
///
@@ -529,6 +565,8 @@ impl f32 {
/// Computes the sine of a number (in radians).
///
+ /// # Examples
+ ///
/// ```
/// use std::f32;
///
@@ -550,6 +588,8 @@ impl f32 {
/// Computes the cosine of a number (in radians).
///
+ /// # Examples
+ ///
/// ```
/// use std::f32;
///
@@ -571,6 +611,8 @@ impl f32 {
/// Computes the tangent of a number (in radians).
///
+ /// # Examples
+ ///
/// ```
/// use std::f32;
///
@@ -589,6 +631,8 @@ impl f32 {
/// the range [-pi/2, pi/2] or NaN if the number is outside the range
/// [-1, 1].
///
+ /// # Examples
+ ///
/// ```
/// use std::f32;
///
@@ -609,6 +653,8 @@ impl f32 {
/// the range [0, pi] or NaN if the number is outside the range
/// [-1, 1].
///
+ /// # Examples
+ ///
/// ```
/// use std::f32;
///
@@ -628,6 +674,8 @@ impl f32 {
/// Computes the arctangent of a number. Return value is in radians in the
/// range [-pi/2, pi/2];
///
+ /// # Examples
+ ///
/// ```
/// use std::f32;
///
@@ -651,6 +699,8 @@ impl f32 {
/// * `y >= 0`: `arctan(y/x) + pi` -> `(pi/2, pi]`
/// * `y < 0`: `arctan(y/x) - pi` -> `(-pi, -pi/2)`
///
+ /// # Examples
+ ///
/// ```
/// use std::f32;
///
@@ -680,6 +730,8 @@ impl f32 {
/// Simultaneously computes the sine and cosine of the number, `x`. Returns
/// `(sin(x), cos(x))`.
///
+ /// # Examples
+ ///
/// ```
/// use std::f32;
///
@@ -701,6 +753,8 @@ impl f32 {
/// Returns `e^(self) - 1` in a way that is accurate even if the
/// number is close to zero.
///
+ /// # Examples
+ ///
/// ```
/// use std::f32;
///
@@ -720,6 +774,8 @@ impl f32 {
/// Returns `ln(1+n)` (natural logarithm) more accurately than if
/// the operations were performed separately.
///
+ /// # Examples
+ ///
/// ```
/// use std::f32;
///
@@ -738,6 +794,8 @@ impl f32 {
/// Hyperbolic sine function.
///
+ /// # Examples
+ ///
/// ```
/// use std::f32;
///
@@ -759,6 +817,8 @@ impl f32 {
/// Hyperbolic cosine function.
///
+ /// # Examples
+ ///
/// ```
/// use std::f32;
///
@@ -780,6 +840,8 @@ impl f32 {
/// Hyperbolic tangent function.
///
+ /// # Examples
+ ///
/// ```
/// use std::f32;
///
@@ -801,6 +863,8 @@ impl f32 {
/// Inverse hyperbolic sine function.
///
+ /// # Examples
+ ///
/// ```
/// use std::f32;
///
@@ -823,6 +887,8 @@ impl f32 {
/// Inverse hyperbolic cosine function.
///
+ /// # Examples
+ ///
/// ```
/// use std::f32;
///
@@ -844,6 +910,8 @@ impl f32 {
/// Inverse hyperbolic tangent function.
///
+ /// # Examples
+ ///
/// ```
/// use std::f32;
///