nstd_sys/
math.rs

1//! High level math operations.
2//!
3//! This library provides access to math functions that require the use of the "std" feature.
4use crate::{NSTDFloat32, NSTDFloat64, NSTDInt32};
5use nstdapi::nstdapi;
6
7/// Returns the absolute value of `x`.
8///
9/// # Parameters:
10///
11/// - `NSTDFloat32 x` - The value.
12///
13/// # Returns
14///
15/// `NSTDFloat32 abs` - The absolute value of `x`.
16#[inline]
17#[nstdapi]
18pub fn nstd_math_abs_f32(x: NSTDFloat32) -> NSTDFloat32 {
19    x.abs()
20}
21/// Returns the absolute value of `x`.
22///
23/// # Parameters:
24///
25/// - `NSTDFloat64 x` - The value.
26///
27/// # Returns
28///
29/// `NSTDFloat64 abs` - The absolute value of `x`.
30#[inline]
31#[nstdapi]
32pub fn nstd_math_abs_f64(x: NSTDFloat64) -> NSTDFloat64 {
33    x.abs()
34}
35
36/// Rounds the value `x` down to the closest integral value.
37///
38/// # Parameters:
39///
40/// - `NSTDFloat32 x` - The value.
41///
42/// # Returns
43///
44/// `NSTDFloat32 value` - The value rounded down to the nearest integral value.
45#[inline]
46#[nstdapi]
47pub fn nstd_math_floor_f32(x: NSTDFloat32) -> NSTDFloat32 {
48    x.floor()
49}
50/// Rounds the value `x` down to the closest integral value.
51///
52/// # Parameters:
53///
54/// - `NSTDFloat64 x` - The value.
55///
56/// # Returns
57///
58/// `NSTDFloat64 value` - The value rounded down to the nearest integral value.
59#[inline]
60#[nstdapi]
61pub fn nstd_math_floor_f64(x: NSTDFloat64) -> NSTDFloat64 {
62    x.floor()
63}
64
65/// Rounds the value `x` up to the closest integral value.
66///
67/// # Parameters:
68///
69/// - `NSTDFloat32 x` - The value.
70///
71/// # Returns
72///
73/// `NSTDFloat32 value` - The value rounded up to the nearest integral value.
74#[inline]
75#[nstdapi]
76pub fn nstd_math_ceil_f32(x: NSTDFloat32) -> NSTDFloat32 {
77    x.ceil()
78}
79/// Rounds the value `x` up to the closest integral value.
80///
81/// # Parameters:
82///
83/// - `NSTDFloat64 x` - The value.
84///
85/// # Returns
86///
87/// `NSTDFloat64 value` - The value rounded up to the nearest integral value.
88#[inline]
89#[nstdapi]
90pub fn nstd_math_ceil_f64(x: NSTDFloat64) -> NSTDFloat64 {
91    x.ceil()
92}
93
94/// Raises `x` to an integral power.
95///
96/// # Parameters:
97///
98/// - `NSTDFloat32 x` - The value.
99///
100/// - `NSTDInt32 exp` - The exponent.
101///
102/// # Returns
103///
104/// `NSTDFloat32 pow` - `x` raised to the power of `exp`.
105#[inline]
106#[nstdapi]
107pub fn nstd_math_pow_f32(x: NSTDFloat32, exp: NSTDInt32) -> NSTDFloat32 {
108    x.powi(exp)
109}
110/// Raises `x` to an integral power.
111///
112/// # Parameters:
113///
114/// - `NSTDFloat64 x` - The value.
115///
116/// - `NSTDInt32 exp` - The exponent.
117///
118/// # Returns
119///
120/// `NSTDFloat64 pow` - `x` raised to the power of `exp`.
121#[inline]
122#[nstdapi]
123pub fn nstd_math_pow_f64(x: NSTDFloat64, exp: NSTDInt32) -> NSTDFloat64 {
124    x.powi(exp)
125}
126
127/// Computes the square root of `x`.
128///
129/// # Parameters:
130///
131/// - `NSTDFloat32 x` - The value.
132///
133/// # Returns
134///
135/// `NSTDFloat32 sqrt` - The square root of `x`.
136#[inline]
137#[nstdapi]
138pub fn nstd_math_sqrt_f32(x: NSTDFloat32) -> NSTDFloat32 {
139    x.sqrt()
140}
141/// Computes the square root of `x`.
142///
143/// # Parameters:
144///
145/// - `NSTDFloat64 x` - The value.
146///
147/// # Returns
148///
149/// `NSTDFloat64 sqrt` - The square root of `x`.
150#[inline]
151#[nstdapi]
152pub fn nstd_math_sqrt_f64(x: NSTDFloat64) -> NSTDFloat64 {
153    x.sqrt()
154}
155
156/// Computes the sine of `x`.
157///
158/// # Parameters:
159///
160/// - `NSTDFloat32 x` - The value.
161///
162/// # Returns
163///
164/// `NSTDFloat32 sin` - The sine value of `x`.
165#[inline]
166#[nstdapi]
167pub fn nstd_math_sin_f32(x: NSTDFloat32) -> NSTDFloat32 {
168    x.sin()
169}
170/// Computes the sine of `x`.
171///
172/// # Parameters:
173///
174/// - `NSTDFloat64 x` - The value.
175///
176/// # Returns
177///
178/// `NSTDFloat64 sin` - The sine value of `x`.
179#[inline]
180#[nstdapi]
181pub fn nstd_math_sin_f64(x: NSTDFloat64) -> NSTDFloat64 {
182    x.sin()
183}
184
185/// Computes the cosine of `x`.
186///
187/// # Parameters:
188///
189/// - `NSTDFloat32 x` - The value.
190///
191/// # Returns
192///
193/// `NSTDFloat32 cos` - The cosine value of `x`.
194#[inline]
195#[nstdapi]
196pub fn nstd_math_cos_f32(x: NSTDFloat32) -> NSTDFloat32 {
197    x.cos()
198}
199/// Computes the cosine of `x`.
200///
201/// # Parameters:
202///
203/// - `NSTDFloat64 x` - The value.
204///
205/// # Returns
206///
207/// `NSTDFloat64 cos` - The cosine value of `x`.
208#[inline]
209#[nstdapi]
210pub fn nstd_math_cos_f64(x: NSTDFloat64) -> NSTDFloat64 {
211    x.cos()
212}
213
214/// Computes the tangent of `x`.
215///
216/// # Parameters:
217///
218/// - `NSTDFloat32 x` - The value.
219///
220/// # Returns
221///
222/// `NSTDFloat32 tan` - The tangent value of `x`.
223#[inline]
224#[nstdapi]
225pub fn nstd_math_tan_f32(x: NSTDFloat32) -> NSTDFloat32 {
226    x.tan()
227}
228/// Computes the tangent of `x`.
229///
230/// # Parameters:
231///
232/// - `NSTDFloat64 x` - The value.
233///
234/// # Returns
235///
236/// `NSTDFloat64 tan` - The tangent value of `x`.
237#[inline]
238#[nstdapi]
239pub fn nstd_math_tan_f64(x: NSTDFloat64) -> NSTDFloat64 {
240    x.tan()
241}
242
243/// Computes the arcsine of `x`.
244///
245/// # Parameters:
246///
247/// - `NSTDFloat32 x` - The value.
248///
249/// # Returns
250///
251/// `NSTDFloat32 asin` - The arcsine value of `x`.
252#[inline]
253#[nstdapi]
254pub fn nstd_math_asin_f32(x: NSTDFloat32) -> NSTDFloat32 {
255    x.asin()
256}
257/// Computes the arcsine of `x`.
258///
259/// # Parameters:
260///
261/// - `NSTDFloat64 x` - The value.
262///
263/// # Returns
264///
265/// `NSTDFloat64 asin` - The arcsine value of `x`.
266#[inline]
267#[nstdapi]
268pub fn nstd_math_asin_f64(x: NSTDFloat64) -> NSTDFloat64 {
269    x.asin()
270}
271
272/// Computes the arccosine of `x`.
273///
274/// # Parameters:
275///
276/// - `NSTDFloat32 x` - The value.
277///
278/// # Returns
279///
280/// `NSTDFloat32 acos` - The arccosine value of `x`.
281#[inline]
282#[nstdapi]
283pub fn nstd_math_acos_f32(x: NSTDFloat32) -> NSTDFloat32 {
284    x.acos()
285}
286/// Computes the arccosine of `x`.
287///
288/// # Parameters:
289///
290/// - `NSTDFloat64 x` - The value.
291///
292/// # Returns
293///
294/// `NSTDFloat64 acos` - The arccosine value of `x`.
295#[inline]
296#[nstdapi]
297pub fn nstd_math_acos_f64(x: NSTDFloat64) -> NSTDFloat64 {
298    x.acos()
299}
300
301/// Computes the arctangent of `x`.
302///
303/// # Parameters:
304///
305/// - `NSTDFloat32 x` - The value.
306///
307/// # Returns
308///
309/// `NSTDFloat32 atan` - The arctangent value of `x`.
310#[inline]
311#[nstdapi]
312pub fn nstd_math_atan_f32(x: NSTDFloat32) -> NSTDFloat32 {
313    x.atan()
314}
315/// Computes the arctangent of `x`.
316///
317/// # Parameters:
318///
319/// - `NSTDFloat64 x` - The value.
320///
321/// # Returns
322///
323/// `NSTDFloat64 atan` - The arctangent value of `x`.
324#[inline]
325#[nstdapi]
326pub fn nstd_math_atan_f64(x: NSTDFloat64) -> NSTDFloat64 {
327    x.atan()
328}
329
330/// Computes the four quadrant arctangent of `x` & `y`.
331///
332/// # Parameters:
333///
334/// - `NSTDFloat32 x` - The value.
335///
336/// - `NSTDFloat32 y` - The second value.
337///
338/// # Returns
339///
340/// `NSTDFloat32 atan2` - The four quadrant arctangent of `x` & `y`.
341#[inline]
342#[nstdapi]
343pub fn nstd_math_atan2_f32(x: NSTDFloat32, y: NSTDFloat32) -> NSTDFloat32 {
344    x.atan2(y)
345}
346/// Computes the four quadrant arctangent of `x` & `y`.
347///
348/// # Parameters:
349///
350/// - `NSTDFloat64 x` - The value.
351///
352/// - `NSTDFloat64 y` - The second value.
353///
354/// # Returns
355///
356/// `NSTDFloat64 atan2` - The four quadrant arctangent of `x` & `y`.
357#[inline]
358#[nstdapi]
359pub fn nstd_math_atan2_f64(x: NSTDFloat64, y: NSTDFloat64) -> NSTDFloat64 {
360    x.atan2(y)
361}
362
363/// Computes the hyperbolic sine of `x`.
364///
365/// # Parameters:
366///
367/// - `NSTDFloat32 x` - The value.
368///
369/// # Returns
370///
371/// `NSTDFloat32 sinh` - The hyperbolic sine of `x`.
372#[inline]
373#[nstdapi]
374pub fn nstd_math_sinh_f32(x: NSTDFloat32) -> NSTDFloat32 {
375    x.sinh()
376}
377/// Computes the hyperbolic sine of `x`.
378///
379/// # Parameters:
380///
381/// - `NSTDFloat64 x` - The value.
382///
383/// # Returns
384///
385/// `NSTDFloat64 sinh` - The hyperbolic sine of `x`.
386#[inline]
387#[nstdapi]
388pub fn nstd_math_sinh_f64(x: NSTDFloat64) -> NSTDFloat64 {
389    x.sinh()
390}
391
392/// Computes the hyperbolic cosine of `x`.
393///
394/// # Parameters:
395///
396/// - `NSTDFloat32 x` - The value.
397///
398/// # Returns
399///
400/// `NSTDFloat32 cosh` - The hyperbolic cosine of `x`.
401#[inline]
402#[nstdapi]
403pub fn nstd_math_cosh_f32(x: NSTDFloat32) -> NSTDFloat32 {
404    x.cosh()
405}
406/// Computes the hyperbolic cosine of `x`.
407///
408/// # Parameters:
409///
410/// - `NSTDFloat64 x` - The value.
411///
412/// # Returns
413///
414/// `NSTDFloat64 cosh` - The hyperbolic cosine of `x`.
415#[inline]
416#[nstdapi]
417pub fn nstd_math_cosh_f64(x: NSTDFloat64) -> NSTDFloat64 {
418    x.cosh()
419}
420
421/// Computes the hyperbolic tangent of `x`.
422///
423/// # Parameters:
424///
425/// - `NSTDFloat32 x` - The value.
426///
427/// # Returns
428///
429/// `NSTDFloat32 tanh` - The hyperbolic tangent of `x`.
430#[inline]
431#[nstdapi]
432pub fn nstd_math_tanh_f32(x: NSTDFloat32) -> NSTDFloat32 {
433    x.tanh()
434}
435/// Computes the hyperbolic tangent of `x`.
436///
437/// # Parameters:
438///
439/// - `NSTDFloat64 x` - The value.
440///
441/// # Returns
442///
443/// `NSTDFloat64 tanh` - The hyperbolic tangent of `x`.
444#[inline]
445#[nstdapi]
446pub fn nstd_math_tanh_f64(x: NSTDFloat64) -> NSTDFloat64 {
447    x.tanh()
448}