Skip to content

Commit 0e97df2

Browse files
bors[bot]japaric
andcommitted
116: inline more functions; add more methods to F{32,64}Ext r=japaric a=japaric Co-authored-by: Jorge Aparicio <[email protected]>
2 parents 3c048e9 + 745b302 commit 0e97df2

20 files changed

+49
-56
lines changed

src/lib.rs

+18-38
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,27 @@
1414

1515
mod math;
1616

17-
#[cfg(todo)]
1817
use core::{f32, f64};
1918

2019
pub use math::*;
2120

2221
/// Approximate equality with 1 ULP of tolerance
2322
#[doc(hidden)]
23+
#[inline]
2424
pub fn _eqf(a: u32, b: u32) -> bool {
2525
(a as i32).wrapping_sub(b as i32).abs() <= 1
2626
}
2727

2828
#[doc(hidden)]
29+
#[inline]
2930
pub fn _eq(a: u64, b: u64) -> bool {
3031
(a as i64).wrapping_sub(b as i64).abs() <= 1
3132
}
3233

3334
/// Math support for `f32`
3435
///
3536
/// This trait is sealed and cannot be implemented outside of `libm`.
36-
pub trait F32Ext: private::Sealed {
37+
pub trait F32Ext: private::Sealed + Sized {
3738
fn floor(self) -> Self;
3839

3940
fn ceil(self) -> Self;
@@ -44,20 +45,17 @@ pub trait F32Ext: private::Sealed {
4445

4546
fn fdim(self, rhs: Self) -> Self;
4647

47-
#[cfg(todo)]
4848
fn fract(self) -> Self;
4949

5050
fn abs(self) -> Self;
5151

52-
#[cfg(todo)]
53-
fn signum(self) -> Self;
52+
// NOTE depends on unstable intrinsics::copysignf32
53+
// fn signum(self) -> Self;
5454

5555
fn mul_add(self, a: Self, b: Self) -> Self;
5656

57-
#[cfg(todo)]
5857
fn div_euc(self, rhs: Self) -> Self;
5958

60-
#[cfg(todo)]
6159
fn mod_euc(self, rhs: Self) -> Self;
6260

6361
// NOTE depends on unstable intrinsics::powif32
@@ -97,9 +95,11 @@ pub trait F32Ext: private::Sealed {
9795

9896
fn atan2(self, other: Self) -> Self;
9997

100-
#[cfg(todo)]
10198
#[inline]
102-
fn sin_cos(self) -> (Self, Self) {
99+
fn sin_cos(self) -> (Self, Self)
100+
where
101+
Self: Copy,
102+
{
103103
(self.sin(), self.cos())
104104
}
105105

@@ -113,13 +113,10 @@ pub trait F32Ext: private::Sealed {
113113

114114
fn tanh(self) -> Self;
115115

116-
#[cfg(todo)]
117116
fn asinh(self) -> Self;
118117

119-
#[cfg(todo)]
120118
fn acosh(self) -> Self;
121119

122-
#[cfg(todo)]
123120
fn atanh(self) -> Self;
124121
}
125122

@@ -149,7 +146,6 @@ impl F32Ext for f32 {
149146
fdimf(self, rhs)
150147
}
151148

152-
#[cfg(todo)]
153149
#[inline]
154150
fn fract(self) -> Self {
155151
self - self.trunc()
@@ -165,7 +161,6 @@ impl F32Ext for f32 {
165161
fmaf(self, a, b)
166162
}
167163

168-
#[cfg(todo)]
169164
#[inline]
170165
fn div_euc(self, rhs: Self) -> Self {
171166
let q = (self / rhs).trunc();
@@ -175,7 +170,6 @@ impl F32Ext for f32 {
175170
q
176171
}
177172

178-
#[cfg(todo)]
179173
#[inline]
180174
fn mod_euc(self, rhs: f32) -> f32 {
181175
let r = self % rhs;
@@ -296,7 +290,6 @@ impl F32Ext for f32 {
296290
tanhf(self)
297291
}
298292

299-
#[cfg(todo)]
300293
#[inline]
301294
fn asinh(self) -> Self {
302295
if self == f32::NEG_INFINITY {
@@ -306,7 +299,6 @@ impl F32Ext for f32 {
306299
}
307300
}
308301

309-
#[cfg(todo)]
310302
#[inline]
311303
fn acosh(self) -> Self {
312304
match self {
@@ -315,7 +307,6 @@ impl F32Ext for f32 {
315307
}
316308
}
317309

318-
#[cfg(todo)]
319310
#[inline]
320311
fn atanh(self) -> Self {
321312
0.5 * ((2.0 * self) / (1.0 - self)).ln_1p()
@@ -325,7 +316,7 @@ impl F32Ext for f32 {
325316
/// Math support for `f64`
326317
///
327318
/// This trait is sealed and cannot be implemented outside of `libm`.
328-
pub trait F64Ext: private::Sealed {
319+
pub trait F64Ext: private::Sealed + Sized {
329320
fn floor(self) -> Self;
330321

331322
fn ceil(self) -> Self;
@@ -336,20 +327,17 @@ pub trait F64Ext: private::Sealed {
336327

337328
fn fdim(self, rhs: Self) -> Self;
338329

339-
#[cfg(todo)]
340330
fn fract(self) -> Self;
341331

342332
fn abs(self) -> Self;
343333

344-
#[cfg(todo)]
345-
fn signum(self) -> Self;
334+
// NOTE depends on unstable intrinsics::copysignf64
335+
// fn signum(self) -> Self;
346336

347337
fn mul_add(self, a: Self, b: Self) -> Self;
348338

349-
#[cfg(todo)]
350339
fn div_euc(self, rhs: Self) -> Self;
351340

352-
#[cfg(todo)]
353341
fn mod_euc(self, rhs: Self) -> Self;
354342

355343
// NOTE depends on unstable intrinsics::powif64
@@ -382,7 +370,6 @@ pub trait F64Ext: private::Sealed {
382370

383371
fn tan(self) -> Self;
384372

385-
#[cfg(todo)]
386373
fn asin(self) -> Self;
387374

388375
fn acos(self) -> Self;
@@ -393,9 +380,11 @@ pub trait F64Ext: private::Sealed {
393380
#[cfg(todo)]
394381
fn atan2(self, other: Self) -> Self;
395382

396-
#[cfg(todo)]
397383
#[inline]
398-
fn sin_cos(self) -> (Self, Self) {
384+
fn sin_cos(self) -> (Self, Self)
385+
where
386+
Self: Copy,
387+
{
399388
(self.sin(), self.cos())
400389
}
401390

@@ -410,13 +399,10 @@ pub trait F64Ext: private::Sealed {
410399

411400
fn tanh(self) -> Self;
412401

413-
#[cfg(todo)]
414402
fn asinh(self) -> Self;
415403

416-
#[cfg(todo)]
417404
fn acosh(self) -> Self;
418405

419-
#[cfg(todo)]
420406
fn atanh(self) -> Self;
421407
}
422408

@@ -445,7 +431,7 @@ impl F64Ext for f64 {
445431
fn fdim(self, rhs: Self) -> Self {
446432
fdim(self, rhs)
447433
}
448-
#[cfg(todo)]
434+
449435
#[inline]
450436
fn fract(self) -> Self {
451437
self - self.trunc()
@@ -461,7 +447,6 @@ impl F64Ext for f64 {
461447
fma(self, a, b)
462448
}
463449

464-
#[cfg(todo)]
465450
#[inline]
466451
fn div_euc(self, rhs: Self) -> Self {
467452
let q = (self / rhs).trunc();
@@ -471,9 +456,8 @@ impl F64Ext for f64 {
471456
q
472457
}
473458

474-
#[cfg(todo)]
475459
#[inline]
476-
fn mod_euc(self, rhs: f32) -> f32 {
460+
fn mod_euc(self, rhs: f64) -> f64 {
477461
let r = self % rhs;
478462
if r < 0.0 {
479463
r + rhs.abs()
@@ -548,7 +532,6 @@ impl F64Ext for f64 {
548532
tan(self)
549533
}
550534

551-
#[cfg(todo)]
552535
#[inline]
553536
fn asin(self) -> Self {
554537
asin(self)
@@ -597,7 +580,6 @@ impl F64Ext for f64 {
597580
tanh(self)
598581
}
599582

600-
#[cfg(todo)]
601583
#[inline]
602584
fn asinh(self) -> Self {
603585
if self == f64::NEG_INFINITY {
@@ -607,7 +589,6 @@ impl F64Ext for f64 {
607589
}
608590
}
609591

610-
#[cfg(todo)]
611592
#[inline]
612593
fn acosh(self) -> Self {
613594
match self {
@@ -616,7 +597,6 @@ impl F64Ext for f64 {
616597
}
617598
}
618599

619-
#[cfg(todo)]
620600
#[inline]
621601
fn atanh(self) -> Self {
622602
0.5 * ((2.0 * self) / (1.0 - self)).ln_1p()

src/math/acosf.rs

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const P_S1: f32 = -4.2743422091e-02;
2222
const P_S2: f32 = -8.6563630030e-03;
2323
const Q_S1: f32 = -7.0662963390e-01;
2424

25+
#[inline]
2526
fn r(z: f32) -> f32 {
2627
let p = z * (P_S0 + z * (P_S1 + z * P_S2));
2728
let q = 1. + z * Q_S1;

src/math/asin.rs

+2
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,14 @@ const Q_S2: f64 = 2.02094576023350569471e+00; /* 0x40002AE5, 0x9C598AC8 */
5555
const Q_S3: f64 = -6.88283971605453293030e-01; /* 0xBFE6066C, 0x1B8D0159 */
5656
const Q_S4: f64 = 7.70381505559019352791e-02; /* 0x3FB3B8C5, 0xB12E9282 */
5757

58+
#[inline]
5859
fn comp_r(z: f64) -> f64 {
5960
let p = z * (P_S0 + z * (P_S1 + z * (P_S2 + z * (P_S3 + z * (P_S4 + z * P_S5)))));
6061
let q = 1.0 + z * (Q_S1 + z * (Q_S2 + z * (Q_S3 + z * Q_S4)));
6162
return p / q;
6263
}
6364

65+
#[inline]
6466
pub fn asin(mut x: f64) -> f64 {
6567
let z: f64;
6668
let r: f64;

src/math/asinf.rs

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const P_S1: f32 = -4.2743422091e-02;
2424
const P_S2: f32 = -8.6563630030e-03;
2525
const Q_S1: f32 = -7.0662963390e-01;
2626

27+
#[inline]
2728
fn r(z: f32) -> f32 {
2829
let p = z * (P_S0 + z * (P_S1 + z * P_S2));
2930
let q = 1. + z * Q_S1;

src/math/cos.rs

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ use super::{k_cos, k_sin, rem_pio2};
4141
// Accuracy:
4242
// TRIG(x) returns trig(x) nearly rounded
4343
//
44+
#[inline]
4445
pub fn cos(x: f64) -> f64 {
4546
let ix = (f64::to_bits(x) >> 32) as u32 & 0x7fffffff;
4647

src/math/expm1.rs

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

26-
#[allow(warnings)]
26+
#[inline]
2727
pub fn expm1(mut x: f64) -> f64 {
2828
let hi: f64;
2929
let lo: f64;

src/math/expo2.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use super::{combine_words, exp};
22

33
/* exp(x)/2 for x >= log(DBL_MAX), slightly better than 0.5*exp(x/2)*exp(x/2) */
4-
pub(crate) fn expo2(x: f64) -> f64 {
4+
#[inline]
5+
pub fn expo2(x: f64) -> f64 {
56
/* k is such that k*ln2 has minimal relative error and x - kln2 > log(DBL_MIN) */
67
const K: i32 = 2043;
78
let kln2 = f64::from_bits(0x40962066151add8b);

src/math/fenv.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
11
// src: musl/src/fenv/fenv.c
22
/* Dummy functions for archs lacking fenv implementation */
33

4-
pub(crate) const FE_UNDERFLOW: i32 = 0;
5-
pub(crate) const FE_INEXACT: i32 = 0;
4+
pub const FE_UNDERFLOW: i32 = 0;
5+
pub const FE_INEXACT: i32 = 0;
66

7-
pub(crate) const FE_TONEAREST: i32 = 0;
8-
pub(crate) const FE_TOWARDZERO: i32 = 0;
7+
pub const FE_TONEAREST: i32 = 0;
8+
pub const FE_TOWARDZERO: i32 = 0;
99

1010
#[inline]
11-
pub(crate) fn feclearexcept(_mask: i32) -> i32 {
11+
pub fn feclearexcept(_mask: i32) -> i32 {
1212
0
1313
}
1414

1515
#[inline]
16-
pub(crate) fn feraiseexcept(_mask: i32) -> i32 {
16+
pub fn feraiseexcept(_mask: i32) -> i32 {
1717
0
1818
}
1919

2020
#[inline]
21-
pub(crate) fn fetestexcept(_mask: i32) -> i32 {
21+
pub fn fetestexcept(_mask: i32) -> i32 {
2222
0
2323
}
2424

2525
#[inline]
26-
pub(crate) fn fegetround() -> i32 {
26+
pub fn fegetround() -> i32 {
2727
FE_TONEAREST
2828
}
2929

3030
#[inline]
31-
pub(crate) fn fesetround(_r: i32) -> i32 {
31+
pub fn fesetround(_r: i32) -> i32 {
3232
0
3333
}

src/math/k_cosf.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const C2: f64 = -0.00138867637746099294692; /* -0x16c087e80f1e27.0p-62 */
2121
const C3: f64 = 0.0000243904487962774090654; /* 0x199342e0ee5069.0p-68 */
2222

2323
#[inline]
24-
pub(crate) fn k_cosf(x: f64) -> f32 {
24+
pub fn k_cosf(x: f64) -> f32 {
2525
let z = x * x;
2626
let w = z * z;
2727
let r = C2 + z * C3;

src/math/k_expo2f.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const K: i32 = 235;
55

66
/* expf(x)/2 for x >= log(FLT_MAX), slightly better than 0.5f*expf(x/2)*expf(x/2) */
77
#[inline]
8-
pub(crate) fn k_expo2f(x: f32) -> f32 {
8+
pub fn k_expo2f(x: f32) -> f32 {
99
let k_ln2 = f32::from_bits(0x4322e3bc);
1010
/* note that k is odd and scale*scale overflows */
1111
let scale = f32::from_bits(((0x7f + K / 2) as u32) << 23);

src/math/k_sinf.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const S3: f64 = -0.000198393348360966317347; /* -0x1a00f9e2cae774.0p-65 */
2121
const S4: f64 = 0.0000027183114939898219064; /* 0x16cd878c3b46a7.0p-71 */
2222

2323
#[inline]
24-
pub(crate) fn k_sinf(x: f64) -> f32 {
24+
pub fn k_sinf(x: f64) -> f32 {
2525
let z = x * x;
2626
let w = z * z;
2727
let r = S3 + z * S4;

src/math/k_tan.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ static T: [f64; 13] = [
5858
const PIO4: f64 = 7.85398163397448278999e-01; /* 3FE921FB, 54442D18 */
5959
const PIO4_LO: f64 = 3.06161699786838301793e-17; /* 3C81A626, 33145C07 */
6060

61-
pub(crate) fn k_tan(mut x: f64, mut y: f64, odd: i32) -> f64 {
61+
#[inline]
62+
pub fn k_tan(mut x: f64, mut y: f64, odd: i32) -> f64 {
6263
let hx = (f64::to_bits(x) >> 32) as u32;
6364
let big = (hx & 0x7fffffff) >= 0x3FE59428; /* |x| >= 0.6744 */
6465
if big {

0 commit comments

Comments
 (0)