1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
macro_rules! ctor_impls {
($ty:ident <F: $bound:ident>, $msg:literal) => {
impl<F: $bound> $ty<F> {
/// Creates a new checked float.
/// # Panics
#[doc = $msg]
/// Note that this fn will *not* panic in release mode, unless the `strict` feature flag is set.
#[track_caller]
pub fn new(val: F) -> Self {
if $crate::STRICT {
$crate::unwrap_display(Self::try_new(val))
} else {
// SAFETY: lol
unsafe { Self::unchecked(val) }
}
}
}
};
}
macro_rules! eq_impls {
($ty:ident <F: $bound:ident>) => {
impl<F: $bound + $crate::ToOrd, Rhs: $crate::IntoInner<F> + Copy>
::core::cmp::PartialEq<Rhs> for $ty<F>
{
fn eq(&self, rhs: &Rhs) -> bool {
// we can ignore the case where `rhs` is NaN since
// we know that `self` is not NaN.
let rhs = (*rhs).into_inner();
self.val().total_eq(rhs)
}
}
impl<F: $bound + $crate::ToOrd> ::core::cmp::Eq for $ty<F> {}
};
}
macro_rules! ord_impls {
($ty:ident <F : $bound:ident>) => {
impl<F: $bound + $crate::ToOrd, Rhs: $crate::IntoInner<F> + Copy>
::core::cmp::PartialOrd<Rhs> for $ty<F>
{
fn partial_cmp(&self, rhs: &Rhs) -> Option<::core::cmp::Ordering> {
let rhs = (*rhs).into_inner();
let rhs = Self::try_new(rhs).ok()?.val().to_ord();
let lhs = self.val().to_ord();
Some(lhs.cmp(&rhs))
}
}
impl<F: $bound + $crate::ToOrd> ::core::cmp::Ord for $ty<F> {
fn cmp(&self, rhs: &Self) -> ::core::cmp::Ordering {
let lhs = self.val().to_ord();
let rhs = rhs.val().to_ord();
lhs.cmp(&rhs)
}
}
impl<F: $bound + $crate::ToOrd> $ty<F> {
/// Returns the larger of two floating point values.
#[must_use]
pub fn max(self, other: impl IntoInner<F>) -> Self {
let other = other.into_inner();
match self.partial_cmp(&other) {
Some(::core::cmp::Ordering::Greater) => unsafe { Self::unchecked(other) },
_ => self,
}
}
/// Returns the smaller of two floating point values.
#[must_use]
pub fn min(self, other: impl IntoInner<F>) -> Self {
let other = other.into_inner();
match self.partial_cmp(&other) {
Some(::core::cmp::Ordering::Less) => unsafe { Self::unchecked(other) },
_ => self,
}
}
}
};
}
macro_rules! round_impls {
($ty: ident <F : $bound: ident>) => {
impl<F: $bound + $crate::ops::Round> $ty<F> {
/// Rounds this floating point number to the previous whole number.
#[must_use]
pub fn floor(self) -> Self {
unsafe { Self::unchecked(self.val().floor()) }
}
/// Rounds this floating point number to the next whole number.
#[must_use]
pub fn ceil(self) -> Self {
unsafe { Self::unchecked(self.val().ceil()) }
}
/// Rounds this floating point number to the nearest whole number.
#[must_use]
pub fn round(self) -> Self {
unsafe { Self::unchecked(self.val().round()) }
}
/// Drops the fractional part of this floating point number.
#[must_use]
pub fn trunc(self) -> Self {
unsafe { Self::unchecked(self.val().trunc()) }
}
/// Returns the fractional part of this floating point number.
#[must_use]
pub fn fract(self) -> Self {
unsafe { Self::unchecked(self.val().fract()) }
}
}
};
}
macro_rules! signed_impls {
($ty: ident <F : $bound: ident>) => {
impl<F: $bound + $crate::ops::Signed> $ty<F> {
/// Computes the absolute value of self.
#[must_use]
pub fn abs(self) -> Self {
unsafe { Self::unchecked(self.val().abs()) }
}
/// Returns a number that represents the sign of self.
/// * `1.0` if the number is positive, `+0.0` or `INFINITY`
/// * `-1.0` if the number is negative, `-0.0` or `NEG_INFINITY`
#[must_use]
pub fn signum(self) -> Self {
unsafe { Self::unchecked(self.val().signum()) }
}
/// Returns true if self has a negative sign, including -0.0 and negative infinity.
#[must_use]
pub fn is_sign_negative(self) -> bool {
self.val().is_sign_negative()
}
/// Returns true if self has a positive sign, including +0.0 and positive infinity.
#[must_use]
pub fn is_sign_positive(self) -> bool {
self.val().is_sign_positive()
}
}
};
}
macro_rules! sum_impls {
($ty: ident <F : $bound: ident>, $err: ty, $msg: literal) => {
impl<F: $bound> $ty<F> {
/// Attempts to add two numbers.
/// # Errors
#[doc = $msg]
pub fn try_add(self, rhs: impl $crate::IntoInner<F>) -> Result<Self, $err>
where
F: ::core::ops::Add<Output = F>,
{
let val = self.val() + rhs.into_inner();
Self::try_new(val)
}
/// Attempts to subtract two numbers.
/// # Errors
#[doc = $msg]
pub fn try_sub(self, rhs: impl $crate::IntoInner<F>) -> Result<Self, $err>
where
F: ::core::ops::Sub<Output = F>,
{
let val = self.val() - rhs.into_inner();
Self::try_new(val)
}
}
impl<F: $bound + ::core::ops::Add<Output = F>, Rhs: $crate::IntoInner<F>>
::core::ops::Add<Rhs> for $ty<F>
{
type Output = Self;
#[track_caller]
fn add(self, rhs: Rhs) -> Self {
let val = self.val() + rhs.into_inner();
Self::new(val)
}
}
impl<F: $bound + ::core::ops::Sub<Output = F>, Rhs: $crate::IntoInner<F>>
::core::ops::Sub<Rhs> for $ty<F>
{
type Output = Self;
#[track_caller]
fn sub(self, rhs: Rhs) -> Self {
let val = self.val() - rhs.into_inner();
Self::new(val)
}
}
impl<F: $bound + ::core::ops::Add<Output = F>, Rhs: $crate::IntoInner<F>>
::core::ops::AddAssign<Rhs> for $ty<F>
{
#[track_caller]
fn add_assign(&mut self, rhs: Rhs) {
*self = *self + rhs.into_inner();
}
}
impl<F: $bound + ::core::ops::Sub<Output = F>, Rhs: $crate::IntoInner<F>>
::core::ops::SubAssign<Rhs> for $ty<F>
{
#[track_caller]
fn sub_assign(&mut self, rhs: Rhs) {
*self = *self - rhs.into_inner();
}
}
};
}
macro_rules! neg_impls {
($ty: ident <F : $bound: ident>, $err: ty, $msg: literal) => {
impl<F: $bound> $ty<F> {
/// Attempts to negate a number.
/// # Errors
#[doc = $msg]
pub fn try_neg(self) -> Result<Self, $err>
where
F: ::core::ops::Neg<Output = F>,
{
let val = -self.val();
Self::try_new(val)
}
}
impl<F: $bound + ::core::ops::Neg<Output = F>> ::core::ops::Neg for $ty<F> {
type Output = Self;
#[track_caller]
fn neg(self) -> Self {
let val = -self.val();
Self::new(val)
}
}
};
}
macro_rules! product_impls {
($ty: ident <F : $bound: ident>, $err: ty, $msg: literal) => {
impl<F: $bound> $ty<F> {
/// Attempts to multiply two numbers.
/// # Errors
#[doc = $msg]
pub fn try_mul(self, rhs: impl $crate::IntoInner<F>) -> Result<Self, $err>
where
F: ::core::ops::Mul<Output = F>,
{
let val = self.val() * rhs.into_inner();
Self::try_new(val)
}
/// Attempts to divide two numbers.
/// # Errors
#[doc = $msg]
pub fn try_div(self, rhs: impl $crate::IntoInner<F>) -> Result<Self, $err>
where
F: ::core::ops::Div<Output = F>,
{
let val = self.val() / rhs.into_inner();
Self::try_new(val)
}
/// Attempts to find the remainder of two numbers.
/// # Errors
#[doc = $msg]
pub fn try_rem(self, rhs: impl $crate::IntoInner<F>) -> Result<Self, $err>
where
F: ::core::ops::Rem<Output = F>,
{
let val = self.val() % rhs.into_inner();
Self::try_new(val)
}
}
impl<F: $bound + ::core::ops::Mul<Output = F>, Rhs: $crate::IntoInner<F>>
::core::ops::Mul<Rhs> for $ty<F>
{
type Output = Self;
#[track_caller]
fn mul(self, rhs: Rhs) -> Self {
let val = self.val() * rhs.into_inner();
Self::new(val)
}
}
impl<F: $bound + ::core::ops::Div<Output = F>, Rhs: $crate::IntoInner<F>>
::core::ops::Div<Rhs> for $ty<F>
{
type Output = Self;
#[track_caller]
fn div(self, rhs: Rhs) -> Self {
let val = self.val() / rhs.into_inner();
Self::new(val)
}
}
impl<F: $bound + ::core::ops::Rem<Output = F>, Rhs: $crate::IntoInner<F>>
::core::ops::Rem<Rhs> for $ty<F>
{
type Output = Self;
#[track_caller]
fn rem(self, rhs: Rhs) -> Self {
let val = self.val() % rhs.into_inner();
Self::new(val)
}
}
impl<F: $bound + ::core::ops::Mul<Output = F>, Rhs: $crate::IntoInner<F>>
::core::ops::MulAssign<Rhs> for $ty<F>
{
#[track_caller]
fn mul_assign(&mut self, rhs: Rhs) {
*self = *self * rhs.into_inner()
}
}
impl<F: $bound + ::core::ops::Div<Output = F>, Rhs: $crate::IntoInner<F>>
::core::ops::DivAssign<Rhs> for $ty<F>
{
#[track_caller]
fn div_assign(&mut self, rhs: Rhs) {
*self = *self / rhs.into_inner()
}
}
impl<F: $bound + ::core::ops::Rem<Output = F>, Rhs: $crate::IntoInner<F>>
::core::ops::RemAssign<Rhs> for $ty<F>
{
#[track_caller]
fn rem_assign(&mut self, rhs: Rhs) {
*self = *self % rhs.into_inner()
}
}
};
}
macro_rules! pow_methods {
($f: ident, $err: ty, $msg: literal) => {
/// Attempts to raise `self` to the power `n`.
/// # Errors
#[doc = $msg]
pub fn try_powf(self, n: impl $crate::IntoInner<F>) -> Result<Self, $err> {
let val = self.val().powf(n.into_inner());
Self::try_new(val)
}
/// Attempts to raise `self` to the power `n`.
/// # Errors
#[doc = $msg]
pub fn try_powi(self, n: i32) -> Result<Self, $err> {
let val = self.val().powi(n);
Self::try_new(val)
}
/// Raises `self` to the power `n`.
/// # Panics
#[doc = $msg]
#[track_caller]
#[must_use]
pub fn powf(self, n: impl $crate::IntoInner<F>) -> Self {
let val = self.val().powf(n.into_inner());
Self::new(val)
}
/// Raises `self` to the power `n`.
/// # Panics
#[doc = $msg]
#[track_caller]
#[must_use]
pub fn powi(self, n: i32) -> Self {
let val = self.val().powi(n);
Self::new(val)
}
};
}
macro_rules! recip_methods {
($f: ident, $err: ty, $msg: literal) => {
/// Attempts to compute the reciprocal (`1/x`) of `self`.
/// # Errors
#[doc = $msg]
pub fn try_recip(self) -> Result<Self, $err> {
let val = self.val().recip();
Self::try_new(val)
}
/// Computes the reciprocal (`1/x`) of `self`.
/// # Panics
#[doc = $msg]
#[track_caller]
#[must_use]
pub fn recip(self) -> Self {
let val = self.val().recip();
Self::new(val)
}
};
($f:ident) => {
/// Computes the reciprocal (`1/x`) of `self`.
#[must_use]
pub fn recip(self) -> Self {
// this macro arm assumes that `recip` always succeeds.
unsafe { Self::unchecked(self.val().recip()) }
}
};
}
macro_rules! sqrt_methods {
($f:ident, $err:ty, $msg:literal) => {
/// Attempts to find the square root of a number.
/// # Errors
#[doc = $msg]
pub fn try_sqrt(self) -> Result<Self, $err> {
let val = self.val().sqrt();
Self::try_new(val)
}
/// Computes the square root of a number.
/// # Panics
#[doc = $msg]
#[track_caller]
#[must_use]
pub fn sqrt(self) -> Self {
let val = self.val().sqrt();
Self::new(val)
}
};
($f:ident) => {
/// Computes the square root of a number.
#[must_use]
pub fn sqrt(self) -> Self {
let val = self.val().sqrt();
unsafe { Self::unchecked(val) }
}
};
}
macro_rules! cbrt_methods {
($f:ident) => {
/// Computes the cube root of a number.
#[must_use]
pub fn cbrt(self) -> Self {
// cube root is defined for any real value
let val = self.val().cbrt();
unsafe { Self::unchecked(val) }
}
};
}
macro_rules! hypot_methods {
($f:ident, $err: ty, $msg: literal) => {
/// Attempts to calculate the length of the hypotenuse of a right-angle triangle given legs of length `x` and `y`.
///
/// Equivalent to `sqrt(x^2 + y^2)`.
/// # Errors
#[doc = $msg]
pub fn try_hypot(self, other: impl $crate::IntoInner<F>) -> Result<Self, $err> {
let val = self.val().hypot(other.into_inner());
Self::try_new(val)
}
/// Calculates the length of the hypotenuse of a right-angle triangle given legs of length `x` and `y`.
/// # Panics
#[doc = $msg]
#[track_caller]
#[must_use]
pub fn hypot(self, other: impl $crate::IntoInner<F>) -> Self {
let val = self.val().hypot(other.into_inner());
Self::new(val)
}
};
}
macro_rules! exp_methodss {
($f:ident, $err:ty, $msg:literal) => {
/// Attempts to find `e^(self)`, the exponential function.
/// # Errors
#[doc = $msg]
pub fn try_exp(self) -> Result<Self, $err> {
let val = self.val().exp();
Self::try_new(val)
}
/// Attempts to find `2^(self)`.
/// # Errors
#[doc = $msg]
pub fn try_exp2(self) -> Result<Self, $err> {
let val = self.val().exp2();
Self::try_new(val)
}
/// Attempts to find `e^(self) - 1` in a way that is accurate even if the number is close to zero.
/// # Errors
#[doc = $msg]
pub fn try_exp_m1(self) -> Result<Self, $err> {
let val = self.val().exp_m1();
Self::try_new(val)
}
/// Computes `e^(self)`, the exponential function.
/// # Panics
#[doc = $msg]
#[track_caller]
#[must_use]
pub fn exp(self) -> Self {
let val = self.val().exp();
Self::new(val)
}
/// Computes `2^(self)`.
/// # Panics
#[doc = $msg]
#[track_caller]
#[must_use]
pub fn exp2(self) -> Self {
let val = self.val().exp2();
Self::new(val)
}
/// Computes `e^(self) - 1` more accurately than performing the operations separately.
/// # Panics
#[doc = $msg]
#[track_caller]
#[must_use]
pub fn exp_m1(self) -> Self {
let val = self.val().exp_m1();
Self::new(val)
}
};
}
macro_rules! log_methods {
($f:ident, $err:ty, $msg:literal) => {
/// Attempts to find the log base `b` of `self`.
/// # Errors
#[doc = $msg]
pub fn try_log(self, b: impl IntoInner<F>) -> Result<Self, $err> {
let val = self.val().log(b.into_inner());
Self::try_new(val)
}
/// Attempts to find the natural log (base e) of `self`.
/// # Errors
#[doc = $msg]
pub fn try_ln(self) -> Result<Self, $err> {
let val = self.val().ln();
Self::try_new(val)
}
/// Attempts to find the log base 2 of `self`.
/// # Errors
#[doc = $msg]
pub fn try_log2(self) -> Result<Self, $err> {
let val = self.val().log2();
Self::try_new(val)
}
/// Attempts to find the log base 10 of `self`.
/// # Errors
#[doc = $msg]
pub fn try_log10(self) -> Result<Self, $err> {
let val = self.val().log10();
Self::try_new(val)
}
/// Attempts to find `ln(1+n)` (natural logarithm) more accurately than if the operations were performed separately.
/// # Errors
#[doc = $msg]
pub fn try_ln_1p(self) -> Result<Self, $err> {
let val = self.val().ln_1p();
Self::try_new(val)
}
/// Computes the log base `b` of `self`.
/// # Panics
#[doc = $msg]
#[track_caller]
#[must_use]
pub fn log(self, b: impl IntoInner<F>) -> Self {
let val = self.val().log(b.into_inner());
Self::new(val)
}
/// Computes the natural log (base e) of `self`.
/// # Panics
#[doc = $msg]
#[track_caller]
#[must_use]
pub fn ln(self) -> Self {
let val = self.val().ln();
Self::new(val)
}
/// Computes the log base 2 of `self`.
/// # Panics
#[doc = $msg]
#[track_caller]
#[must_use]
pub fn log2(self) -> Self {
let val = self.val().log2();
Self::new(val)
}
/// Computes the log base 10 of `self`.
/// # Panics
#[doc = $msg]
#[track_caller]
#[must_use]
pub fn log10(self) -> Self {
let val = self.val().log10();
Self::new(val)
}
/// Computes `ln(1+n)` (natural logarithm) more accurately than if the operations were performed separately.
/// # Panics
#[doc = $msg]
#[track_caller]
#[must_use]
pub fn ln_1p(self) -> Self {
let val = self.val().ln_1p();
Self::new(val)
}
};
}
macro_rules! exp_impls {
($ty:ident <F : $bound:ident>, $err:ty, $msg:literal) => {
impl<F: $bound + $crate::ops::Exp> $ty<F> {
exp_methodss!(F, $err, $msg);
log_methods!(F, $err, $msg);
}
};
}
macro_rules! sin_cos_methods {
($f:ident, $err:ty, $msg:literal) => {
/// Attempts to compute the sine of a number (in radians).
/// # Errors
#[doc = $msg]
pub fn try_sin(self) -> Result<Self, $err> {
let val = self.val().sin();
Self::try_new(val)
}
/// Attempts to compute the cosine of a number (in radians).
/// # Errors
#[doc = $msg]
pub fn try_cos(self) -> Result<Self, $err> {
let val = self.val().cos();
Self::try_new(val)
}
/// Attempts to compute both the sine and cosine of a number simultaneously (in radians).
/// # Errors
#[doc = $msg]
pub fn try_sin_cos(self) -> Result<(Self, Self), $err> {
let (s, c) = self.val().sin_cos();
Ok((Self::try_new(s)?, Self::try_new(c)?))
}
/// Computes the sine of a number.
/// # Panics
#[doc = $msg]
#[track_caller]
#[must_use]
pub fn sin(self) -> Self {
let val = self.val().sin();
Self::new(val)
}
/// Computes the cosine of a number.
/// # Panics
#[doc = $msg]
#[track_caller]
#[must_use]
pub fn cos(self) -> Self {
let val = self.val().cos();
Self::new(val)
}
/// Computes the sine and cosine of a number simultaneously.
/// # Panics
#[doc = $msg]
#[track_caller]
#[must_use]
pub fn sin_cos(self) -> (Self, Self) {
let (s, c) = self.val().sin_cos();
(Self::new(s), Self::new(c))
}
};
($f:ident) => {
/// Computes the sine of a number.
#[must_use]
pub fn sin(self) -> Self {
// this macro arm assumes that sin/cos always succeed
unsafe { Self::unchecked(self.val().sin()) }
}
/// Computes the cosine of a number.
#[must_use]
pub fn cos(self) -> Self {
unsafe { Self::unchecked(self.val().cos()) }
}
/// Computes the sine and cosine of a number simultaneously.
#[must_use]
pub fn sin_cos(self) -> (Self, Self) {
let (s, c) = self.val().sin_cos();
unsafe { (Self::unchecked(s), Self::unchecked(c)) }
}
};
}
macro_rules! tan_methods {
($f:ident, $err:ty, $msg:literal) => {
/// Attempts to compute the tangent of a number (in radians).
/// # Errors
#[doc = $msg]
pub fn try_tan(self) -> Result<Self, $err> {
let val = self.val().tan();
Self::try_new(val)
}
/// Computes the tangent of a number.
/// # Panics
#[doc = $msg]
#[track_caller]
#[must_use]
pub fn tan(self) -> Self {
let val = self.val().tan();
Self::new(val)
}
};
}
macro_rules! asin_acos_methods {
($f:ident, $err:ty, $msg:literal) => {
/// Attempts to compute the arcsine of a number (in radians).
/// # Errors
#[doc = $msg]
pub fn try_asin(self) -> Result<Self, $err> {
let val = self.val().asin();
Self::try_new(val)
}
/// Attempts to compute the arccosine of a number (in radians).
/// # Errors
#[doc = $msg]
pub fn try_acos(self) -> Result<Self, $err> {
let val = self.val().acos();
Self::try_new(val)
}
/// Computes the arcsine of a number.
/// # Panics
#[doc = $msg]
#[track_caller]
#[must_use]
pub fn asin(self) -> Self {
let val = self.val().asin();
Self::new(val)
}
/// Computes the arccosine of a number.
/// # Panics
#[doc = $msg]
#[track_caller]
#[must_use]
pub fn acos(self) -> Self {
let val = self.val().acos();
Self::new(val)
}
};
}
macro_rules! atan_methods {
($f:ident, $err:ty, $msg:literal) => {
/// Attempts to compute the arccosine of a number (in radians).
/// # Errors
#[doc = $msg]
pub fn try_atan(self) -> Result<Self, $err> {
let val = self.val().atan();
Self::try_new(val)
}
/// Computes the arctangent of a number.
/// # Panics
#[doc = $msg]
#[track_caller]
#[must_use]
pub fn atan(self) -> Self {
let val = self.val().atan();
Self::new(val)
}
};
($f:ident) => {
/// Computes the arctangent of a number.
#[must_use]
pub fn atan(self) -> Self {
// this macro arm assuems tangent always succeeds
unsafe { Self::unchecked(self.val().atan()) }
}
};
}
macro_rules! atan2_methods {
($f:ident, $err:ty, $msg:literal) => {
/// Attempts to compute the four quadrant arctangent of self (`y`) and other (`x`) in radians.
/// # Errors
#[doc = $msg]
pub fn try_atan2(self, other: impl IntoInner<F>) -> Result<Self, $err> {
let val = self.val().atan2(other.into_inner());
Self::try_new(val)
}
/// Computes the four quadrant arctangent of self (`y`) and other (`x`) in radians.
/// # Panics
#[doc = $msg]
#[track_caller]
#[must_use]
pub fn atan2(self, other: impl IntoInner<F>) -> Self {
let val = self.val().atan2(other.into_inner());
Self::new(val)
}
};
}