Skip to content

Commit d19f45a

Browse files
authored
Merge pull request #171 from Schultzer/add-docs
Add missing docs
2 parents efcc86b + 47cb891 commit d19f45a

38 files changed

+185
-2
lines changed

src/math/acos.rs

+5
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ fn r(z: f64) -> f64 {
5555
p / q
5656
}
5757

58+
/// Arccosine (f64)
59+
///
60+
/// Computes the inverse cosine (arc cosine) of the input value.
61+
/// Arguments must be in the range -1 to 1.
62+
/// Returns values in radians, in the range of 0 to pi.
5863
#[inline]
5964
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
6065
pub fn acos(x: f64) -> f64 {

src/math/acosf.rs

+5
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ fn r(z: f32) -> f32 {
2929
p / q
3030
}
3131

32+
/// Arccosine (f32)
33+
///
34+
/// Computes the inverse cosine (arc cosine) of the input value.
35+
/// Arguments must be in the range -1 to 1.
36+
/// Returns values in radians, in the range of 0 to pi.
3237
#[inline]
3338
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
3439
pub fn acosf(x: f32) -> f32 {

src/math/acosh.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ use super::{log, log1p, sqrt};
22

33
const LN2: f64 = 0.693147180559945309417232121458176568; /* 0x3fe62e42, 0xfefa39ef*/
44

5-
/* acosh(x) = log(x + sqrt(x*x-1)) */
5+
/// Inverse hyperbolic cosine (f64)
6+
///
7+
/// Calculates the inverse hyperbolic cosine of `x`.
8+
/// Is defined as `log(x + sqrt(x*x-1))`.
9+
/// `x` must be a number greater than or equal to 1.
610
pub fn acosh(x: f64) -> f64 {
711
let u = x.to_bits();
812
let e = ((u >> 52) as usize) & 0x7ff;

src/math/acoshf.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ use super::{log1pf, logf, sqrtf};
22

33
const LN2: f32 = 0.693147180559945309417232121458176568;
44

5-
/* acosh(x) = log(x + sqrt(x*x-1)) */
5+
/// Inverse hyperbolic cosine (f32)
6+
///
7+
/// Calculates the inverse hyperbolic cosine of `x`.
8+
/// Is defined as `log(x + sqrt(x*x-1))`.
9+
/// `x` must be a number greater than or equal to 1.
610
pub fn acoshf(x: f32) -> f32 {
711
let u = x.to_bits();
812
let a = u & 0x7fffffff;

src/math/asin.rs

+5
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ fn comp_r(z: f64) -> f64 {
6262
p / q
6363
}
6464

65+
/// Arcsine (f64)
66+
///
67+
/// Computes the inverse sine (arc sine) of the argument `x`.
68+
/// Arguments to asin must be in the range -1 to 1.
69+
/// Returns values in radians, in the range of -pi/2 to pi/2.
6570
#[inline]
6671
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
6772
pub fn asin(mut x: f64) -> f64 {

src/math/asinf.rs

+5
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ fn r(z: f32) -> f32 {
3131
p / q
3232
}
3333

34+
/// Arcsine (f32)
35+
///
36+
/// Computes the inverse sine (arc sine) of the argument `x`.
37+
/// Arguments to asin must be in the range -1 to 1.
38+
/// Returns values in radians, in the range of -pi/2 to pi/2.
3439
#[inline]
3540
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
3641
pub fn asinf(mut x: f32) -> f32 {

src/math/asinh.rs

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ use super::{log, log1p, sqrt};
33
const LN2: f64 = 0.693147180559945309417232121458176568; /* 0x3fe62e42, 0xfefa39ef*/
44

55
/* asinh(x) = sign(x)*log(|x|+sqrt(x*x+1)) ~= x - x^3/6 + o(x^5) */
6+
/// Inverse hyperbolic sine (f64)
7+
///
8+
/// Calculates the inverse hyperbolic sine of `x`.
9+
/// Is defined as `sgn(x)*log(|x|+sqrt(x*x+1))`.
610
pub fn asinh(mut x: f64) -> f64 {
711
let mut u = x.to_bits();
812
let e = ((u >> 52) as usize) & 0x7ff;

src/math/asinhf.rs

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ use super::{log1pf, logf, sqrtf};
33
const LN2: f32 = 0.693147180559945309417232121458176568;
44

55
/* asinh(x) = sign(x)*log(|x|+sqrt(x*x+1)) ~= x - x^3/6 + o(x^5) */
6+
/// Inverse hyperbolic sine (f32)
7+
///
8+
/// Calculates the inverse hyperbolic sine of `x`.
9+
/// Is defined as `sgn(x)*log(|x|+sqrt(x*x+1))`.
610
pub fn asinhf(mut x: f32) -> f32 {
711
let u = x.to_bits();
812
let i = u & 0x7fffffff;

src/math/atan.rs

+4
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ const AT: [f64; 11] = [
6060
1.62858201153657823623e-02, /* 0x3F90AD3A, 0xE322DA11 */
6161
];
6262

63+
/// Arctangent (f64)
64+
///
65+
/// Computes the inverse tangent (arc tangent) of the input value.
66+
/// Returns a value in radians, in the range of -pi/2 to pi/2.
6367
#[inline]
6468
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
6569
pub fn atan(x: f64) -> f64 {

src/math/atan2.rs

+5
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ use super::fabs;
4343
const PI: f64 = 3.1415926535897931160E+00; /* 0x400921FB, 0x54442D18 */
4444
const PI_LO: f64 = 1.2246467991473531772E-16; /* 0x3CA1A626, 0x33145C07 */
4545

46+
/// Arctangent of y/x (f64)
47+
///
48+
/// Computes the inverse tangent (arc tangent) of `y/x`.
49+
/// Produces the correct result even for angles near pi/2 or -pi/2 (that is, when `x` is near 0).
50+
/// Returns a value in radians, in the range of -pi to pi.
4651
#[inline]
4752
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
4853
pub fn atan2(y: f64, x: f64) -> f64 {

src/math/atan2f.rs

+5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ use super::fabsf;
1919
const PI: f32 = 3.1415927410e+00; /* 0x40490fdb */
2020
const PI_LO: f32 = -8.7422776573e-08; /* 0xb3bbbd2e */
2121

22+
/// Arctangent of y/x (f32)
23+
///
24+
/// Computes the inverse tangent (arc tangent) of `y/x`.
25+
/// Produces the correct result even for angles near pi/2 or -pi/2 (that is, when `x` is near 0).
26+
/// Returns a value in radians, in the range of -pi to pi.
2227
#[inline]
2328
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
2429
pub fn atan2f(y: f32, x: f32) -> f32 {

src/math/atanf.rs

+4
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ const A_T: [f32; 5] = [
3737
6.1687607318e-02,
3838
];
3939

40+
/// Arctangent (f32)
41+
///
42+
/// Computes the inverse tangent (arc tangent) of the input value.
43+
/// Returns a value in radians, in the range of -pi/2 to pi/2.
4044
#[inline]
4145
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
4246
pub fn atanf(mut x: f32) -> f32 {

src/math/atanh.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
use super::log1p;
22

33
/* atanh(x) = log((1+x)/(1-x))/2 = log1p(2x/(1-x))/2 ~= x + x^3/3 + o(x^5) */
4+
/// Inverse hyperbolic tangent (f64)
5+
///
6+
/// Calculates the inverse hyperbolic tangent of `x`.
7+
/// Is defined as `log((1+x)/(1-x))/2 = log1p(2x/(1-x))/2`.
48
pub fn atanh(x: f64) -> f64 {
59
let u = x.to_bits();
610
let e = ((u >> 52) as usize) & 0x7ff;

src/math/atanhf.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
use super::log1pf;
22

33
/* atanh(x) = log((1+x)/(1-x))/2 = log1p(2x/(1-x))/2 ~= x + x^3/3 + o(x^5) */
4+
/// Inverse hyperbolic tangent (f32)
5+
///
6+
/// Calculates the inverse hyperbolic tangent of `x`.
7+
/// Is defined as `log((1+x)/(1-x))/2 = log1p(2x/(1-x))/2`.
48
pub fn atanhf(mut x: f32) -> f32 {
59
let mut u = x.to_bits();
610
let sign = (u >> 31) != 0;

src/math/cbrt.rs

+3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ const P2: f64 = 1.621429720105354466140; /* 0x3ff9f160, 0x4a49d6c2 */
2727
const P3: f64 = -0.758397934778766047437; /* 0xbfe844cb, 0xbee751d9 */
2828
const P4: f64 = 0.145996192886612446982; /* 0x3fc2b000, 0xd4e4edd7 */
2929

30+
// Cube root (f64)
31+
///
32+
/// Computes the cube root of the argument.
3033
#[inline]
3134
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
3235
pub fn cbrt(x: f64) -> f64 {

src/math/cbrtf.rs

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ use core::f32;
2222
const B1: u32 = 709958130; /* B1 = (127-127.0/3-0.03306235651)*2**23 */
2323
const B2: u32 = 642849266; /* B2 = (127-127.0/3-24/3-0.03306235651)*2**23 */
2424

25+
/// Cube root (f32)
26+
///
27+
/// Computes the cube root of the argument.
2528
#[inline]
2629
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
2730
pub fn cbrtf(x: f32) -> f32 {

src/math/ceil.rs

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ use core::f64;
22

33
const TOINT: f64 = 1. / f64::EPSILON;
44

5+
/// Ceil (f64)
6+
///
7+
/// Finds the nearest integer greater than or equal to `x`.
58
#[inline]
69
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
710
pub fn ceil(x: f64) -> f64 {

src/math/ceilf.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
use core::f32;
22

3+
/// Ceil (f32)
4+
///
5+
/// Finds the nearest integer greater than or equal to `x`.
36
#[inline]
47
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
58
pub fn ceilf(x: f32) -> f32 {

src/math/copysign.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/// Sign of Y, magnitude of X (f64)
2+
///
3+
/// Constructs a number with the magnitude (absolute value) of its
4+
/// first argument, `x`, and the sign of its second argument, `y`.
15
pub fn copysign(x: f64, y: f64) -> f64 {
26
let mut ux = x.to_bits();
37
let uy = y.to_bits();

src/math/copysignf.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/// Sign of Y, magnitude of X (f32)
2+
///
3+
/// Constructs a number with the magnitude (absolute value) of its
4+
/// first argument, `x`, and the sign of its second argument, `y`.
15
pub fn copysignf(x: f32, y: f32) -> f32 {
26
let mut ux = x.to_bits();
37
let uy = y.to_bits();

src/math/cosh.rs

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ use super::exp;
22
use super::expm1;
33
use super::k_expo2;
44

5+
/// Hyperbolic cosine (f64)
6+
///
7+
/// Computes the hyperbolic cosine of the argument x.
8+
/// Is defined as `(exp(x) + exp(-x))/2`
9+
/// Angles are specified in radians.
510
#[inline]
611
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
712
pub fn cosh(mut x: f64) -> f64 {

src/math/coshf.rs

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ use super::expf;
22
use super::expm1f;
33
use super::k_expo2f;
44

5+
/// Hyperbolic cosine (f64)
6+
///
7+
/// Computes the hyperbolic cosine of the argument x.
8+
/// Is defined as `(exp(x) + exp(-x))/2`
9+
/// Angles are specified in radians.
510
#[inline]
611
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
712
pub fn coshf(mut x: f32) -> f32 {

src/math/erf.rs

+11
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,11 @@ fn erfc2(ix: u32, mut x: f64) -> f64 {
214214
exp(-z * z - 0.5625) * exp((z - x) * (z + x) + r / big_s) / x
215215
}
216216

217+
/// Error function (f64)
218+
///
219+
/// Calculates an approximation to the “error function”, which estimates
220+
/// the probability that an observation will fall within x standard
221+
/// deviations of the mean (assuming a normal distribution).
217222
pub fn erf(x: f64) -> f64 {
218223
let r: f64;
219224
let s: f64;
@@ -257,6 +262,12 @@ pub fn erf(x: f64) -> f64 {
257262
}
258263
}
259264

265+
/// Error function (f64)
266+
///
267+
/// Calculates the complementary probability.
268+
/// Is `1 - erf(x)`. Is computed directly, so that you can use it to avoid
269+
/// the loss of precision that would result from subtracting
270+
/// large probabilities (on large `x`) from 1.
260271
pub fn erfc(x: f64) -> f64 {
261272
let r: f64;
262273
let s: f64;

src/math/erff.rs

+11
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,11 @@ fn erfc2(mut ix: u32, mut x: f32) -> f32 {
125125
expf(-z * z - 0.5625) * expf((z - x) * (z + x) + r / big_s) / x
126126
}
127127

128+
/// Error function (f32)
129+
///
130+
/// Calculates an approximation to the “error function”, which estimates
131+
/// the probability that an observation will fall within x standard
132+
/// deviations of the mean (assuming a normal distribution).
128133
pub fn erff(x: f32) -> f32 {
129134
let r: f32;
130135
let s: f32;
@@ -168,6 +173,12 @@ pub fn erff(x: f32) -> f32 {
168173
}
169174
}
170175

176+
/// Error function (f32)
177+
///
178+
/// Calculates the complementary probability.
179+
/// Is `1 - erf(x)`. Is computed directly, so that you can use it to avoid
180+
/// the loss of precision that would result from subtracting
181+
/// large probabilities (on large `x`) from 1.
171182
pub fn erfcf(x: f32) -> f32 {
172183
let r: f32;
173184
let s: f32;

src/math/exp.rs

+4
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ const P3: f64 = 6.61375632143793436117e-05; /* 0x3F11566A, 0xAF25DE2C */
7777
const P4: f64 = -1.65339022054652515390e-06; /* 0xBEBBBD41, 0xC5D26BF1 */
7878
const P5: f64 = 4.13813679705723846039e-08; /* 0x3E663769, 0x72BEA4D0 */
7979

80+
/// Exponential, base *e* (f64)
81+
///
82+
/// Calculate the exponential of `x`, that is, *e* raised to the power `x`
83+
/// (where *e* is the base of the natural system of logarithms, approximately 2.71828).
8084
#[inline]
8185
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
8286
pub fn exp(mut x: f64) -> f64 {

src/math/exp2.rs

+4
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,10 @@ static TBL: [u64; TBLSIZE * 2] = [
318318
//
319319
// Gal, S. and Bachelis, B. An Accurate Elementary Mathematical Library
320320
// for the IEEE Floating Point Standard. TOMS 17(1), 26-46 (1991).
321+
322+
/// Exponential, base 2 (f64)
323+
///
324+
/// Calculate `2^x`, that is, 2 raised to the power `x`.
321325
#[inline]
322326
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
323327
pub fn exp2(mut x: f64) -> f64 {

src/math/exp2f.rs

+4
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ static EXP2FT: [u64; TBLSIZE] = [
6969
//
7070
// Tang, P. Table-driven Implementation of the Exponential Function
7171
// in IEEE Floating-Point Arithmetic. TOMS 15(2), 144-157 (1989).
72+
73+
/// Exponential, base 2 (f32)
74+
///
75+
/// Calculate `2^x`, that is, 2 raised to the power `x`.
7276
#[inline]
7377
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
7478
pub fn exp2f(mut x: f32) -> f32 {

src/math/expf.rs

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ const INV_LN2: f32 = 1.4426950216e+00; /* 0x3fb8aa3b */
2626
const P1: f32 = 1.6666625440e-1; /* 0xaaaa8f.0p-26 */
2727
const P2: f32 = -2.7667332906e-3; /* -0xb55215.0p-32 */
2828

29+
/// Exponential, base *e* (f32)
30+
///
31+
/// Calculate the exponential of `x`, that is, *e* raised to the power `x`
32+
/// (where *e* is the base of the natural system of logarithms, approximately 2.71828).
2933
#[inline]
3034
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
3135
pub fn expf(mut x: f32) -> f32 {

src/math/expm1.rs

+7
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ const Q3: f64 = -7.93650757867487942473e-05; /* BF14CE19 9EAADBB7 */
2323
const Q4: f64 = 4.00821782732936239552e-06; /* 3ED0CFCA 86E65239 */
2424
const Q5: f64 = -2.01099218183624371326e-07; /* BE8AFDB7 6E09C32D */
2525

26+
/// Exponential, base *e*, of x-1 (f64)
27+
///
28+
/// Calculates the exponential of `x` and subtract 1, that is, *e* raised
29+
/// to the power `x` minus 1 (where *e* is the base of the natural
30+
/// system of logarithms, approximately 2.71828).
31+
/// The result is accurate even for small values of `x`,
32+
/// where using `exp(x)-1` would lose many significant digits.
2633
#[inline]
2734
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
2835
pub fn expm1(mut x: f64) -> f64 {

src/math/expm1f.rs

+7
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ const INV_LN2: f32 = 1.4426950216e+00; /* 0x3fb8aa3b */
2525
const Q1: f32 = -3.3333212137e-2; /* -0x888868.0p-28 */
2626
const Q2: f32 = 1.5807170421e-3; /* 0xcf3010.0p-33 */
2727

28+
/// Exponential, base *e*, of x-1 (f32)
29+
///
30+
/// Calculates the exponential of `x` and subtract 1, that is, *e* raised
31+
/// to the power `x` minus 1 (where *e* is the base of the natural
32+
/// system of logarithms, approximately 2.71828).
33+
/// The result is accurate even for small values of `x`,
34+
/// where using `exp(x)-1` would lose many significant digits.
2835
#[inline]
2936
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
3037
pub fn expm1f(mut x: f32) -> f32 {

src/math/fabs.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
use core::u64;
22

3+
/// Absolute value (magnitude) (f64)
4+
/// Calculates the absolute value (magnitude) of the argument `x`,
5+
/// by direct manipulation of the bit representation of `x`.
36
#[inline]
47
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
58
pub fn fabs(x: f64) -> f64 {

src/math/fabsf.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/// Absolute value (magnitude) (f32)
2+
/// Calculates the absolute value (magnitude) of the argument `x`,
3+
/// by direct manipulation of the bit representation of `x`.
14
#[inline]
25
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
36
pub fn fabsf(x: f32) -> f32 {

src/math/fdim.rs

+8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
use core::f64;
22

3+
/// Positive difference (f64)
4+
///
5+
/// Determines the positive difference between arguments, returning:
6+
/// * x - y if x > y, or
7+
/// * +0 if x <= y, or
8+
/// * NAN if either argument is NAN.
9+
///
10+
/// A range error may occur.
311
#[inline]
412
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
513
pub fn fdim(x: f64, y: f64) -> f64 {

0 commit comments

Comments
 (0)