aboutsummaryrefslogtreecommitdiff
path: root/ctr-std/src/f64.rs
diff options
context:
space:
mode:
Diffstat (limited to 'ctr-std/src/f64.rs')
-rw-r--r--ctr-std/src/f64.rs98
1 files changed, 83 insertions, 15 deletions
diff --git a/ctr-std/src/f64.rs b/ctr-std/src/f64.rs
index a7e63f5..7950d43 100644
--- a/ctr-std/src/f64.rs
+++ b/ctr-std/src/f64.rs
@@ -11,22 +11,16 @@
//! This module provides constants which are specific to the implementation
//! of the `f64` floating point data type.
//!
-//! Mathematically significant numbers are provided in the `consts` sub-module.
-//!
//! *[See also the `f64` primitive type](../../std/primitive.f64.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::f64::{MIN, MIN_POSITIVE, MAX};
pub use core::f64::consts;
#[cfg(not(test))]
-#[cfg_attr(stage0, lang = "f64")]
-#[cfg_attr(not(stage0), lang = "f64_runtime")]
+#[lang = "f64_runtime"]
impl f64 {
- #[cfg(stage0)]
- f64_core_methods!();
-
/// Returns the largest integer less than or equal to a number.
///
+ /// # Examples
+ ///
/// ```
/// let f = 3.99_f64;
/// let g = 3.0_f64;
@@ -64,6 +56,8 @@ impl f64 {
/// Returns the smallest integer greater than or equal to a number.
///
+ /// # Examples
+ ///
/// ```
/// let f = 3.01_f64;
/// let g = 4.0_f64;
@@ -80,6 +74,8 @@ impl f64 {
/// Returns the nearest integer to a number. Round half-way cases away from
/// `0.0`.
///
+ /// # Examples
+ ///
/// ```
/// let f = 3.3_f64;
/// let g = -3.3_f64;
@@ -95,6 +91,8 @@ impl f64 {
/// Returns the integer part of a number.
///
+ /// # Examples
+ ///
/// ```
/// let f = 3.3_f64;
/// let g = -3.7_f64;
@@ -110,6 +108,8 @@ impl f64 {
/// Returns the fractional part of a number.
///
+ /// # Examples
+ ///
/// ```
/// let x = 3.5_f64;
/// let y = -3.5_f64;
@@ -126,6 +126,8 @@ impl f64 {
/// Computes the absolute value of `self`. Returns `NAN` if the
/// number is `NAN`.
///
+ /// # Examples
+ ///
/// ```
/// use std::f64;
///
@@ -152,6 +154,8 @@ impl f64 {
/// - `-1.0` if the number is negative, `-0.0` or `NEG_INFINITY`
/// - `NAN` if the number is `NAN`
///
+ /// # Examples
+ ///
/// ```
/// use std::f64;
///
@@ -173,8 +177,12 @@ impl f64 {
}
/// 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
///
/// ```
/// let m = 10.0_f64;
@@ -199,6 +207,8 @@ impl f64 {
/// In other words, the result is `self / rhs` rounded to the integer `n`
/// such that `self >= n * rhs`.
///
+ /// # Examples
+ ///
/// ```
/// #![feature(euclidean_division)]
/// let a: f64 = 7.0;
@@ -222,6 +232,8 @@ impl f64 {
///
/// In particular, the result `n` satisfies `0 <= n < rhs.abs()`.
///
+ /// # Examples
+ ///
/// ```
/// #![feature(euclidean_division)]
/// let a: f64 = 7.0;
@@ -246,6 +258,8 @@ impl f64 {
///
/// Using this function is generally faster than using `powf`
///
+ /// # Examples
+ ///
/// ```
/// let x = 2.0_f64;
/// let abs_difference = (x.powi(2) - x*x).abs();
@@ -260,6 +274,8 @@ impl f64 {
/// Raises a number to a floating point power.
///
+ /// # Examples
+ ///
/// ```
/// let x = 2.0_f64;
/// let abs_difference = (x.powf(2.0) - x*x).abs();
@@ -276,6 +292,8 @@ impl f64 {
///
/// Returns NaN if `self` is a negative number.
///
+ /// # Examples
+ ///
/// ```
/// let positive = 4.0_f64;
/// let negative = -4.0_f64;
@@ -297,6 +315,8 @@ impl f64 {
/// Returns `e^(self)`, (the exponential function).
///
+ /// # Examples
+ ///
/// ```
/// let one = 1.0_f64;
/// // e^1
@@ -315,6 +335,8 @@ impl f64 {
/// Returns `2^(self)`.
///
+ /// # Examples
+ ///
/// ```
/// let f = 2.0_f64;
///
@@ -331,6 +353,8 @@ impl f64 {
/// Returns the natural logarithm of the number.
///
+ /// # Examples
+ ///
/// ```
/// let one = 1.0_f64;
/// // e^1
@@ -353,6 +377,8 @@ impl f64 {
/// `self.log2()` can produce more accurate results for base 2, and
/// `self.log10()` can produce more accurate results for base 10.
///
+ /// # Examples
+ ///
/// ```
/// let five = 5.0_f64;
///
@@ -367,6 +393,8 @@ impl f64 {
/// Returns the base 2 logarithm of the number.
///
+ /// # Examples
+ ///
/// ```
/// let two = 2.0_f64;
///
@@ -388,6 +416,8 @@ impl f64 {
/// Returns the base 10 logarithm of the number.
///
+ /// # Examples
+ ///
/// ```
/// let ten = 10.0_f64;
///
@@ -407,6 +437,8 @@ impl f64 {
/// * If `self <= other`: `0:0`
/// * Else: `self - other`
///
+ /// # Examples
+ ///
/// ```
/// let x = 3.0_f64;
/// let y = -3.0_f64;
@@ -432,6 +464,8 @@ impl f64 {
/// Takes the cubic root of a number.
///
+ /// # Examples
+ ///
/// ```
/// let x = 8.0_f64;
///
@@ -449,6 +483,8 @@ impl f64 {
/// Calculates the length of the hypotenuse of a right-angle triangle given
/// legs of length `x` and `y`.
///
+ /// # Examples
+ ///
/// ```
/// let x = 2.0_f64;
/// let y = 3.0_f64;
@@ -466,6 +502,8 @@ impl f64 {
/// Computes the sine of a number (in radians).
///
+ /// # Examples
+ ///
/// ```
/// use std::f64;
///
@@ -483,6 +521,8 @@ impl f64 {
/// Computes the cosine of a number (in radians).
///
+ /// # Examples
+ ///
/// ```
/// use std::f64;
///
@@ -500,6 +540,8 @@ impl f64 {
/// Computes the tangent of a number (in radians).
///
+ /// # Examples
+ ///
/// ```
/// use std::f64;
///
@@ -518,6 +560,8 @@ impl f64 {
/// the range [-pi/2, pi/2] or NaN if the number is outside the range
/// [-1, 1].
///
+ /// # Examples
+ ///
/// ```
/// use std::f64;
///
@@ -538,6 +582,8 @@ impl f64 {
/// the range [0, pi] or NaN if the number is outside the range
/// [-1, 1].
///
+ /// # Examples
+ ///
/// ```
/// use std::f64;
///
@@ -557,6 +603,8 @@ impl f64 {
/// Computes the arctangent of a number. Return value is in radians in the
/// range [-pi/2, pi/2];
///
+ /// # Examples
+ ///
/// ```
/// let f = 1.0_f64;
///
@@ -578,6 +626,8 @@ impl f64 {
/// * `y >= 0`: `arctan(y/x) + pi` -> `(pi/2, pi]`
/// * `y < 0`: `arctan(y/x) - pi` -> `(-pi, -pi/2)`
///
+ /// # Examples
+ ///
/// ```
/// use std::f64;
///
@@ -607,6 +657,8 @@ impl f64 {
/// Simultaneously computes the sine and cosine of the number, `x`. Returns
/// `(sin(x), cos(x))`.
///
+ /// # Examples
+ ///
/// ```
/// use std::f64;
///
@@ -628,6 +680,8 @@ impl f64 {
/// Returns `e^(self) - 1` in a way that is accurate even if the
/// number is close to zero.
///
+ /// # Examples
+ ///
/// ```
/// let x = 7.0_f64;
///
@@ -645,6 +699,8 @@ impl f64 {
/// Returns `ln(1+n)` (natural logarithm) more accurately than if
/// the operations were performed separately.
///
+ /// # Examples
+ ///
/// ```
/// use std::f64;
///
@@ -663,6 +719,8 @@ impl f64 {
/// Hyperbolic sine function.
///
+ /// # Examples
+ ///
/// ```
/// use std::f64;
///
@@ -684,6 +742,8 @@ impl f64 {
/// Hyperbolic cosine function.
///
+ /// # Examples
+ ///
/// ```
/// use std::f64;
///
@@ -705,6 +765,8 @@ impl f64 {
/// Hyperbolic tangent function.
///
+ /// # Examples
+ ///
/// ```
/// use std::f64;
///
@@ -726,6 +788,8 @@ impl f64 {
/// Inverse hyperbolic sine function.
///
+ /// # Examples
+ ///
/// ```
/// let x = 1.0_f64;
/// let f = x.sinh().asinh();
@@ -746,6 +810,8 @@ impl f64 {
/// Inverse hyperbolic cosine function.
///
+ /// # Examples
+ ///
/// ```
/// let x = 1.0_f64;
/// let f = x.cosh().acosh();
@@ -765,6 +831,8 @@ impl f64 {
/// Inverse hyperbolic tangent function.
///
+ /// # Examples
+ ///
/// ```
/// use std::f64;
///