Skip to content
This repository was archived by the owner on Apr 28, 2025. It is now read-only.

Commit c3ab752

Browse files
authored
Add basic docstrings to some functions (#337)
* Add docstring to Bessel functions * Add docstrings to logarithm functions * Add docstrings to pow functions * Specify argument bit-size of the Bessel functions * Specify argument bit-size for pow functions * Specify argument bit-size for logarithms * Add docstrings to sin, cos, sincos and sinh functions * Add docstrings to sqrt * Add docstrings to tan and tanh functions * Add an inline link to https://en.wikipedia.org/wiki/Bessel_function to the docstrings of all Bessel functions.
1 parent 3f2db72 commit c3ab752

30 files changed

+61
-0
lines changed

src/math/cos.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ use super::{k_cos, k_sin, rem_pio2};
4141
// Accuracy:
4242
// TRIG(x) returns trig(x) nearly rounded
4343
//
44+
45+
/// The cosine of `x` (f64).
46+
///
47+
/// `x` is specified in radians.
4448
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
4549
pub fn cos(x: f64) -> f64 {
4650
let ix = (f64::to_bits(x) >> 32) as u32 & 0x7fffffff;

src/math/cosf.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ const C2_PIO2: f64 = 2. * FRAC_PI_2; /* 0x400921FB, 0x54442D18 */
2424
const C3_PIO2: f64 = 3. * FRAC_PI_2; /* 0x4012D97C, 0x7F3321D2 */
2525
const C4_PIO2: f64 = 4. * FRAC_PI_2; /* 0x401921FB, 0x54442D18 */
2626

27+
/// The cosine of `x` (f32).
28+
///
29+
/// `x` is specified in radians.
2730
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
2831
pub fn cosf(x: f32) -> f32 {
2932
let x64 = x as f64;

src/math/j0.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ const S02: f64 = 1.16926784663337450260e-04; /* 0x3F1EA6D2, 0xDD57DBF4 */
109109
const S03: f64 = 5.13546550207318111446e-07; /* 0x3EA13B54, 0xCE84D5A9 */
110110
const S04: f64 = 1.16614003333790000205e-09; /* 0x3E1408BC, 0xF4745D8F */
111111

112+
/// Zeroth order of the [Bessel function](https://en.wikipedia.org/wiki/Bessel_function) of the first kind (f64).
112113
pub fn j0(mut x: f64) -> f64 {
113114
let z: f64;
114115
let r: f64;
@@ -162,6 +163,7 @@ const V02: f64 = 7.60068627350353253702e-05; /* 0x3F13ECBB, 0xF578C6C1 */
162163
const V03: f64 = 2.59150851840457805467e-07; /* 0x3E91642D, 0x7FF202FD */
163164
const V04: f64 = 4.41110311332675467403e-10; /* 0x3DFE5018, 0x3BD6D9EF */
164165

166+
/// Zeroth order of the [Bessel function](https://en.wikipedia.org/wiki/Bessel_function) of the second kind (f64).
165167
pub fn y0(x: f64) -> f64 {
166168
let z: f64;
167169
let u: f64;

src/math/j0f.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ const S02: f32 = 1.1692678527e-04; /* 0x38f53697 */
6262
const S03: f32 = 5.1354652442e-07; /* 0x3509daa6 */
6363
const S04: f32 = 1.1661400734e-09; /* 0x30a045e8 */
6464

65+
/// Zeroth order of the [Bessel function](https://en.wikipedia.org/wiki/Bessel_function) of the first kind (f32).
6566
pub fn j0f(mut x: f32) -> f32 {
6667
let z: f32;
6768
let r: f32;
@@ -107,6 +108,7 @@ const V02: f32 = 7.6006865129e-05; /* 0x389f65e0 */
107108
const V03: f32 = 2.5915085189e-07; /* 0x348b216c */
108109
const V04: f32 = 4.4111031494e-10; /* 0x2ff280c2 */
109110

111+
/// Zeroth order of the [Bessel function](https://en.wikipedia.org/wiki/Bessel_function) of the second kind (f32).
110112
pub fn y0f(x: f32) -> f32 {
111113
let z: f32;
112114
let u: f32;

src/math/j1.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ const S03: f64 = 1.17718464042623683263e-06; /* 0x3EB3BFF8, 0x333F8498 */
113113
const S04: f64 = 5.04636257076217042715e-09; /* 0x3E35AC88, 0xC97DFF2C */
114114
const S05: f64 = 1.23542274426137913908e-11; /* 0x3DAB2ACF, 0xCFB97ED8 */
115115

116+
/// First order of the [Bessel function](https://en.wikipedia.org/wiki/Bessel_function) of the first kind (f64).
116117
pub fn j1(x: f64) -> f64 {
117118
let mut z: f64;
118119
let r: f64;
@@ -158,6 +159,7 @@ const V0: [f64; 5] = [
158159
1.66559246207992079114e-11, /* 0x3DB25039, 0xDACA772A */
159160
];
160161

162+
/// First order of the [Bessel function](https://en.wikipedia.org/wiki/Bessel_function) of the second kind (f64).
161163
pub fn y1(x: f64) -> f64 {
162164
let z: f64;
163165
let u: f64;

src/math/j1f.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ const S03: f32 = 1.1771846857e-06; /* 0x359dffc2 */
6363
const S04: f32 = 5.0463624390e-09; /* 0x31ad6446 */
6464
const S05: f32 = 1.2354227016e-11; /* 0x2d59567e */
6565

66+
/// First order of the [Bessel function](https://en.wikipedia.org/wiki/Bessel_function) of the first kind (f32).
6667
pub fn j1f(x: f32) -> f32 {
6768
let mut z: f32;
6869
let r: f32;
@@ -107,6 +108,7 @@ const V0: [f32; 5] = [
107108
1.6655924903e-11, /* 0x2d9281cf */
108109
];
109110

111+
/// First order of the [Bessel function](https://en.wikipedia.org/wiki/Bessel_function) of the second kind (f32).
110112
pub fn y1f(x: f32) -> f32 {
111113
let z: f32;
112114
let u: f32;

src/math/jn.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ use super::{cos, fabs, get_high_word, get_low_word, j0, j1, log, sin, sqrt, y0,
3838

3939
const INVSQRTPI: f64 = 5.64189583547756279280e-01; /* 0x3FE20DD7, 0x50429B6D */
4040

41+
/// Integer order of the [Bessel function](https://en.wikipedia.org/wiki/Bessel_function) of the first kind (f64).
4142
pub fn jn(n: i32, mut x: f64) -> f64 {
4243
let mut ix: u32;
4344
let lx: u32;
@@ -247,6 +248,7 @@ pub fn jn(n: i32, mut x: f64) -> f64 {
247248
if sign { -b } else { b }
248249
}
249250

251+
/// Integer order of the [Bessel function](https://en.wikipedia.org/wiki/Bessel_function) of the second kind (f64).
250252
pub fn yn(n: i32, x: f64) -> f64 {
251253
let mut ix: u32;
252254
let lx: u32;

src/math/jnf.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
use super::{fabsf, j0f, j1f, logf, y0f, y1f};
1717

18+
/// Integer order of the [Bessel function](https://en.wikipedia.org/wiki/Bessel_function) of the first kind (f32).
1819
pub fn jnf(n: i32, mut x: f32) -> f32 {
1920
let mut ix: u32;
2021
let mut nm1: i32;
@@ -191,6 +192,7 @@ pub fn jnf(n: i32, mut x: f32) -> f32 {
191192
if sign { -b } else { b }
192193
}
193194

195+
/// Integer order of the [Bessel function](https://en.wikipedia.org/wiki/Bessel_function) of the second kind (f32).
194196
pub fn ynf(n: i32, x: f32) -> f32 {
195197
let mut ix: u32;
196198
let mut ib: u32;

src/math/log.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ const LG5: f64 = 1.818357216161805012e-01; /* 3FC74664 96CB03DE */
7070
const LG6: f64 = 1.531383769920937332e-01; /* 3FC39A09 D078C69F */
7171
const LG7: f64 = 1.479819860511658591e-01; /* 3FC2F112 DF3E5244 */
7272

73+
/// The natural logarithm of `x` (f64).
7374
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
7475
pub fn log(mut x: f64) -> f64 {
7576
let x1p54 = f64::from_bits(0x4350000000000000); // 0x1p54 === 2 ^ 54

src/math/log10.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const LG5: f64 = 1.818357216161805012e-01; /* 3FC74664 96CB03DE */
3131
const LG6: f64 = 1.531383769920937332e-01; /* 3FC39A09 D078C69F */
3232
const LG7: f64 = 1.479819860511658591e-01; /* 3FC2F112 DF3E5244 */
3333

34+
/// The base 10 logarithm of `x` (f64).
3435
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
3536
pub fn log10(mut x: f64) -> f64 {
3637
let x1p54 = f64::from_bits(0x4350000000000000); // 0x1p54 === 2 ^ 54

src/math/log10f.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const LG2: f32 = 0.40000972152; /* 0xccce13.0p-25 */
2525
const LG3: f32 = 0.28498786688; /* 0x91e9ee.0p-25 */
2626
const LG4: f32 = 0.24279078841; /* 0xf89e26.0p-26 */
2727

28+
/// The base 10 logarithm of `x` (f32).
2829
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
2930
pub fn log10f(mut x: f32) -> f32 {
3031
let x1p25f = f32::from_bits(0x4c000000); // 0x1p25f === 2 ^ 25

src/math/log1p.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ const LG5: f64 = 1.818357216161805012e-01; /* 3FC74664 96CB03DE */
6565
const LG6: f64 = 1.531383769920937332e-01; /* 3FC39A09 D078C69F */
6666
const LG7: f64 = 1.479819860511658591e-01; /* 3FC2F112 DF3E5244 */
6767

68+
/// The natural logarithm of 1+`x` (f64).
6869
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
6970
pub fn log1p(x: f64) -> f64 {
7071
let mut ui: u64 = x.to_bits();

src/math/log1pf.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const LG2: f32 = 0.40000972152; /* 0xccce13.0p-25 */
2020
const LG3: f32 = 0.28498786688; /* 0x91e9ee.0p-25 */
2121
const LG4: f32 = 0.24279078841; /* 0xf89e26.0p-26 */
2222

23+
/// The natural logarithm of 1+`x` (f32).
2324
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
2425
pub fn log1pf(x: f32) -> f32 {
2526
let mut ui: u32 = x.to_bits();

src/math/log2.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const LG5: f64 = 1.818357216161805012e-01; /* 3FC74664 96CB03DE */
2929
const LG6: f64 = 1.531383769920937332e-01; /* 3FC39A09 D078C69F */
3030
const LG7: f64 = 1.479819860511658591e-01; /* 3FC2F112 DF3E5244 */
3131

32+
/// The base 2 logarithm of `x` (f64).
3233
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
3334
pub fn log2(mut x: f64) -> f64 {
3435
let x1p54 = f64::from_bits(0x4350000000000000); // 0x1p54 === 2 ^ 54

src/math/log2f.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const LG2: f32 = 0.40000972152; /* 0xccce13.0p-25 */
2323
const LG3: f32 = 0.28498786688; /* 0x91e9ee.0p-25 */
2424
const LG4: f32 = 0.24279078841; /* 0xf89e26.0p-26 */
2525

26+
/// The base 2 logarithm of `x` (f32).
2627
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
2728
pub fn log2f(mut x: f32) -> f32 {
2829
let x1p25f = f32::from_bits(0x4c000000); // 0x1p25f === 2 ^ 25

src/math/logf.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const LG2: f32 = 0.40000972152; /* 0xccce13.0p-25 */
2121
const LG3: f32 = 0.28498786688; /* 0x91e9ee.0p-25 */
2222
const LG4: f32 = 0.24279078841; /* 0xf89e26.0p-26 */
2323

24+
/// The natural logarithm of `x` (f32).
2425
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
2526
pub fn logf(mut x: f32) -> f32 {
2627
let x1p25 = f32::from_bits(0x4c000000); // 0x1p25f === 2 ^ 25

src/math/pow.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ const IVLN2: f64 = 1.44269504088896338700e+00; /* 0x3ff71547_652b82fe =1/ln2 */
8989
const IVLN2_H: f64 = 1.44269502162933349609e+00; /* 0x3ff71547_60000000 =24b 1/ln2*/
9090
const IVLN2_L: f64 = 1.92596299112661746887e-08; /* 0x3e54ae0b_f85ddf44 =1/ln2 tail*/
9191

92+
/// Returns `x` to the power of `y` (f64).
9293
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
9394
pub fn pow(x: f64, y: f64) -> f64 {
9495
let t1: f64;

src/math/powf.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const IVLN2: f32 = 1.4426950216e+00;
4343
const IVLN2_H: f32 = 1.4426879883e+00;
4444
const IVLN2_L: f32 = 7.0526075433e-06;
4545

46+
/// Returns `x` to the power of `y` (f32).
4647
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
4748
pub fn powf(x: f32, y: f32) -> f32 {
4849
let mut z: f32;

src/math/sin.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ use super::{k_cos, k_sin, rem_pio2};
4040
//
4141
// Accuracy:
4242
// TRIG(x) returns trig(x) nearly rounded
43+
44+
/// The sine of `x` (f64).
45+
///
46+
/// `x` is specified in radians.
4347
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
4448
pub fn sin(x: f64) -> f64 {
4549
let x1p120 = f64::from_bits(0x4770000000000000); // 0x1p120f === 2 ^ 120

src/math/sincos.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212

1313
use super::{get_high_word, k_cos, k_sin, rem_pio2};
1414

15+
/// Both the sine and cosine of `x` (f64).
16+
///
17+
/// `x` is specified in radians and the return value is (sin(x), cos(x)).
1518
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
1619
pub fn sincos(x: f64) -> (f64, f64) {
1720
let s: f64;

src/math/sincosf.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ const S2PIO2: f32 = 2.0 * PI_2; /* 0x400921FB, 0x54442D18 */
2323
const S3PIO2: f32 = 3.0 * PI_2; /* 0x4012D97C, 0x7F3321D2 */
2424
const S4PIO2: f32 = 4.0 * PI_2; /* 0x401921FB, 0x54442D18 */
2525

26+
/// Both the sine and cosine of `x` (f32).
27+
///
28+
/// `x` is specified in radians and the return value is (sin(x), cos(x)).
2629
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
2730
pub fn sincosf(x: f32) -> (f32, f32) {
2831
let s: f32;

src/math/sinf.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ const S2_PIO2: f64 = 2. * FRAC_PI_2; /* 0x400921FB, 0x54442D18 */
2424
const S3_PIO2: f64 = 3. * FRAC_PI_2; /* 0x4012D97C, 0x7F3321D2 */
2525
const S4_PIO2: f64 = 4. * FRAC_PI_2; /* 0x401921FB, 0x54442D18 */
2626

27+
/// The sine of `x` (f32).
28+
///
29+
/// `x` is specified in radians.
2730
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
2831
pub fn sinf(x: f32) -> f32 {
2932
let x64 = x as f64;

src/math/sinh.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ use super::{expm1, expo2};
44
// = (exp(x)-1 + (exp(x)-1)/exp(x))/2
55
// = x + x^3/6 + o(x^5)
66
//
7+
8+
/// The hyperbolic sine of `x` (f64).
79
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
810
pub fn sinh(x: f64) -> f64 {
911
// union {double f; uint64_t i;} u = {.f = x};

src/math/sinhf.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use super::{expm1f, k_expo2f};
22

3+
/// The hyperbolic sine of `x` (f32).
34
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
45
pub fn sinhf(x: f32) -> f32 {
56
let mut h = 0.5f32;

src/math/sqrt.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878

7979
use core::f64;
8080

81+
/// The square root of `x` (f64).
8182
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
8283
pub fn sqrt(x: f64) -> f64 {
8384
// On wasm32 we know that LLVM's intrinsic will compile to an optimized

src/math/sqrtf.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* ====================================================
1414
*/
1515

16+
/// The square root of `x` (f32).
1617
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
1718
pub fn sqrtf(x: f32) -> f32 {
1819
// On wasm32 we know that LLVM's intrinsic will compile to an optimized

src/math/tan.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ use super::{k_tan, rem_pio2};
3939
//
4040
// Accuracy:
4141
// TRIG(x) returns trig(x) nearly rounded
42+
43+
/// The tangent of `x` (f64).
44+
///
45+
/// `x` is specified in radians.
4246
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
4347
pub fn tan(x: f64) -> f64 {
4448
let x1p120 = f32::from_bits(0x7b800000); // 0x1p120f === 2 ^ 120

src/math/tanf.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ const T2_PIO2: f64 = 2. * FRAC_PI_2; /* 0x400921FB, 0x54442D18 */
2424
const T3_PIO2: f64 = 3. * FRAC_PI_2; /* 0x4012D97C, 0x7F3321D2 */
2525
const T4_PIO2: f64 = 4. * FRAC_PI_2; /* 0x401921FB, 0x54442D18 */
2626

27+
/// The tangent of `x` (f32).
28+
///
29+
/// `x` is specified in radians.
2730
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
2831
pub fn tanf(x: f32) -> f32 {
2932
let x64 = x as f64;

src/math/tanh.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ use super::expm1;
44
* = (exp(2*x) - 1)/(exp(2*x) - 1 + 2)
55
* = (1 - exp(-2*x))/(exp(-2*x) - 1 + 2)
66
*/
7+
8+
/// The hyperbolic tangent of `x` (f64).
9+
///
10+
/// `x` is specified in radians.
711
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
812
pub fn tanh(mut x: f64) -> f64 {
913
let mut uf: f64 = x;

src/math/tanhf.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
use super::expm1f;
22

3+
/// The hyperbolic tangent of `x` (f32).
4+
///
5+
/// `x` is specified in radians.
36
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
47
pub fn tanhf(mut x: f32) -> f32 {
58
/* x = |x| */

0 commit comments

Comments
 (0)