mathlab/functions/num/mod.rs
1use crate::constants::{E, INF_F32, INF_F64, NINF_F32, NINF_F64, PI};
2
3/// ### abs(x)
4///
5/// Native Function
6///
7/// The `abs` function returns the absolute value of a number.
8///
9/// ### Examples
10/// ```rust
11/// use mathlab::math::abs;
12/// assert_eq!(abs(0.0), 0.0);
13/// assert_eq!(abs(-1.0), 1.0);
14/// assert_eq!(abs(3.33), 3.33);
15/// assert_eq!(abs(-3.33), 3.33);
16/// ```
17/// <small>End Fun Doc</small>
18pub fn abs(x: f64) -> f64 {
19 if x < 0.0 {
20 -x
21 } else {
22 x
23 }
24}
25
26/// ### sign(x)
27///
28/// Native Function
29///
30/// The `sign` function returns only one of three possible values: `−1`, `0` or `1`.
31/// ### Examples
32/// ```rust
33/// use mathlab::math::sign;
34/// assert_eq!(sign(-9.0), -1.0);
35/// assert_eq!(sign(9.0), 1.0);
36/// assert_eq!(sign(--9.5), 1.0);
37/// assert_eq!(sign(6.0 - 15.0), -1.0);
38/// assert_eq!(sign(0.0), 0.0);
39/// assert_eq!(sign(0.0 / 0.0), 0.0);
40/// ```
41/// <small>End Fun Doc</small>
42pub fn sign(x: f64) -> f64 {
43 if x > 0.0 {
44 1.0
45 } else if x < 0.0 {
46 -1.0
47 } else {
48 0.0
49 }
50}
51
52/// ### floor(x)
53///
54/// Rounding Function
55///
56/// The `floor` function returns the largest integer less than or equal to a given floating-point number.
57///
58/// ### Examples
59/// ```rust
60/// use mathlab::math::floor;
61/// assert_eq!(floor(0.0), 0.0);
62/// assert_eq!(floor(0.99), 0.0);
63/// assert_eq!(floor(-0.99), -1.0);
64/// assert_eq!(floor(1.99), 1.0);
65/// assert_eq!(floor(1.01), 1.0);
66/// assert_eq!(floor(-1.99), -2.0);
67/// ```
68/// <small>End Fun Doc</small>
69pub fn floor(x: f64) -> f64 {
70 x.floor()
71}
72
73/// ### ceil(x)
74///
75/// Rounding Function
76///
77/// The `ceil` function rounds a number up to the nearest integer greater than or equal to it.
78///
79/// ### Examples
80/// ```rust
81/// use mathlab::math::ceil;
82/// assert_eq!(ceil(0.0), 0.0);
83/// assert_eq!(ceil(0.99), 1.0);
84/// assert_eq!(ceil(-0.99), 0.0);
85/// assert_eq!(ceil(1.99), 2.0);
86/// assert_eq!(ceil(1.01), 2.0);
87/// assert_eq!(ceil(-1.99), -1.0);
88/// ```
89/// <small>End Fun Doc</small>
90pub fn ceil(x: f64) -> f64 {
91 x.ceil()
92}
93
94/// ### round(x)
95///
96/// Rounding Function
97///
98/// The `round` function aligns a number to the closest integer,
99/// adjusting fractions of `0.5` or greater up, and less than `0.5` down.
100///
101/// The native way to define a `round` function in `Rust` is:
102/// ```rust
103/// pub fn round(x: f64) -> f64 {
104/// x.round()
105/// }
106/// ```
107///
108/// The alternative way to define a native round function is by using the ceil function for negative numbers and the floor function for non-negative numbers.
109/// ```rust
110/// use mathlab::math::{ceil, floor};
111/// pub fn round(x: f64) -> f64 {
112/// if x < 0.0 {
113/// ceil(x - 0.5)
114/// } else {
115/// floor(x + 0.5)
116/// }
117/// }
118/// ```
119///
120/// ### Examples
121/// ```rust
122/// use mathlab::math::round;
123/// assert_eq!(round(0.0), 0.0);
124/// assert_eq!(round(0.5), 1.0);
125/// assert_eq!(round(-0.5), -1.0);
126/// assert_eq!(round(1.99), 2.0);
127/// assert_eq!(round(1.01), 1.0);
128/// assert_eq!(round(-1.99), -2.0);
129/// ```
130/// <small>End Fun Doc</small>
131pub fn round(x: f64) -> f64 {
132 x.round()
133}
134
135/// ### fround(x)
136///
137/// Rounding Function
138///
139/// The `fround` function performs the same operation as the `f64_to_f32` function.
140///
141/// The `fround` function rounds a floating-point number to the nearest
142/// single-precision `(32-bit)` floating-point number.
143///
144/// ### Examples
145/// ```rust
146/// use mathlab::math::fround;
147/// assert_eq!(fround(0.6666666666666666), 0.6666667);
148/// assert_eq!(fround(0.30000000000000004), 0.3);
149/// assert_eq!(fround(0.020000000000000004), 0.02);
150/// assert_eq!(fround(0.09999999999999998), 0.1);
151/// ```
152/// <small>End Fun Doc</small>
153pub fn fround(x: f64) -> f32 {
154 x as f32
155}
156
157/// ### f64_to_f32(x)
158///
159/// Rounding Function
160///
161/// The `f64_to_f32` function performs the same operation as the `fround` function.
162///
163/// The `f64_to_f32` function rounds a floating-point number to the nearest
164/// single-precision `(32-bit)` floating-point number.
165///
166/// ### Examples
167/// ```rust
168/// use mathlab::math::f64_to_f32;
169/// assert_eq!(f64_to_f32(0.6666666666666666), 0.6666667);
170/// assert_eq!(f64_to_f32(0.30000000000000004), 0.3);
171/// assert_eq!(f64_to_f32(0.020000000000000004), 0.02);
172/// assert_eq!(f64_to_f32(0.09999999999999998), 0.1);
173/// ```
174/// <small>End Fun Doc</small>
175pub fn f64_to_f32(x: f64) -> f32 {
176 x as f32
177}
178
179/// ### u64_to_f64(x)
180///
181/// Conversion Function
182///
183/// The `u64_to_f64` function takes a u64 value as input and returns its `f64` representation.
184///
185/// ### Examples
186/// ```rust
187/// use mathlab::math::u64_to_f64;
188/// assert_eq!(u64_to_f64(0), 0.0);
189/// assert_eq!(u64_to_f64(1), 1.0);
190/// assert_eq!(u64_to_f64(2), 2.0);
191/// assert_eq!(u64_to_f64(3), 3.0);
192/// ```
193/// <small>End Fun Doc</small>
194pub fn u64_to_f64(x: u64) -> f64 {
195 x as f64
196}
197
198/// ### i64_to_f64(x)
199///
200/// Conversion Function
201///
202/// The `i64_to_f64` function takes a i64 value as input and returns its `f64` representation.
203///
204/// ### Examples
205/// ```rust
206/// use mathlab::math::i64_to_f64;
207/// assert_eq!(i64_to_f64(-2), -2.0);
208/// assert_eq!(i64_to_f64(-1), -1.0);
209/// assert_eq!(i64_to_f64(0), 0.0);
210/// assert_eq!(i64_to_f64(1), 1.0);
211/// assert_eq!(i64_to_f64(2), 2.0);
212/// ```
213/// <small>End Fun Doc</small>
214pub fn i64_to_f64(x: i64) -> f64 {
215 x as f64
216}
217
218/// ### is_nan_f32(x)
219///
220/// Boolean Check Function
221///
222/// The `is_nan_f32` function is a utility method used to check whether a given `f32 number`
223/// represents Not a Number (`NaN`) according to `IEEE 754` arithmetic standards.
224///
225/// ### Examples
226/// ```rust
227/// use mathlab::math::{NAN_F64, is_nan_f32, f64_to_f32, add};
228/// assert!(is_nan_f32(add(NAN_F64, 1.0) as f32));
229/// assert!(is_nan_f32(f64_to_f32(add(NAN_F64, 1.0))));
230/// assert_eq!(assert!(is_nan_f32(add(NAN_F64, 1.0) as f32)), assert!(is_nan_f32(f64_to_f32(add(NAN_F64, 1.0)))));
231/// ```
232/// <small>End Fun Doc</small>
233pub fn is_nan_f32(x: f32) -> bool {
234 x != x
235}
236
237/// ### is_inf_f32(x)
238///
239/// Boolean Check Function
240///
241/// The `is_inf_f32` function is a utility method that helps determine whether a specified `f32 number`
242/// follows the convention of `infinity` under the `IEEE 754` standard for floating-point arithmetic.
243///
244/// ### Examples
245/// ```rust
246/// use mathlab::math::{is_inf_f32, f64_to_f32, divi};
247/// assert!(is_inf_f32(divi(2.0, 0.0) as f32));
248/// assert!(is_inf_f32(f64_to_f32(divi(2.0, 0.0))));
249/// assert_eq!(assert!(is_inf_f32(divi(2.0, 0.0) as f32)), assert!(is_inf_f32(f64_to_f32(divi(2.0, 0.0)))));
250/// ```
251/// <small>End Fun Doc</small>
252pub fn is_inf_f32(x: f32) -> bool {
253 if x == INF_F32 {
254 true
255 } else {
256 false
257 }
258}
259
260/// ### is_ninf_f32(x)
261///
262/// Boolean Check Function
263///
264/// The `is_ninf_f32` function helps determine whether a provided `f32 negative number` follows
265/// the convention of `negative infinity` as per the `IEEE 754` standard for floating-point arithmetic.
266///
267///
268/// ### Examples
269/// ```rust
270/// use mathlab::math::{is_ninf_f32, f64_to_f32, divi};
271/// assert!(is_ninf_f32(divi(-2.0, 0.0) as f32));
272/// assert!(is_ninf_f32(f64_to_f32(divi(-2.0, 0.0))));
273/// assert_eq!(assert!(is_ninf_f32(divi(-2.0, 0.0) as f32)), assert!(is_ninf_f32(f64_to_f32(divi(-2.0, 0.0)))));
274/// ```
275/// <small>End Fun Doc</small>
276pub fn is_ninf_f32(x: f32) -> bool {
277 if x == NINF_F32 {
278 true
279 } else {
280 false
281 }
282}
283
284/// ### is_nan_f64(x)
285///
286/// Boolean Check Function
287///
288/// The `is_nan_f64` function is a utility method used to check whether a given `f64 number`
289/// represents Not a Number (`NaN`) according to `IEEE 754` arithmetic standards.
290///
291/// ### Examples
292/// ```rust
293/// use mathlab::math::{NAN_F64, is_nan_f64, add, divi};
294/// assert!(is_nan_f64(add(NAN_F64, 1.0)));
295/// assert!(is_nan_f64(divi(0.0, 0.0)));
296/// assert_eq!(assert!(is_nan_f64(add(NAN_F64, 1.0))), assert!(is_nan_f64(divi(0.0, 0.0))));
297/// ```
298/// <small>End Fun Doc</small>
299pub fn is_nan_f64(x: f64) -> bool {
300 x != x
301}
302
303/// ### is_inf_f64(x)
304///
305/// Boolean Check Function
306///
307/// The `is_inf_f64` function is a utility method that helps determine whether a specified `f64 number`
308/// follows the convention of `infinity` under the `IEEE 754` standard for floating-point arithmetic.
309///
310/// ### Examples
311/// ```rust
312/// use mathlab::math::{INF_F64, is_inf_f64, divi, mult};
313/// assert!(is_inf_f64(divi(2.0, 0.0)));
314/// assert!(is_inf_f64(mult(10.0, INF_F64)));
315/// assert_eq!(assert!(is_inf_f64(divi(2.0, 0.0))), assert!(is_inf_f64(mult(10.0, INF_F64))));
316/// ```
317/// <small>End Fun Doc</small>
318pub fn is_inf_f64(x: f64) -> bool {
319 if x == INF_F64 {
320 true
321 } else {
322 false
323 }
324}
325
326/// ### is_ninf_f64(x)
327///
328/// Boolean Check Function
329///
330/// The `is_ninf_f64` function helps determine whether a provided `f64 negative number` follows
331/// the convention of `negative infinity` as per the `IEEE 754` standard for floating-point arithmetic.
332///
333/// ### Examples
334/// ```rust
335/// use mathlab::math::{INF_F64, NINF_F64, is_ninf_f64, divi, mult};
336/// assert!(is_ninf_f64(divi(-2.0, 0.0)));
337/// assert!(is_ninf_f64(mult(10.0, -INF_F64)));
338/// assert_eq!(assert!(is_ninf_f64(divi(-2.0, 0.0))), assert!(is_ninf_f64(mult(10.0, -INF_F64))));
339/// assert_eq!(assert!(is_ninf_f64(divi(-2.0, 0.0))), assert!(is_ninf_f64(mult(10.0, NINF_F64))));
340/// ```
341/// <small>End Fun Doc</small>
342pub fn is_ninf_f64(x: f64) -> bool {
343 if x == NINF_F64 {
344 true
345 } else {
346 false
347 }
348}
349
350/// ### fact(x)
351///
352/// Native Function
353///
354/// The factorial function, denoted as `n!`, is a mathematical function
355/// that multiplies a given positive integer n by all the positive integers less than it.
356/// The factorial of `n` is defined as:
357///
358/// `n!=n×(n−1)×(n−2)×…×1`
359///
360/// For example, the factorial of 5 (denoted as 5!) is:
361///
362/// `5!=5×4×3×2×1=120`
363///
364/// By definition, the factorial of 0 is 1, i.e., `0! = 1`.
365/// ### Examples
366/// ```rust
367/// use mathlab::math::fact;
368/// assert_eq!(fact(0), 1);
369/// assert_eq!(fact(1), 1);
370/// assert_eq!(fact(2), 2);
371/// assert_eq!(fact(3), 6);
372/// assert_eq!(fact(3) as u8, 6);
373/// assert_eq!(fact(3) as i32, 6);
374/// assert_eq!(fact(3) as f64, 6.0);
375/// assert_eq!(fact(16), 20922789888000);
376/// assert_eq!(fact(18), 6402373705728000);
377/// ```
378/// <small>End Fun Doc</small>
379pub fn fact(x: u64) -> u64 {
380 if x == 0 {
381 1
382 } else {
383 x * fact(x - 1)
384 }
385}
386
387/// ### gamma(x)
388///
389/// Extended Factorial Function
390///
391/// `Γ(n)` is a way to extend the factorial function to all complex numbers
392/// except the negative integers and zero.
393/// For any positive integer, the Gamma function is defined as:
394///
395/// `Γ(n)=(n−1)!`
396///
397/// For example, the gamma of `3` (denoted as `Γ(3)`) is:
398///
399/// `Γ(3)=(3−1)! = 2!=2×1=2`
400///
401/// By definition, the Gamma function of `0` returns an `error` because `0 − 1 = − 1`,
402/// which is not accepted in the factorial function.
403/// ### Examples
404/// ```rust
405/// use mathlab::math::gamma;
406/// assert_eq!(gamma(1), 1);
407/// assert_eq!(gamma(2), 1);
408/// assert_eq!(gamma(3), 2);
409/// assert_eq!(gamma(4), 6);
410/// assert_eq!(gamma(4) as u8, 6);
411/// assert_eq!(gamma(4) as i32, 6);
412/// assert_eq!(gamma(4) as f64, 6.0);
413/// assert_eq!(gamma(17), 20922789888000);
414/// assert_eq!(gamma(19), 6402373705728000);
415/// ```
416/// <small>End Fun Doc</small>
417pub fn gamma(x: u64) -> u64 {
418 fact(x - 1)
419}
420
421/// ### inv(x)
422///
423/// Native Function
424///
425/// The `inv` function returns the inverse of `x`.
426///
427/// ### Examples
428/// ```rust
429/// use mathlab::math::{inv, INF_F64};
430/// assert_eq!(inv(0.0), INF_F64);
431/// assert_eq!(inv(1.0), 1.0);
432/// assert_eq!(inv(2.0), 0.5);
433/// assert_eq!(inv(10.0), 0.1);
434/// assert_eq!(inv(0.1), 10.0);
435/// ```
436/// <small>End Fun Doc</small>
437pub fn inv(x: f64) -> f64 {
438 1.0 / x
439}
440
441/// ### add(x, y)
442///
443/// Native Function
444///
445/// The `add` function returns the sum of `x` and `y`.
446///
447/// ### Examples
448/// ```rust
449/// use mathlab::math::{add, fix64};
450/// assert_eq!(add(1.0, 2.0), 3.0);
451/// assert_eq!(add(0.1, 0.2), 0.30000000000000004);
452/// assert_eq!(add(0.1, 0.2) as f64, 0.30000000000000004);
453/// assert_eq!(add(0.1, 0.2) as f32, 0.3); // 0.3 -> f32
454/// assert_eq!(fix64(add(0.1, 0.2)), 0.3); // 0.3 -> f64
455/// assert_eq!(0.1 + 0.2, 0.30000000000000004);
456/// assert_eq!(fix64(0.1 + 0.2), 0.3); // 0.3 -> f64
457/// ```
458/// <small>End Fun Doc</small>
459pub fn add(x: f64, y: f64) -> f64 {
460 x + y
461}
462
463/// ### subt(x, y)
464///
465/// Native Function
466///
467/// The `subt` function is a mathematical operation that subtracts the value of `y` from `x`.
468///
469/// ### Examples
470/// ```rust
471/// use mathlab::math::{subt, fix64, is_nan_f64, NAN_F64, INF_F64, NINF_F64};
472/// assert_eq!(subt(1.0, 2.0), -1.0);
473/// assert_eq!(subt(1.0, 2.0), -1.0);
474/// assert_eq!(subt(0.3, 0.2), 0.09999999999999998);
475/// assert_eq!(subt(0.3, 0.2) as f64, 0.09999999999999998);
476/// assert_eq!(subt(0.3, 0.2) as f32, 0.1); // 0.1 -> f32
477/// assert_eq!(fix64(subt(0.3, 0.2)), 0.1); // 0.1 -> f64
478/// assert!(is_nan_f64(subt(NAN_F64, 2.0)));
479/// assert_eq!(subt(INF_F64, 2.0), INF_F64);
480/// assert_eq!(subt(1.0, INF_F64), -INF_F64);
481/// assert_eq!(subt(1.0, INF_F64), NINF_F64);
482/// ```
483/// <small>End Fun Doc</small>
484pub fn subt(x: f64, y: f64) -> f64 {
485 x - y
486}
487
488/// ### mult(x, y)
489///
490/// Native Function
491///
492/// The `mult` function is a mathematical operation that multiplies the value of `x` by `y`.
493///
494/// ### Examples
495/// ```rust
496/// use mathlab::math::{mult, fix64, is_nan_f64, NAN_F64, INF_F64, NINF_F64};
497/// assert_eq!(mult(2.0, 3.0), 6.0);
498/// assert_eq!(mult(0.1, 0.2), 0.020000000000000004);
499/// assert_eq!(mult(0.1, 0.2) as f32, 0.02); // 0.02 -> f32
500/// assert_eq!(fix64(mult(0.1, 0.2)), 0.02); // 0.02 -> f64
501/// assert!(is_nan_f64(mult(NAN_F64, 2.0)));
502/// assert_eq!(mult(INF_F64, 2.0), INF_F64);
503/// assert_eq!(mult(-1.0, INF_F64), -INF_F64);
504/// assert_eq!(mult(1.0, -INF_F64), NINF_F64);
505/// ```
506/// <small>End Fun Doc</small>
507pub fn mult(x: f64, y: f64) -> f64 {
508 x * y
509}
510
511/// ### divi(x, y)
512///
513/// Native Function
514///
515/// The `divi` function is a mathematical operation that divides the value of `x` by `y`.
516///
517/// ### Examples
518/// ```rust
519/// use mathlab::math::{divi, fix64, is_nan_f64, is_inf_f64, is_ninf_f64, is_ninf_f32, NAN_F64, INF_F64, NINF_F64};
520/// assert_eq!(divi(2.0, 3.0), 0.6666666666666666);
521/// assert_eq!(divi(2.0, 3.0) as f32, 0.6666667); // 0.6666667 -> f32
522/// assert_eq!(fix64(divi(2.0, 3.0)), 0.6666667); // 0.6666667 -> f64
523/// assert_eq!(divi(0.3, 0.6), 0.5);
524/// assert_eq!(divi(0.3, 0.6) as f64, 0.5);
525/// assert_eq!(divi(0.3, 0.6) as f32, 0.5);
526///
527/// assert_eq!(divi(0.3, 0.0), INF_F64);
528/// assert_eq!(divi(0.3, 0.0) as f32, INF_F64 as f32);
529/// assert_eq!(divi(-0.3, 0.0), -INF_F64);
530/// assert_eq!(divi(-0.3, 0.0), NINF_F64);
531///
532/// assert!(is_nan_f64(divi(0.0, 0.0)));
533/// assert!(is_inf_f64(divi(1.0, 0.0)));
534/// assert!(is_ninf_f64(divi(-1.0, 0.0)));
535/// assert!(is_ninf_f32(divi(-1.0, 0.0) as f32));
536/// ```
537/// <small>End Fun Doc</small>
538pub fn divi(x: f64, y: f64) -> f64 {
539 x / y
540}
541
542/// ### pow(x, y)
543///
544/// Native Function
545///
546/// The `pow` function is a mathematical function that computes the power of a number.
547///
548/// ### Examples
549/// ```rust
550/// use mathlab::math::{pow, is_nan_f64, NAN_F64, INF_F64};
551/// assert_eq!(pow(0.0, 1.0), 0.0);
552/// assert_eq!(pow(0.0, 0.0), 1.0);
553/// assert_eq!(pow(0.0 / 0.0, 0.0), 1.0);
554/// assert_eq!(pow(1.0 , 0.0), 1.0);
555/// assert_eq!(pow(3.0 , 3.0), 27.0);
556/// assert_eq!(pow(2.0 , -3.0), 0.125);
557/// assert_eq!(pow(-3.0 , 2.0), 9.0);
558/// assert_eq!(pow(-3.0 , -3.0), -0.037037037037037035);
559/// assert_eq!(pow(3.33 , 3.33), 54.92110892259572);
560/// assert_eq!(pow(3.33 , -3.33), 0.01820793533883979);
561/// assert!(is_nan_f64(pow(NAN_F64, 2.0)));
562/// assert_eq!(pow(INF_F64, 2.0), INF_F64);
563/// ```
564/// <small>End Fun Doc</small>
565pub fn pow(x: f64, y: f64) -> f64 {
566 x.powf(y)
567}
568
569/// ### deg_to_rad(x)
570///
571/// Conversion Function
572///
573/// The `deg_to_rad` function converts an `angle` from `degrees` to `radians`.
574/// This is useful in `trigonometric` calculations, where `angles` are often required in `radians`.
575///
576/// ### Examples
577/// ```rust
578/// use mathlab::math::deg_to_rad;
579/// assert_eq!(deg_to_rad(0.0), 0.0);
580/// assert_eq!(deg_to_rad(1.0), 0.0174532925);
581/// assert_eq!(deg_to_rad(30.0), 0.5235987756);
582/// assert_eq!(deg_to_rad(45.0), 0.7853981634);
583/// assert_eq!(deg_to_rad(60.0), 1.0471975512);
584/// assert_eq!(deg_to_rad(90.0), 1.5707963268);
585/// assert_eq!(deg_to_rad(135.0), 2.3561944902);
586/// assert_eq!(deg_to_rad(180.0), 3.1415926536);
587/// assert_eq!(deg_to_rad(270.0), 4.7123889804);
588/// assert_eq!(deg_to_rad(360.0), 6.2831853072);
589/// assert_eq!(deg_to_rad(-360.0), -6.2831853072);
590/// ```
591/// <small>End Fun Doc</small>
592pub fn deg_to_rad(x: f64) -> f64 {
593 fix(x * PI / 180.0, 10)
594}
595
596/// ### rad_to_deg(x)
597///
598/// Conversion Function
599///
600/// The `rad_to_deg` function converts an `angle` from `radians` to `degrees`.
601/// This is useful in `trigonometric` calculations, where `angles` are often required in `degrees`.
602///
603/// ### Examples
604/// ```rust
605/// use mathlab::math::{rad_to_deg, fix64};
606/// assert_eq!(rad_to_deg(0.0), 0.0);
607/// assert_eq!(rad_to_deg(0.0174532925), 1.0);
608/// assert_eq!(rad_to_deg(0.5235987756), 30.0);
609/// assert_eq!(rad_to_deg(0.7853981634), 45.0);
610/// assert_eq!(rad_to_deg(1.0471975512), 60.0);
611/// assert_eq!(rad_to_deg(1.5707963268), 90.0);
612/// assert_eq!(rad_to_deg(3.1415926536), 180.0);
613/// assert_eq!(rad_to_deg(4.7123889804), 270.0);
614/// assert_eq!(rad_to_deg(6.2831853072), 360.0);
615/// assert_eq!(rad_to_deg(-6.2831853072), -360.0);
616/// ```
617/// <small>End Fun Doc</small>
618pub fn rad_to_deg(x: f64) -> f64 {
619 fix64(x * 180.0 / PI)
620}
621
622/// ### sqr(x)
623///
624/// Native Function
625///
626/// The `sqr` function calculates its square by multiplying it with itself.
627///
628/// ### Examples
629/// ```rust
630/// use mathlab::math::{sqr, INF_F64};
631/// assert_eq!(sqr(0.0), 0.0);
632/// assert_eq!(sqr(0.1), 0.010000000000000002);
633/// assert_eq!(sqr(0.1) as f32, 0.01);
634/// assert_eq!(sqr(1.0), 1.0);
635/// assert_eq!(sqr(2.0), 4.0);
636/// assert_eq!(sqr(10.0), 100.0);
637/// assert_eq!(sqr(INF_F64), INF_F64);
638/// ```
639/// <small>End Fun Doc</small>
640pub fn sqr(x: f64) -> f64 {
641 x * x
642}
643
644/// ### sqrt(x)
645///
646/// Native Function
647///
648/// The `sqrt` function returns the square root of a given number, which is the number that, when multiplied by itself, equals the original input.
649///
650/// ### Examples
651/// ```rust
652/// use mathlab::math::{sqrt, INF_F64};
653/// assert_eq!(sqrt(0.0), 0.0);
654/// assert_eq!(sqrt(0.01), 0.1);
655/// assert_eq!(sqrt(1.0), 1.0);
656/// assert_eq!(sqrt(4.0), 2.0);
657/// assert_eq!(sqrt(9.0), 3.0);
658/// assert_eq!(sqrt(100.0), 10.0);
659/// assert_eq!(sqrt(INF_F64), INF_F64);
660/// ```
661/// <small>End Fun Doc</small>
662pub fn sqrt(x: f64) -> f64 {
663 x.sqrt()
664}
665
666/// ### rem(x, y)
667///
668/// Operation Function
669///
670/// The `rem` function provides the remainder of dividing `x` by `y`, returning a `f64` floating-point number.
671///
672/// ### Examples
673/// ```rust
674/// use mathlab::math::{rem, fix64, is_nan_f64, INF_F64};
675/// assert!(is_nan_f64(rem(0.0, 0.0)));
676/// assert!(is_nan_f64(rem(1.0, 0.0)));
677/// assert!(is_nan_f64(rem(INF_F64, 0.0)));
678/// assert!(is_nan_f64(rem(INF_F64, 2.0)));
679/// assert!(is_nan_f64(rem(INF_F64, INF_F64)));
680/// assert!(is_nan_f64(rem(INF_F64, INF_F64)));
681/// assert_eq!(rem(0.0, INF_F64), 0.0);
682/// assert_eq!(rem(2.0, INF_F64), 2.0);
683/// assert_eq!(rem(1.0, 0.1), 0.09999999999999995);
684/// assert_eq!(rem(1.0, 0.1) as f32, 0.1); // f32
685/// assert_eq!(fix64(rem(1.0, 0.1)), 0.1); // f64
686/// assert_eq!(rem(0.0, 3.0), 0.0);
687/// assert_eq!(rem(1.0, 3.0), 1.0);
688/// assert_eq!(rem(2.0, 3.0), 2.0);
689/// assert_eq!(rem(3.0, 3.0), 0.0);
690/// assert_eq!(rem(4.0, 3.0), 1.0);
691/// ```
692/// <small>End Fun Doc</small>
693pub fn rem(x: f64, y: f64) -> f64 {
694 x % y
695}
696
697/// ### nrt(x, n)
698///
699/// Operation Function
700///
701/// The `nrt` function calculates the `n-th` root of `x`, where `n` is a given power,
702/// and returns the result as a floating-point number.
703///
704/// ### Examples
705/// ```rust
706/// use mathlab::math::nrt;
707/// assert_eq!(nrt(1.0, 3.0), 1.0);
708/// assert_eq!(nrt(3.0, 1.0), 3.0);
709/// assert_eq!(nrt(9.0, 2.0), 3.0);
710/// assert_eq!(nrt(27.0, 3.0), 3.0);
711/// assert_eq!(nrt(81.0, 4.0), 3.0);
712/// ```
713/// <small>End Fun Doc</small>
714pub fn nrt(x: f64, n: f64) -> f64 {
715 x.powf(1.0 / n)
716}
717
718/// ### exp(x)
719///
720/// Operation Function
721///
722/// The `exp` function defined as `pow(E, x)` raises the mathematical constant `e` to the power of `x`.
723///
724/// ### Examples
725/// ```rust
726/// use mathlab::math::{exp, E};
727/// assert_eq!(exp(0.0), 1.0);
728/// assert_eq!(exp(-1.0), 0.36787944117144233);
729/// assert_eq!(exp(-1.0) as f32, 0.36787945);
730/// assert_eq!(exp(1.0), E);
731/// ```
732/// <small>End Fun Doc</small>
733pub fn exp(x: f64) -> f64 {
734 pow(E, x)
735}
736
737/// ### ln(x)
738///
739/// Logarithm Function
740///
741/// The `ln` function returns the natural logarithm (base e) of the given float value 'x'.
742///
743/// ### Examples
744/// ```rust
745/// use mathlab::math::{ln, E, INF_F64 as inf, LN10, is_nan_f64};
746/// assert!(is_nan_f64(ln(-inf)));
747/// assert_eq!(ln(0.0), -inf);
748/// assert_eq!(ln(1.0), 0.0);
749/// assert_eq!(ln(E), 1.0);
750/// assert_eq!(ln(10.0), 2.302585092994046);
751/// assert_eq!(ln(10.0), LN10);
752/// assert_eq!(-ln(1.5), -0.4054651081081644);
753/// ```
754/// <small>End Fun Doc</small>
755pub fn ln(x: f64) -> f64 {
756 x.ln()
757}
758
759/// ### ln1p(x)
760///
761/// Logarithm Function
762///
763/// The `ln1p` returns `ln(1+x)` (natural logarithm) more accurately than if the operations were performed separately.
764///
765/// ### Examples
766/// ```rust
767/// use mathlab::math::{ln1p, E, INF_F64 as inf, LN10, is_nan_f64};
768/// assert!(is_nan_f64(ln1p(-inf)));
769/// assert_eq!(ln1p(0.0), 0.0);
770/// assert_eq!(ln1p(1.0), 0.6931471805599453);
771/// assert_eq!(ln1p(E), 1.3132616875182228);
772/// assert_eq!(ln1p(10.0), 2.3978952727983707);
773/// assert_eq!(ln1p(LN10), 1.1947055233182953);
774/// assert_eq!(-ln1p(1.5), -0.9162907318741551);
775/// ```
776/// <small>End Fun Doc</small>
777pub fn ln1p(x: f64) -> f64 {
778 x.ln_1p()
779}
780
781/// ### log2(x)
782///
783/// Logarithm Function
784///
785/// The `log2` computes the base-2 logarithm of the supplied float number 'x'.
786///
787/// ### Examples
788/// ```rust
789/// use mathlab::math::{log2, E, INF_F64 as inf, LN10, is_nan_f64};
790/// assert!(is_nan_f64(log2(-inf)));
791/// assert_eq!(log2(0.0), -inf);
792/// assert_eq!(log2(1.0), 0.0);
793/// assert_eq!(log2(E), 1.4426950408889634);
794/// assert_eq!(log2(10.0), 3.321928094887362);
795/// assert_eq!(log2(LN10), 1.2032544726997219);
796/// assert_eq!(-log2(1.5), -0.5849625007211562);
797/// ```
798/// <small>End Fun Doc</small>
799pub fn log2(x: f64) -> f64 {
800 x.log2()
801}
802
803/// ### log10(x)
804///
805/// Logarithm Function
806///
807/// The `log10` computes the base-10 logarithm of the supplied float number 'x'.
808///
809/// ### Examples
810/// ```rust
811/// use mathlab::math::{log10, E, INF_F64 as inf, LN10, is_nan_f64};
812/// assert!(is_nan_f64(log10(-inf)));
813/// assert_eq!(log10(0.0), -inf);
814/// assert_eq!(log10(1.0), 0.0);
815/// assert_eq!(log10(E), 0.4342944819032518);
816/// assert_eq!(log10(10.0), 1.0);
817/// assert_eq!(log10(LN10), 0.36221568869946325);
818/// assert_eq!(-log10(1.5), -0.17609125905568124);
819/// ```
820/// <small>End Fun Doc</small>
821pub fn log10(x: f64) -> f64 {
822 x.log10()
823}
824
825/// ### fix64(x)
826///
827/// Fixation Function
828///
829/// The `fix64` function, takes a `64-bit floating-point number` (a double precision value) as input
830/// and returns an equivalent `fixed-point value` with `the same bit width`. To achieve this conversion,
831/// the input float is first converted to a 32-bit floating-point type (an f32) using (as f32) method. Then,
832/// this intermediate value is converted back to a string representation using to_string(),
833/// parsed as an f32 again, and finally returned as an `f64`.
834///
835/// ### Examples
836/// ```rust
837/// use mathlab::math::fix64;
838/// // assert_eq!(fix64("abc"), 0.3); // error: expected `f64`, found `&str`
839/// // assert_eq!(fix64("0.1"), 0.3); // error: expected `f64`, found `&str`
840/// // assert_eq!(fix64(1), 0.3); // error: expected `f64`, found integer
841/// assert_eq!(0.1 + 0.2, 0.30000000000000004);
842/// assert_eq!(0.3 - 0.2, 0.09999999999999998);
843/// assert_eq!(fix64(0.1 + 0.2), 0.3);
844/// assert_eq!(fix64(0.3 - 0.2), 0.1);
845/// assert_eq!(fix64(0.30000000000000004), 0.3);
846/// ```
847/// <small>End Fun Doc</small>
848pub fn fix64(x: f64) -> f64 {
849 (x as f32).to_string().parse().expect("")
850}
851
852/// ### fix(x, decimal_places)
853///
854/// Fixation Function
855///
856/// The `fix` function rounds a floating-point number `x` to a fixed-point value with a
857/// specified number of decimal places, returning the result as a floating-point number.
858///
859/// ### Examples
860/// ```rust
861/// use mathlab::math::{fix, to_fixed, is_nan_f64, INF_F64 as inf, NAN_F64 as NaN};
862/// assert_eq!(fix(0.5235987755982988, 3), 0.524);
863/// assert_eq!(fix(0.5235987755982928, 15), 0.523598775598293);
864/// assert_eq!(fix(0.5235987755982928, 1), 0.5);
865/// assert_eq!(fix(0.5235987755982928, 0), 1.0);
866/// assert_eq!(fix(0.0, 0), 0.0);
867/// assert_eq!(fix(inf, 0), inf);
868/// assert!(is_nan_f64(fix(NaN, 0)));
869/// assert_eq!(to_fixed(NaN, 0), "NaN");
870/// assert_eq!(to_fixed(0.1 + 0.2, 15), "0.3");
871/// assert_eq!(fix(3.1415926536 * 7.0, 10), 21.9911485752);
872/// assert_eq!(fix(21.9911485752 / 7.0, 10), 3.1415926536);
873/// ```
874/// <small>End Fun Doc</small>
875pub fn fix(x: f64, decimal_places: u32) -> f64 {
876 let multiplier = 10f64.powi(decimal_places as i32);
877 (x * multiplier).round() / multiplier
878}
879
880/// ### cube(x)
881///
882/// Native Function
883///
884/// The `cube` function computes the value of `x` raised to the power of three,
885/// which is equivalent to multiplying `x` by itself three times.
886///
887/// ### Examples
888/// ```rust
889/// use mathlab::math::{cube, fix64};
890/// assert_eq!(cube(0.1), 0.0010000000000000002);
891/// assert_eq!(fix64(cube(0.1)), 0.001);
892/// assert_eq!(cube(2.0), 8.0);
893/// ```
894/// <small>End Fun Doc</small>
895pub fn cube(x: f64) -> f64 {
896 x * x * x
897}
898
899/// ### cbrt(x)
900///
901/// Native Function
902///
903/// The `cbrt` function computes the real cube root of the given floating-point number `x`.
904///
905/// ### Examples
906/// ```rust
907/// use mathlab::math::cbrt;
908/// assert_eq!(cbrt(0.001), 0.1);
909/// assert_eq!(cbrt(8.0), 2.0);
910/// ```
911/// <small>End Fun Doc</small>
912pub fn cbrt(x: f64) -> f64 {
913 x.cbrt()
914}
915
916/// ### trunc(x)
917///
918/// Rounding Function
919///
920/// The `trunc` function returns the integer part of self.
921/// This means that non-integer numbers are always truncated towards zero.
922///
923/// ### Examples
924/// ```rust
925/// use mathlab::math::trunc;
926/// assert_eq!(trunc(-0.37), 0.0);
927/// assert_eq!(trunc(0.37), 0.0);
928/// assert_eq!(trunc(-3.7), -3.0);
929/// assert_eq!(trunc(3.7), 3.0);
930/// ```
931/// <small>End Fun Doc</small>
932pub fn trunc(x: f64) -> f64 {
933 x.trunc()
934}
935
936/// ### perimeter(x, y)
937///
938/// Geometry Function
939///
940/// The `perimeter` function calculates the total length of a rectangle's boundaries,
941/// given its width and height, returning the result as a floating-point number.
942///
943/// ### Examples
944/// ```rust
945/// use mathlab::math::{perimeter, INF_F64 as inf};
946/// assert_eq!(perimeter(0.0 , 0.0), 0.0);
947/// assert_eq!(perimeter(0.0 , 1.0), 2.0);
948/// assert_eq!(perimeter(1.0 , 0.0), 2.0);
949/// assert_eq!(perimeter(1.0 , 1.0), 4.0);
950/// assert_eq!(perimeter(2.0 , 1.0), 6.0);
951/// assert_eq!(perimeter(inf , 1.0), inf);
952/// ```
953/// <small>End Fun Doc</small>
954pub fn perimeter(x: f64, y: f64) -> f64 {
955 2.0 * (x + y)
956}
957
958/// ### sin(x)
959///
960/// Trigonometric Function
961///
962/// The `sin` function computes the sine of a number (in radians).
963///
964/// ### Examples
965/// ```rust
966/// use mathlab::math::sin;
967/// assert_eq!(sin(0.0), 0.0);
968/// assert_eq!(sin(1e-11), 1e-11);
969/// assert_eq!(sin(1e-10), 1e-10);
970/// assert_eq!(sin(1e-4), 1e-4);
971/// assert_eq!(sin(0.0050000208), 5e-3);
972/// assert_eq!(sin(0.5235987756), 0.5);
973/// assert_eq!(sin(0.7853981634), 0.7071067812);
974/// assert_eq!(sin(1.0471975512), 0.8660254038);
975/// assert_eq!(sin(1.5707963268), 1.0);
976/// assert_eq!(sin(3.1415926536), 0.0);
977/// assert_eq!(sin(4.7123889804), -1.0);
978/// assert_eq!(sin(6.2831853072), 0.0);
979/// ```
980/// <small>End Fun Doc</small>
981pub fn sin(x: f64) -> f64 {
982 if abs(x) <= 1e-10 {
983 x
984 } else {
985 fix(x.sin(), 10)
986 }
987}
988
989/// ### sin_deg(x)
990///
991/// Trigonometric Function
992///
993/// The `sin_deg` function computes the sine of an angle given in degrees.
994///
995/// ### Examples
996/// ```rust
997/// use mathlab::math::sin_deg;
998/// assert_eq!(sin_deg(0.0), 0.0);
999/// assert_eq!(sin_deg(30.0), 0.5);
1000/// assert_eq!(sin_deg(45.0), 0.7071067812);
1001/// assert_eq!(sin_deg(60.0), 0.8660254038);
1002/// assert_eq!(sin_deg(90.0), 1.0);
1003/// assert_eq!(sin_deg(180.0), 0.0);
1004/// assert_eq!(sin_deg(270.0), -1.0);
1005/// assert_eq!(sin_deg(360.0), 0.0);
1006/// ```
1007/// <small>End Fun Doc</small>
1008pub fn sin_deg(x: f64) -> f64 {
1009 sin(deg_to_rad(x))
1010}
1011
1012/// ### asin(x)
1013///
1014/// Inverse Trigonometric Function
1015///
1016/// The `asin` function computes the inverse sine of a number (in radians), returning the angle whose sine is equal to the input value.
1017///
1018/// ### Examples
1019/// ```rust
1020/// use mathlab::math::asin;
1021/// assert_eq!(asin(0.0), 0.0);
1022/// assert_eq!(asin(1e-11), 1e-11);
1023/// assert_eq!(asin(1e-10), 1e-10);
1024/// assert_eq!(asin(1e-4), 1e-4);
1025/// assert_eq!(asin(5e-3), 0.0050000208);
1026/// assert_eq!(asin(0.5), 0.5235987756);
1027/// assert_eq!(asin(0.7071067812), 0.7853981634);
1028/// assert_eq!(asin(0.8660254038), 1.0471975512);
1029/// assert_eq!(asin(1.0), 1.5707963268);
1030/// assert_eq!(asin(-1.0), -1.5707963268);
1031/// ```
1032/// <small>End Fun Doc</small>
1033pub fn asin(x: f64) -> f64 {
1034 if abs(x) <= 1e-10 {
1035 x
1036 } else {
1037 fix(x.asin(), 10)
1038 }
1039}
1040
1041/// ### asin_deg(x)
1042///
1043/// Inverse Trigonometric Function
1044///
1045/// The `asin_deg` function computes the inverse sine of a number (in degrees), returning the angle whose sine is equal to the input value.
1046///
1047/// ### Examples
1048/// ```rust
1049/// use mathlab::math::asin_deg;
1050/// assert_eq!(asin_deg(0.0), 0.0);
1051/// assert_eq!(asin_deg(0.5), 30.0);
1052/// assert_eq!(asin_deg(0.7071067812), 45.0);
1053/// assert_eq!(asin_deg(0.8660254038), 60.0);
1054/// assert_eq!(asin_deg(1.0), 90.0);
1055/// assert_eq!(asin_deg(-1.0), -90.0);
1056/// ```
1057/// <small>End Fun Doc</small>
1058pub fn asin_deg(x: f64) -> f64 {
1059 rad_to_deg(asin(x))
1060}
1061
1062/// ### cos(x)
1063///
1064/// Trigonometric Function
1065///
1066/// The `cos` function computes the cosine of a number (in radians).
1067///
1068/// ### Examples
1069/// ```rust
1070/// use mathlab::math::cos;
1071/// assert_eq!(cos(0.0), 1.0);
1072/// assert_eq!(cos(1e-11), 1.0);
1073/// assert_eq!(cos(1e-10), 1.0);
1074/// assert_eq!(cos(1e-5), 1.0);
1075/// assert_eq!(cos(1e-4), 0.999999995);
1076/// assert_eq!(cos(0.5235987756), 0.8660254038);
1077/// assert_eq!(cos(0.7853981634), 0.7071067812);
1078/// assert_eq!(cos(1.0471975512), 0.5);
1079/// assert_eq!(cos(1.5707963268), 0.0);
1080/// assert_eq!(cos(3.1415926536), -1.0);
1081/// assert_eq!(cos(4.7123889804), 0.0);
1082/// assert_eq!(cos(6.2831853072), 1.0);
1083/// ```
1084/// <small>End Fun Doc</small>
1085pub fn cos(x: f64) -> f64 {
1086 if abs(x) <= 1e-10 {
1087 1.0
1088 } else {
1089 fix(x.cos(), 10)
1090 }
1091}
1092
1093/// ### cos_deg(x)
1094///
1095/// Trigonometric Function
1096///
1097/// The `cos_deg` function computes the cosine of an angle given in degrees.
1098///
1099/// ### Examples
1100/// ```rust
1101/// use mathlab::math::cos_deg;
1102/// assert_eq!(cos_deg(0.0), 1.0);
1103/// assert_eq!(cos_deg(30.0), 0.8660254038);
1104/// assert_eq!(cos_deg(45.0), 0.7071067812);
1105/// assert_eq!(cos_deg(60.0), 0.5);
1106/// assert_eq!(cos_deg(90.0), 0.0);
1107/// assert_eq!(cos_deg(180.0), -1.0);
1108/// assert_eq!(cos_deg(270.0), 0.0);
1109/// assert_eq!(cos_deg(360.0), 1.0);
1110/// ```
1111/// <small>End Fun Doc</small>
1112pub fn cos_deg(x: f64) -> f64 {
1113 cos(deg_to_rad(x))
1114}
1115
1116/// ### acos(x)
1117///
1118/// Inverse Trigonometric Function
1119///
1120/// The `acos` function computes the inverse cosine of a number (in radians), returning the angle whose cosine is equal to the input value.
1121///
1122/// ### Examples
1123/// ```rust
1124/// use mathlab::math::acos;
1125/// assert_eq!(acos(1.0), 0.0);
1126/// assert_eq!(acos(1e-11), 1.5707963268);
1127/// assert_eq!(acos(1e-10), 1.5707963268);
1128/// assert_eq!(acos(1e-5), 1.5707863268);
1129/// assert_eq!(acos(0.999999995), 1e-4);
1130/// assert_eq!(acos(0.8660254038), 0.5235987756);
1131/// assert_eq!(acos(0.7071067812), 0.7853981634);
1132/// assert_eq!(acos(0.5), 1.0471975512);
1133/// assert_eq!(acos(0.0), 1.5707963268);
1134/// assert_eq!(acos(-1.0), 3.1415926536);
1135/// ```
1136/// <small>End Fun Doc</small>
1137pub fn acos(x: f64) -> f64 {
1138 if abs(x) <= 1e-10 {
1139 1.5707963268
1140 } else {
1141 fix(x.acos(), 10)
1142 }
1143}
1144
1145/// ### acos_deg(x)
1146///
1147/// Inverse Trigonometric Function
1148///
1149/// The `acos_deg` function computes the inverse cosine of a number (in degrees), returning the angle whose cosine is equal to the input value.
1150///
1151/// ### Examples
1152/// ```rust
1153/// use mathlab::math::{acos_deg, is_nan_f64};
1154/// assert_eq!(acos_deg(1.0), 0.0);
1155/// assert_eq!(acos_deg(0.8660254038), 30.0);
1156/// assert_eq!(acos_deg(0.7071067812), 45.0);
1157/// assert_eq!(acos_deg(0.5), 60.0);
1158/// assert_eq!(acos_deg(0.0), 90.0);
1159/// assert_eq!(acos_deg(-1.0), 180.0);
1160/// assert!(is_nan_f64(acos_deg(-2.0)));
1161/// ```
1162/// <small>End Fun Doc</small>
1163pub fn acos_deg(x: f64) -> f64 {
1164 rad_to_deg(acos(x))
1165}
1166
1167/// ### tan(x)
1168///
1169/// Trigonometric Function
1170///
1171/// The `tan` function computes the tangent of a number (in radians).
1172///
1173/// ### Examples
1174/// ```rust
1175/// use mathlab::math::{tan, deg_to_rad, INF_F64 as inf, PI};
1176/// assert_eq!(tan(0.0), 0.0);
1177/// assert_eq!(tan(1e-10), 1e-10);
1178/// assert_eq!(tan(0.5235987756), 0.5773502692);
1179/// assert_eq!(tan(0.7853981634), 1.0);
1180/// assert_eq!(tan(1.0471975512), 1.7320508076);
1181/// assert_eq!(tan(1.5707963268), -inf);
1182/// assert_eq!(tan(2.3561944902), -1.0);
1183/// assert_eq!(tan(3.1415926536), 0.0);
1184/// assert_eq!(tan(4.7123889804), -inf);
1185/// assert_eq!(tan(6.2831853072), 0.0);
1186/// ```
1187/// <small>End Fun Doc</small>
1188pub fn tan(x: f64) -> f64 {
1189 if abs(x) <= 1e-10 {
1190 x
1191 } else {
1192 fix(sin(x) / cos(x), 10)
1193 }
1194}
1195
1196/// ### tan_deg(x)
1197///
1198/// Trigonometric Function
1199///
1200/// The `tan_deg` function computes the tangent of an angle given in degrees.
1201///
1202/// ### Examples
1203/// ```rust
1204/// use mathlab::math::{tan_deg, INF_F64 as inf};
1205/// assert_eq!(tan_deg(0.0), 0.0);
1206/// assert_eq!(tan_deg(30.0), 0.5773502692);
1207/// assert_eq!(tan_deg(45.0), 1.0);
1208/// assert_eq!(tan_deg(60.0), 1.7320508076);
1209/// assert_eq!(tan_deg(90.0), -inf);
1210/// assert_eq!(tan_deg(135.0), -1.0);
1211/// assert_eq!(tan_deg(180.0), 0.0);
1212/// assert_eq!(tan_deg(270.0), -inf);
1213/// assert_eq!(tan_deg(360.0), 0.0);
1214/// ```
1215/// <small>End Fun Doc</small>
1216pub fn tan_deg(x: f64) -> f64 {
1217 tan(deg_to_rad(x))
1218}
1219
1220/// ### atan(x)
1221///
1222/// Inverse Trigonometric Function
1223///
1224/// The `atan` function computes the inverse tangent of a number (in radians), returning the angle whose tangent is equal to the input value.
1225///
1226/// ### Examples
1227/// ```rust
1228/// use mathlab::math::{atan, INF_F64 as inf};
1229/// assert_eq!(atan(0.0), 0.0);
1230/// assert_eq!(atan(1e-10), 1e-10);
1231/// assert_eq!(atan(0.5773502692), 0.5235987756);
1232/// assert_eq!(atan(1.0), 0.7853981634);
1233/// assert_eq!(atan(1.7320508076), 1.0471975512);
1234/// assert_eq!(atan(-1.0), -0.7853981634);
1235/// assert_eq!(atan(-inf), -1.5707963268);
1236/// assert_eq!(atan(inf), 1.5707963268);
1237/// ```
1238/// <small>End Fun Doc</small>
1239pub fn atan(x: f64) -> f64 {
1240 if abs(x) <= 1e-10 {
1241 x
1242 } else {
1243 fix(x.atan(), 10)
1244 }
1245}
1246
1247/// ### atan_deg(x)
1248///
1249/// Inverse Trigonometric Function
1250///
1251/// The `atan_deg` function computes the inverse tangent of a number (in degrees), returning the angle whose tangent is equal to the input value.
1252///
1253/// ### Examples
1254/// ```rust
1255/// use mathlab::math::{atan_deg, INF_F64 as inf};
1256/// assert_eq!(atan_deg(0.0), 0.0);
1257/// assert_eq!(atan_deg(0.5773502692), 30.0);
1258/// assert_eq!(atan_deg(1.0), 45.0);
1259/// assert_eq!(atan_deg(1.7320508076), 60.0);
1260/// assert_eq!(atan_deg(-1.0), -45.0);
1261/// assert_eq!(atan_deg(-inf), -90.0);
1262/// assert_eq!(atan_deg(inf), 90.0);
1263/// ```
1264/// <small>End Fun Doc</small>
1265pub fn atan_deg(x: f64) -> f64 {
1266 rad_to_deg(atan(x))
1267}
1268
1269/// ### csc(x)
1270///
1271/// Trigonometric Function
1272///
1273/// The `csc` function computes the cosecant of a number (in radians).
1274///
1275/// ### Examples
1276/// ```rust
1277/// use mathlab::math::{csc, INF_F64 as inf};
1278/// assert_eq!(csc(-0.5235987756), -2.0);
1279/// assert_eq!(csc(0.0), inf);
1280/// assert_eq!(csc(0.5235987756), 2.0);
1281/// assert_eq!(csc(0.7853981634), 1.4142135623);
1282/// assert_eq!(csc(1.0471975512), 1.1547005384);
1283/// assert_eq!(csc(1.5707963268), 1.0);
1284/// assert_eq!(csc(3.1415926536), -inf);
1285/// assert_eq!(csc(4.7123889804), -1.0);
1286/// assert_eq!(csc(6.2831853072), inf);
1287/// ```
1288/// <small>End Fun Doc</small>
1289pub fn csc(x: f64) -> f64 {
1290 fix(1.0 / sin(x), 10)
1291}
1292
1293/// ### csc_deg(x)
1294///
1295/// Trigonometric Function
1296///
1297/// The `csc_deg` function computes the cosecant of an angle given in degrees.
1298///
1299/// ### Examples
1300/// ```rust
1301/// use mathlab::math::{csc_deg, INF_F64 as inf};
1302/// assert_eq!(csc_deg(-30.0), -2.0);
1303/// assert_eq!(csc_deg(-15.0), -3.8637033052);
1304/// assert_eq!(csc_deg(0.0), inf);
1305/// assert_eq!(csc_deg(15.0), 3.8637033052);
1306/// assert_eq!(csc_deg(30.0), 2.0);
1307/// assert_eq!(csc_deg(45.0), 1.4142135623);
1308/// assert_eq!(csc_deg(60.0), 1.1547005384);
1309/// assert_eq!(csc_deg(90.0), 1.0);
1310/// assert_eq!(csc_deg(180.0), -inf);
1311/// assert_eq!(csc_deg(270.0), -1.0);
1312/// assert_eq!(csc_deg(360.0), inf);
1313/// ```
1314/// <small>End Fun Doc</small>
1315pub fn csc_deg(x: f64) -> f64 {
1316 csc(deg_to_rad(x))
1317}
1318
1319/// ### acsc(x)
1320///
1321/// Trigonometric Function
1322///
1323/// The `acsc` function computes the inverse cosecant of a number (in radians),
1324/// returning the angle whose cosecant is equal to the input value.
1325///
1326/// ### Examples
1327/// ```rust
1328/// use mathlab::math::{acsc, INF_F64 as inf};
1329/// assert_eq!(acsc(-inf), -0.0);
1330/// assert_eq!(acsc(-2.0), -0.5235987756);
1331/// assert_eq!(acsc(-1.0), -1.5707963268);
1332/// assert_eq!(acsc(inf), 0.0);
1333/// assert_eq!(acsc(2.0), 0.5235987756);
1334/// assert_eq!(acsc(1.4142135623), 0.7853981634);
1335/// assert_eq!(acsc(1.1547005384), 1.0471975512);
1336/// assert_eq!(acsc(1.0), 1.5707963268);
1337/// ```
1338/// <small>End Fun Doc</small>
1339pub fn acsc(x: f64) -> f64 {
1340 asin(1.0 / x)
1341}
1342
1343/// ### acsc_deg(x)
1344///
1345/// Trigonometric Function
1346///
1347/// The `acsc_deg` function computes the inverse cosecant of a number (in degrees),
1348/// returning the angle whose cosecant is equal to the input value.
1349///
1350/// ### Examples
1351/// ```rust
1352/// use mathlab::math::{acsc_deg, INF_F64 as inf};
1353/// assert_eq!(acsc_deg(-inf), -0.0);
1354/// assert_eq!(acsc_deg(-2.0), -30.0);
1355/// assert_eq!(acsc_deg(-1.0), -90.0);
1356/// assert_eq!(acsc_deg(inf), 0.0);
1357/// assert_eq!(acsc_deg(2.0), 30.0);
1358/// assert_eq!(acsc_deg(1.4142135623), 45.0);
1359/// assert_eq!(acsc_deg(1.1547005384), 60.0);
1360/// assert_eq!(acsc_deg(1.0), 90.0);
1361/// ```
1362/// <small>End Fun Doc</small>
1363pub fn acsc_deg(x: f64) -> f64 {
1364 asin_deg(1.0 / x)
1365}
1366
1367/// ### sec(x)
1368///
1369/// Trigonometric Function
1370///
1371/// The `sec` function computes the secant of a number (in radians).
1372///
1373/// ### Examples
1374/// ```rust
1375/// use mathlab::math::{sec, INF_F64 as inf};
1376/// assert_eq!(sec(-0.5235987756), 1.1547005384);
1377/// assert_eq!(sec(0.0), 1.0);
1378/// assert_eq!(sec(0.5235987756), 1.1547005384);
1379/// assert_eq!(sec(0.7853981634), 1.4142135623);
1380/// assert_eq!(sec(1.0471975512), 2.0);
1381/// assert_eq!(sec(1.5707963268), -inf);
1382/// assert_eq!(sec(3.1415926536), -1.0);
1383/// assert_eq!(sec(4.7123889804), inf);
1384/// assert_eq!(sec(6.2831853072), 1.0);
1385/// ```
1386/// <small>End Fun Doc</small>
1387pub fn sec(x: f64) -> f64 {
1388 fix(1.0 / cos(x), 10)
1389}
1390
1391/// ### sec_deg(x)
1392///
1393/// Trigonometric Function
1394///
1395/// The `sec_deg` function computes the secant of an angle given in degrees.
1396///
1397/// ### Examples
1398/// ```rust
1399/// use mathlab::math::{sec_deg, INF_F64 as inf};
1400/// assert_eq!(sec_deg(-30.0), 1.1547005384);
1401/// assert_eq!(sec_deg(-15.0), 1.0352761804);
1402/// assert_eq!(sec_deg(0.0), 1.0);
1403/// assert_eq!(sec_deg(15.0), 1.0352761804);
1404/// assert_eq!(sec_deg(30.0), 1.1547005384);
1405/// assert_eq!(sec_deg(45.0), 1.4142135623);
1406/// assert_eq!(sec_deg(60.0), 2.0);
1407/// assert_eq!(sec_deg(90.0), -inf);
1408/// assert_eq!(sec_deg(180.0), -1.0);
1409/// assert_eq!(sec_deg(270.0), inf);
1410/// assert_eq!(sec_deg(360.0), 1.0);
1411/// ```
1412/// <small>End Fun Doc</small>
1413pub fn sec_deg(x: f64) -> f64 {
1414 sec(deg_to_rad(x))
1415}
1416
1417/// ### asec(x)
1418///
1419/// Trigonometric Function
1420///
1421/// The `asec` function computes the inverse secant of a number (in radians),
1422/// returning the angle whose secant is equal to the input value.
1423///
1424/// ### Examples
1425/// ```rust
1426/// use mathlab::math::{asec, INF_F64 as inf};
1427/// assert_eq!(asec(-inf), 1.5707963268);
1428/// assert_eq!(asec(-999999999999.0), 1.5707963268);
1429/// assert_eq!(asec(-1.0), 3.1415926536);
1430/// assert_eq!(asec(1.0), 0.0);
1431/// assert_eq!(asec(1.1547005384), 0.5235987756);
1432/// assert_eq!(asec(1.4142135623), 0.7853981634);
1433/// assert_eq!(asec(2.0), 1.0471975512);
1434/// assert_eq!(asec(999999999999.0), 1.5707963268);
1435/// assert_eq!(asec(inf), 1.5707963268);
1436/// ```
1437/// <small>End Fun Doc</small>
1438pub fn asec(x: f64) -> f64 {
1439 acos(fix(1.0 / x, 10))
1440}
1441
1442/// ### asec_deg(x)
1443///
1444/// Trigonometric Function
1445///
1446/// The `asec_deg` function computes the inverse secant of a number (in degrees),
1447/// returning the angle whose secant is equal to the input value.
1448///
1449/// ### Examples
1450/// ```rust
1451/// use mathlab::math::{asec_deg, INF_F64 as inf};
1452/// assert_eq!(asec_deg(-inf), 90.0);
1453/// assert_eq!(asec_deg(-999999999999.0), 90.0);
1454/// assert_eq!(asec_deg(-1.0), 180.0);
1455/// assert_eq!(asec_deg(1.0), 0.0);
1456/// assert_eq!(asec_deg(1.1547005384), 30.0);
1457/// assert_eq!(asec_deg(1.4142135623), 45.0);
1458/// assert_eq!(asec_deg(2.0), 60.0);
1459/// assert_eq!(asec_deg(999999999999.0), 90.0);
1460/// assert_eq!(asec_deg(inf), 90.0);
1461/// ```
1462/// <small>End Fun Doc</small>
1463pub fn asec_deg(x: f64) -> f64 {
1464 acos_deg(1.0 / x)
1465}
1466
1467/// ### cot(x)
1468///
1469/// Trigonometric Function
1470///
1471/// The `cot` function computes the cotangent of a number (in radians).
1472///
1473/// ### Examples
1474/// ```rust
1475/// use mathlab::math::{cot, INF_F64 as inf};
1476/// assert_eq!(cot(0.0), inf);
1477/// assert_eq!(cot(1e-10), 1e+10);
1478/// assert_eq!(cot(1e-10), 10000000000.0);
1479/// assert_eq!(cot(0.5235987756), 1.7320508076);
1480/// assert_eq!(cot(0.7853981634), 1.0);
1481/// assert_eq!(cot(1.0471975512), 0.5773502692);
1482/// assert_eq!(cot(1.5707963268), 0.0);
1483/// assert_eq!(cot(3.1415926536), inf);
1484/// assert_eq!(cot(4.7123889804), 0.0);
1485/// assert_eq!(cot(6.2831853072), inf);
1486/// ```
1487/// <small>End Fun Doc</small>
1488pub fn cot(x: f64) -> f64 {
1489 if abs(x) <= 1e-10 {
1490 1.0 / tan(x)
1491 } else {
1492 fix(cos(x) / sin(x), 10)
1493 }
1494}
1495
1496/// ### cot_deg(x)
1497///
1498/// Trigonometric Function
1499///
1500/// The `cot_deg` function computes the cotangent of an angle given in degrees.
1501///
1502/// ### Examples
1503/// ```rust
1504/// use mathlab::math::{cot_deg, INF_F64 as inf};
1505/// assert_eq!(cot_deg(0.0), inf);
1506/// assert_eq!(cot_deg(30.0), 1.7320508076);
1507/// assert_eq!(cot_deg(45.0), 1.0);
1508/// assert_eq!(cot_deg(60.0), 0.5773502692);
1509/// assert_eq!(cot_deg(90.0), 0.0);
1510/// assert_eq!(cot_deg(180.0), inf);
1511/// assert_eq!(cot_deg(270.0), 0.0);
1512/// assert_eq!(cot_deg(360.0), inf);
1513/// ```
1514/// <small>End Fun Doc</small>
1515pub fn cot_deg(x: f64) -> f64 {
1516 cot(deg_to_rad(x))
1517}
1518
1519/// ### acot(x)
1520///
1521/// Trigonometric Function
1522///
1523/// The `acot` function computes the inverse cotangent of a number (in radians),
1524/// returning the angle whose cotangent is equal to the input value.
1525///
1526/// ### Examples
1527/// ```rust
1528/// use mathlab::math::{acot, INF_F64 as inf};
1529/// assert_eq!(acot(-inf), 0.0);
1530/// assert_eq!(acot(1.7320508076), 0.5235987756);
1531/// assert_eq!(acot(1.0), 0.7853981634);
1532/// assert_eq!(acot(0.5773502692), 1.0471975512);
1533/// assert_eq!(acot(0.0), 1.5707963268);
1534/// assert_eq!(acot(10000000000.0), 1e-10);
1535/// assert_eq!(acot(1e+10), 1e-10);
1536/// assert_eq!(acot(inf), 0.0);
1537/// ```
1538/// <small>End Fun Doc</small>
1539pub fn acot(x: f64) -> f64 {
1540 atan(1.0 / x)
1541}
1542
1543/// ### acot_deg(x)
1544///
1545/// Trigonometric Function
1546///
1547/// The `acot_deg` function computes the inverse cotangent of a number (in degrees),
1548/// returning the angle whose cotangent is equal to the input value.
1549///
1550/// ### Examples
1551/// ```rust
1552/// use mathlab::math::{acot_deg, INF_F64 as inf};
1553/// assert_eq!(acot_deg(-inf), 0.0);
1554/// assert_eq!(acot_deg(1.7320508076), 30.0);
1555/// assert_eq!(acot_deg(1.0), 45.0);
1556/// assert_eq!(acot_deg(0.5773502692), 60.0);
1557/// assert_eq!(acot_deg(0.0), 90.0);
1558/// assert_eq!(acot_deg(10000000000.0), 5.729578e-9);
1559/// assert_eq!(acot_deg(1e+10), 5.729578e-9);
1560/// assert_eq!(acot_deg(inf), 0.0);
1561/// ```
1562/// <small>End Fun Doc</small>
1563pub fn acot_deg(x: f64) -> f64 {
1564 atan_deg(1.0 / x)
1565}
1566
1567/// ### sinh(x)
1568///
1569/// Hyperbolic Function
1570///
1571/// The `sinh` function computes the hyperbolic sine of a number (in radians).
1572///
1573/// ### Equation
1574///
1575/// std library -> x.sinh() ≈ (exp(x) - exp(-x)) / 2.0
1576///
1577/// ### Examples
1578/// ```rust
1579/// use mathlab::math::{sinh, INF_F64 as inf};
1580/// assert_eq!(sinh(0.0), 0.0);
1581/// assert_eq!(sinh(0.523598775598299), 0.547853473888040);
1582/// assert_eq!(sinh(3.141592653589793), 11.548739357257748);
1583/// assert_eq!(sinh(6.283185307179586), 267.74489404101644);
1584/// assert_eq!(sinh(inf), inf);
1585/// ```
1586/// <small>End Fun Doc</small>
1587pub fn sinh(x: f64) -> f64 {
1588 fix(x.sinh(), 15)
1589}
1590
1591/// ### sinh_deg(x)
1592///
1593/// Hyperbolic Function
1594///
1595/// The `sinh_deg` function computes the hyperbolic sine of a number (in degrees).
1596///
1597/// ### Examples
1598/// ```rust
1599/// use mathlab::math::{sinh_deg, INF_F64 as inf};
1600/// assert_eq!(sinh_deg(0.0), 0.0);
1601/// assert_eq!(sinh_deg(30.0), 0.547853473888040);
1602/// assert_eq!(sinh_deg(180.0), 11.548739357257748);
1603/// assert_eq!(sinh_deg(360.0), 267.74489404101644);
1604/// assert_eq!(sinh_deg(inf), inf);
1605/// ```
1606/// <small>End Fun Doc</small>
1607pub fn sinh_deg(x: f64) -> f64 {
1608 fix((x * 3.141592653589793 / 180.0).sinh(), 15)
1609}
1610
1611/// ### cosh(x)
1612///
1613/// Hyperbolic Function
1614///
1615/// The `cosh` function computes the hyperbolic cosine of a number (in radians).
1616///
1617/// ### Equation
1618///
1619/// std library -> x.cosh() ≈ (exp(x) + exp(-x)) / 2.0
1620///
1621/// ### Examples
1622/// ```rust
1623/// use mathlab::math::{cosh, INF_F64 as inf};
1624/// assert_eq!(cosh(0.0), 1.0);
1625/// assert_eq!(cosh(0.523598775598299), 1.140238321076429);
1626/// assert_eq!(cosh(3.141592653589793), 11.591953275521519);
1627/// assert_eq!(cosh(6.283185307179586), 267.7467614837482);
1628/// assert_eq!(cosh(inf), inf);
1629/// ```
1630/// <small>End Fun Doc</small>
1631pub fn cosh(x: f64) -> f64 {
1632 fix(x.cosh(), 15)
1633}
1634
1635/// ### cosh_deg(x)
1636///
1637/// Hyperbolic Function
1638///
1639/// The `cosh_deg` function computes the hyperbolic cosine of a number (in degrees).
1640///
1641/// ### Examples
1642/// ```rust
1643/// use mathlab::math::{cosh_deg, INF_F64 as inf};
1644/// assert_eq!(cosh_deg(0.0), 1.0);
1645/// assert_eq!(cosh_deg(30.0), 1.140238321076429);
1646/// assert_eq!(cosh_deg(180.0), 11.591953275521519);
1647/// assert_eq!(cosh_deg(360.0), 267.7467614837482);
1648/// assert_eq!(cosh_deg(inf), inf);
1649/// ```
1650/// <small>End Fun Doc</small>
1651pub fn cosh_deg(x: f64) -> f64 {
1652 fix((x * 3.141592653589793 / 180.0).cosh(), 15)
1653}
1654
1655/// ### tanh(x)
1656///
1657/// Hyperbolic Function
1658///
1659/// The `tanh` function computes the hyperbolic tangent of a number (in radians).
1660///
1661/// ### Equation
1662///
1663/// std library -> x.tanh() ≈ (exp(x) - exp(-x)) / (exp(x) + exp(-x))
1664///
1665/// ### Examples
1666/// ```rust
1667/// use mathlab::math::{tanh, INF_F64 as inf};
1668/// assert_eq!(tanh(0.0), 0.0);
1669/// assert_eq!(tanh(0.523598775598299), 0.480472778156452);
1670/// assert_eq!(tanh(3.141592653589793), 0.99627207622075);
1671/// assert_eq!(tanh(6.283185307179586), 0.999993025339611);
1672/// assert_eq!(tanh(inf), 1.0);
1673/// ```
1674/// <small>End Fun Doc</small>
1675pub fn tanh(x: f64) -> f64 {
1676 fix(x.tanh(), 15)
1677}
1678
1679/// ### tanh_deg(x)
1680///
1681/// Hyperbolic Function
1682///
1683/// The `tanh_deg` function computes the hyperbolic tangent of a number (in degrees).
1684///
1685/// ### Examples
1686/// ```rust
1687/// use mathlab::math::{tanh_deg, INF_F64 as inf};
1688/// assert_eq!(tanh_deg(0.0), 0.0);
1689/// assert_eq!(tanh_deg(30.0), 0.480472778156452);
1690/// assert_eq!(tanh_deg(180.0), 0.99627207622075);
1691/// assert_eq!(tanh_deg(360.0), 0.999993025339611);
1692/// assert_eq!(tanh_deg(inf), 1.0);
1693/// ```
1694/// <small>End Fun Doc</small>
1695pub fn tanh_deg(x: f64) -> f64 {
1696 fix((x * 3.141592653589793 / 180.0).tanh(), 15)
1697}
1698
1699/// ### csch(x)
1700///
1701/// Hyperbolic Function
1702///
1703/// The `csch` function computes the hyperbolic cosecant of a number (in radians).
1704///
1705/// ### Equation
1706///
1707/// csch(x) = 2.0 / (exp(x) - exp(-x))
1708///
1709/// ### Examples
1710/// ```rust
1711/// use mathlab::math::{csch, INF_F64 as inf};
1712/// assert_eq!(csch(0.523598775598299), 1.825305574687952);
1713/// assert_eq!(csch(3.141592653589793), 0.086589537530047);
1714/// assert_eq!(csch(6.283185307179586), 0.003734898488286);
1715/// assert_eq!(csch(inf), 0.0);
1716/// ```
1717/// <small>End Fun Doc</small>
1718pub fn csch(x: f64) -> f64 {
1719 fix(2.0 / (exp(x) - exp(-x)), 15)
1720}
1721
1722/// ### csch_deg(x)
1723///
1724/// Hyperbolic Function
1725///
1726/// The `csch_deg` function computes the hyperbolic cosecant of a number (in degrees).
1727///
1728/// ### Examples
1729/// ```rust
1730/// use mathlab::math::{csch_deg, INF_F64 as inf};
1731/// assert_eq!(csch_deg(30.0), 1.825305574687954);
1732/// assert_eq!(csch_deg(180.0), 0.086589537530047);
1733/// assert_eq!(csch_deg(360.0), 0.003734898488286);
1734/// assert_eq!(csch_deg(inf), 0.0);
1735/// ```
1736/// <small>End Fun Doc</small>
1737pub fn csch_deg(x: f64) -> f64 {
1738 fix(csch(x * 3.141592653589793 / 180.0), 15)
1739}
1740
1741/// ### sech(x)
1742///
1743/// Hyperbolic Function
1744///
1745/// The `sech` function computes the hyperbolic secant of a number (in radians).
1746///
1747/// ### Equation
1748///
1749/// sech(x) = 2.0 / (exp(x) + exp(-x))
1750///
1751/// ### Examples
1752/// ```rust
1753/// use mathlab::math::{sech, INF_F64 as inf};
1754/// assert_eq!(sech(0.0), 1.0);
1755/// assert_eq!(sech(0.523598775598299), 0.877009640454779);
1756/// assert_eq!(sech(3.141592653589793), 0.086266738334054);
1757/// assert_eq!(sech(6.283185307179586), 0.003734872438637);
1758/// assert_eq!(sech(inf), 0.0);
1759/// ```
1760/// <small>End Fun Doc</small>
1761pub fn sech(x: f64) -> f64 {
1762 fix(2.0 / (exp(x) + exp(-x)), 15)
1763}
1764
1765/// ### sech_deg(x)
1766///
1767/// Hyperbolic Function
1768///
1769/// The `sech_deg` function computes the hyperbolic secant of a number (in degrees).
1770///
1771/// ### Examples
1772/// ```rust
1773/// use mathlab::math::{sech_deg, INF_F64 as inf};
1774/// assert_eq!(sech_deg(0.0), 1.0);
1775/// assert_eq!(sech_deg(30.0), 0.877009640454779);
1776/// assert_eq!(sech_deg(180.0), 0.086266738334054);
1777/// assert_eq!(sech_deg(360.0), 0.003734872438637);
1778/// assert_eq!(sech_deg(inf), 0.0);
1779/// ```
1780/// <small>End Fun Doc</small>
1781pub fn sech_deg(x: f64) -> f64 {
1782 fix(sech(x * 3.141592653589793 / 180.0), 15)
1783}
1784
1785/// ### coth(x)
1786///
1787/// Hyperbolic Function
1788///
1789/// The `coth` function computes the hyperbolic cotangent of a number (in radians).
1790///
1791/// ### Equation
1792///
1793/// coth(x) = (exp(x) + exp(-x)) / (exp(x) - exp(-x))
1794///
1795/// ### Examples
1796/// ```rust
1797/// use mathlab::math::{coth, INF_F64 as inf};
1798/// assert_eq!(coth(0.0), inf);
1799/// assert_eq!(coth(0.523598775598299), 2.081283363933637);
1800/// assert_eq!(coth(3.141592653589793), 1.003741873197321);
1801/// assert_eq!(coth(6.283185307179586), 1.000006974709036);
1802/// ```
1803/// <small>End Fun Doc</small>
1804pub fn coth(x: f64) -> f64 {
1805 fix((exp(x) + exp(-x)) / (exp(x) - exp(-x)), 15)
1806}
1807
1808/// ### coth_deg(x)
1809///
1810/// Hyperbolic Function
1811///
1812/// The `coth_deg` function computes the hyperbolic cotangent of a number (in degrees).
1813///
1814/// ### Examples
1815/// ```rust
1816/// use mathlab::math::{coth_deg, INF_F64 as inf};
1817/// assert_eq!(coth_deg(0.0), inf);
1818/// assert_eq!(coth_deg(30.0), 2.081283363933638);
1819/// assert_eq!(coth_deg(180.0), 1.003741873197321);
1820/// assert_eq!(coth_deg(360.0), 1.000006974709036);
1821/// ```
1822/// <small>End Fun Doc</small>
1823pub fn coth_deg(x: f64) -> f64 {
1824 fix(coth(x * 3.141592653589793 / 180.0), 15)
1825}
1826
1827/// ### asinh(x)
1828///
1829/// Inverse Hyperbolic Function
1830///
1831/// The `asinh` function computes the inverse hyperbolic sine of a number (in radians).
1832///
1833/// ### Equation
1834///
1835/// std library -> x.asinh() = ln(x + sqrt(sqr(x) + 1.0))
1836///
1837/// ### Examples
1838/// ```rust
1839/// use mathlab::math::{asinh, INF_F64 as inf};
1840/// assert_eq!(asinh(0.0), 0.0);
1841/// assert_eq!(asinh(0.547853473888040), 0.523598775598299);
1842/// assert_eq!(asinh(11.548739357257748), 3.141592653589793);
1843/// assert_eq!(asinh(267.74489404101644), 6.283185307179586);
1844/// assert_eq!(asinh(inf), inf);
1845/// ```
1846/// <small>End Fun Doc</small>
1847pub fn asinh(x: f64) -> f64 {
1848 fix(x.asinh(), 15)
1849}
1850
1851/// ### asinh_deg(x)
1852///
1853/// Inverse Hyperbolic Function
1854///
1855/// The `asinh_deg` function computes the inverse hyperbolic sine of a number (in degrees).
1856///
1857/// ### Examples
1858/// ```rust
1859/// use mathlab::math::{asinh_deg, INF_F64 as inf};
1860/// assert_eq!(asinh_deg(0.0), 0.0);
1861/// assert_eq!(asinh_deg(0.547853473888040), 30.0);
1862/// assert_eq!(asinh_deg(11.548739357257748), 180.0);
1863/// assert_eq!(asinh_deg(267.74489404101644), 360.0);
1864/// assert_eq!(asinh_deg(inf), inf);
1865/// ```
1866/// <small>End Fun Doc</small>
1867pub fn asinh_deg(x: f64) -> f64 {
1868 fix64(x.asinh() * 180.0 / 3.141592653589793)
1869}
1870
1871/// ### acosh(x)
1872///
1873/// Inverse Hyperbolic Function
1874///
1875/// The `acosh` function computes the inverse hyperbolic cosine of a number (in radians).
1876///
1877/// ### Equation
1878///
1879/// std library -> x.acosh() = ln(x + sqrt(sqr(x) - 1.0))
1880///
1881/// ### Examples
1882/// ```rust
1883/// use mathlab::math::{acosh, INF_F64 as inf};
1884/// assert_eq!(acosh(1.0), 0.0);
1885/// assert_eq!(acosh(1.140238321076429), 0.523598775598299);
1886/// assert_eq!(acosh(11.591953275521519), 3.141592653589793);
1887/// assert_eq!(acosh(267.7467614837482), 6.283185307179586);
1888/// assert_eq!(acosh(inf), inf);
1889/// ```
1890/// <small>End Fun Doc</small>
1891pub fn acosh(x: f64) -> f64 {
1892 fix(x.acosh(), 15)
1893}
1894
1895/// ### acosh_deg(x)
1896///
1897/// Inverse Hyperbolic Function
1898///
1899/// The `acosh_deg` function computes the inverse hyperbolic cosine of a number (in degrees).
1900///
1901/// ### Examples
1902/// ```rust
1903/// use mathlab::math::{acosh_deg, INF_F64 as inf};
1904/// assert_eq!(acosh_deg(1.0), 0.0);
1905/// assert_eq!(acosh_deg(1.140238321076429), 30.0);
1906/// assert_eq!(acosh_deg(11.591953275521519), 180.0);
1907/// assert_eq!(acosh_deg(267.7467614837482), 360.0);
1908/// assert_eq!(acosh_deg(inf), inf);
1909/// ```
1910/// <small>End Fun Doc</small>
1911pub fn acosh_deg(x: f64) -> f64 {
1912 fix64(x.acosh() * 180.0 / 3.141592653589793)
1913}
1914
1915/// ### atanh(x)
1916///
1917/// Inverse Hyperbolic Function
1918///
1919/// The `atanh` function computes the inverse hyperbolic tangent of a number (in radians).
1920///
1921/// ### Equation
1922///
1923/// std library -> x.atanh() = 0.5 * ln((1.0 + x) / (1.0 - x))
1924///
1925/// ### Examples
1926/// ```rust
1927/// use mathlab::math::{atanh, INF_F64 as inf};
1928/// assert_eq!(atanh(0.0), 0.0);
1929/// assert_eq!(atanh(0.480472778156452), 0.523598775598299);
1930/// assert_eq!(atanh(0.99627207622075), 3.141592653589798);
1931/// assert_eq!(atanh(0.999993025339611), 6.283185307206486);
1932/// assert_eq!(atanh(1.0), inf);
1933/// ```
1934/// <small>End Fun Doc</small>
1935pub fn atanh(x: f64) -> f64 {
1936 fix(x.atanh(), 15)
1937}
1938
1939/// ### atanh_deg(x)
1940///
1941/// Inverse Hyperbolic Function
1942///
1943/// The `atanh_deg` function computes the inverse hyperbolic tangent of a number (in degrees).
1944///
1945/// ### Examples
1946/// ```rust
1947/// use mathlab::math::{atanh_deg, INF_F64 as inf};
1948/// assert_eq!(atanh_deg(0.0), 0.0);
1949/// assert_eq!(atanh_deg(0.480472778156452), 30.0);
1950/// assert_eq!(atanh_deg(0.99627207622075), 180.0);
1951/// assert_eq!(atanh_deg(0.999993025339611), 360.0);
1952/// assert_eq!(atanh_deg(1.0), inf);
1953/// ```
1954/// <small>End Fun Doc</small>
1955pub fn atanh_deg(x: f64) -> f64 {
1956 fix64(x.atanh() * 180.0 / 3.141592653589793)
1957}
1958
1959/// ### acsch(x)
1960///
1961/// Inverse Hyperbolic Function
1962///
1963/// The `acsch` function computes the inverse hyperbolic cosecant of a number (in radians).
1964///
1965/// ### Equation
1966///
1967/// acsch(x) = (1.0 / x).asinh() = ln((1.0 / x) + sqrt((1.0 / sqr(x)) + 1.0))
1968///
1969/// ### Examples
1970/// ```rust
1971/// use mathlab::math::{acsch, INF_F64 as inf};
1972/// assert_eq!(acsch(0.0), inf);
1973/// assert_eq!(acsch(1.825305574687952), 0.523598775598299);
1974/// assert_eq!(acsch(0.086589537530047), 3.141592653589793);
1975/// assert_eq!(acsch(0.003734898488286), 6.283185307179499);
1976/// ```
1977/// <small>End Fun Doc</small>
1978pub fn acsch(x: f64) -> f64 {
1979 fix((1.0 / x).asinh(), 15)
1980}
1981
1982/// ### acsch_deg(x)
1983///
1984/// Inverse Hyperbolic Function
1985///
1986/// The `acsch_deg` function computes the inverse hyperbolic cosecant of a number (in degrees).
1987///
1988/// ### Examples
1989/// ```rust
1990/// use mathlab::math::{acsch_deg, INF_F64 as inf};
1991/// assert_eq!(acsch_deg(0.0), inf);
1992/// assert_eq!(acsch_deg(1.825305574687952), 30.0);
1993/// assert_eq!(acsch_deg(0.086589537530047), 180.0);
1994/// assert_eq!(acsch_deg(0.003734898488286), 360.0);
1995/// ```
1996/// <small>End Fun Doc</small>
1997pub fn acsch_deg(x: f64) -> f64 {
1998 fix64((1.0 / x).asinh() * 180.0 / 3.141592653589793)
1999}
2000
2001/// ### asech(x)
2002///
2003/// Inverse Hyperbolic Function
2004///
2005/// The `asech` function computes the inverse hyperbolic secant of a number (in radians).
2006///
2007/// ### Equation
2008///
2009/// asech(x) = (1.0 / x).acosh() = = ln((1.0 / x) + sqrt((1.0 / sqr(x)) - 1.0))
2010///
2011/// ### Examples
2012/// ```rust
2013/// use mathlab::math::{asech, INF_F64 as inf};
2014/// assert_eq!(asech(0.0), inf);
2015/// assert_eq!(asech(1.0), 0.0);
2016/// assert_eq!(asech(0.877009640454779), 0.523598775598299);
2017/// assert_eq!(asech(0.086266738334054), 3.141592653589798);
2018/// assert_eq!(asech(0.003734872438637), 6.28318530717962);
2019/// ```
2020/// <small>End Fun Doc</small>
2021pub fn asech(x: f64) -> f64 {
2022 fix((1.0 / x).acosh(), 15)
2023}
2024
2025/// ### asech_deg(x)
2026///
2027/// Inverse Hyperbolic Function
2028///
2029/// The `asech_deg` function computes the inverse hyperbolic secant of a number (in degrees).
2030///
2031/// ### Examples
2032/// ```rust
2033/// use mathlab::math::{asech_deg, INF_F64 as inf};
2034/// assert_eq!(asech_deg(0.0), inf);
2035/// assert_eq!(asech_deg(1.0), 0.0);
2036/// assert_eq!(asech_deg(0.877009640454779), 30.0);
2037/// assert_eq!(asech_deg(0.086266738334054), 180.0);
2038/// assert_eq!(asech_deg(0.003734872438637), 360.0);
2039/// ```
2040/// <small>End Fun Doc</small>
2041pub fn asech_deg(x: f64) -> f64 {
2042 fix64((1.0 / x).acosh() * 180.0 / 3.141592653589793)
2043}
2044
2045/// ### acoth(x)
2046///
2047/// Inverse Hyperbolic Function
2048///
2049/// The `acoth` function computes the inverse hyperbolic cotangent of a number (in radians).
2050///
2051/// ### Equation
2052///
2053/// acoth(x) = (1.0 / x).atanh() = 0.5 * ln((x + 1.0) / (x - 1.0))
2054///
2055/// ### Examples
2056/// ```rust
2057/// use mathlab::math::{acoth, INF_F64 as inf};
2058/// assert_eq!(acoth(inf), 0.0);
2059/// assert_eq!(acoth(2.081283363933637), 0.523598775598299);
2060/// assert_eq!(acoth(1.003741873197321), 3.141592653589813);
2061/// assert_eq!(acoth(1.000006974709036), 6.283185307142813);
2062/// ```
2063/// <small>End Fun Doc</small>
2064pub fn acoth(x: f64) -> f64 {
2065 fix((1.0 / x).atanh(), 15)
2066}
2067
2068/// ### acoth_deg(x)
2069///
2070/// Inverse Hyperbolic Function
2071///
2072/// The `acoth_deg` function computes the inverse hyperbolic cotangent of a number (in degrees).
2073///
2074/// ### Examples
2075/// ```rust
2076/// use mathlab::math::{acoth_deg, INF_F64 as inf};
2077/// assert_eq!(acoth_deg(inf), 0.0);
2078/// assert_eq!(acoth_deg(2.081283363933637), 30.0);
2079/// assert_eq!(acoth_deg(1.003741873197321), 180.0);
2080/// assert_eq!(acoth_deg(1.000006974709036), 360.0);
2081/// ```
2082/// <small>End Fun Doc</small>
2083pub fn acoth_deg(x: f64) -> f64 {
2084 fix64((1.0 / x).atanh() * 180.0 / 3.141592653589793)
2085}