Mentions légales du service
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
core-math
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
core-math
core-math
Commits
d55a5fca
Commit
d55a5fca
authored
2 years ago
by
Alexei Sibidanov
Browse files
Options
Downloads
Plain Diff
Merge branch 'as_expm1f_v2' into 'master'
expm1f is reviewed and updated See merge request
!43
parents
33bbdec4
97cb7ca9
Branches
Branches containing commit
No related tags found
1 merge request
!43
expm1f is reviewed and updated
Pipeline
#841912
passed
2 years ago
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/binary32/expm1/expm1f.c
+52
-45
52 additions, 45 deletions
src/binary32/expm1/expm1f.c
with
52 additions
and
45 deletions
src/binary32/expm1/expm1f.c
+
52
−
45
View file @
d55a5fca
/* Correctly-rounded natural exponent function biased by 1 for binary32 value.
Copyright (c) 2022 Alexei Sibidanov.
Copyright (c) 2022
-2023
Alexei Sibidanov.
This file is part of the CORE-MATH project
(https://core-math.gitlabpages.inria.fr/).
...
...
@@ -25,60 +25,67 @@ SOFTWARE.
*/
#include
<stdint.h>
#include
<errno.h>
typedef
union
{
float
f
;
uint32_t
u
;}
b32u32_u
;
typedef
union
{
double
f
;
uint64_t
u
;}
b64u64_u
;
float
cr_expm1f
(
float
x
){
static
const
double
c
[]
=
{
0x1
.62e42
fefa398bp
-
5
,
0x1
.
ebfbdff84555ap
-
11
,
0x1
.
c6b08d4ad86d3p
-
17
,
0x1
.
3
b2ad1b1716a2p
-
23
,
0x1
.
5
d7472718ce9dp
-
30
,
0x1
.
4
a1d7f457ac56p
-
37
};
static
const
double
tb
[]
=
{
0x1
p
+
0
,
0x1
.
0
b5586cf9890fp
+
0
,
0x1
.
172
b83c7d517bp
+
0
,
0x1
.
2387
a6e756238p
+
0
,
0x1
.
306
fe0a31b715p
+
0
,
0x1
.
3
dea64c123422p
+
0
,
0x1
.
4
bfdad5362a27p
+
0
,
0x1
.
5
ab07dd485429p
+
0
,
0x1
.
6
a09e667f3bcdp
+
0
,
0x1
.
7
a11473eb0187p
+
0
,
0x1
.
8
ace5422aa0dbp
+
0
,
0x1
.
9
c49182a3f09p
+
0
,
0x1
.
ae89f995ad3adp
+
0
,
0x1
.
c199bdd85529cp
+
0
,
0x1
.
d5818dcfba487p
+
0
,
0x1
.
ea4afa2a490dap
+
0
};
static
const
float
q
[][
2
]
=
{{
0x1
.
fffffep127f
,
0x1
.
fffffep127f
},
{
-
1
.
0
f
,
0x1
p
-
26
f
}};
const
double
iln2h
=
0x1
.
7154765
p
+
0
*
16
,
iln2l
=
0x1
.
5
c17f0bbbe88p
-
31
*
16
;
{
1
,
0x1
.62e42
fef4c4e7p
-
6
,
0x1
.
ebfd1b232f475p
-
13
,
0x1
.
c6b19384ecd93p
-
20
};
static
const
double
ch
[]
=
{
0x1
.62e42
fefa39efp
-
6
,
0x1
.
ebfbdff82c58fp
-
13
,
0x1
.
c6b08d702e0edp
-
20
,
0x1
.
3
b2ab6fb92e5ep
-
27
,
0x1
.
5
d886e6d54203p
-
35
,
0x1
.
430976
b8ce6efp
-
43
};
static
const
double
td
[]
=
{
0x1
p
+
0
,
0x1
.
05
9
b0d3158574p
+
0
,
0x1
.
0
b5586cf9890fp
+
0
,
0x1
.
11301
d0125b51p
+
0
,
0x1
.
172
b83c7d517bp
+
0
,
0x1
.
1
d4873168b9aap
+
0
,
0x1
.
2387
a6e756238p
+
0
,
0x1
.29e9
df51fdee1p
+
0
,
0x1
.
306
fe0a31b715p
+
0
,
0x1
.
371
a7373aa9cbp
+
0
,
0x1
.
3
dea64c123422p
+
0
,
0x1
.44e086061892
dp
+
0
,
0x1
.
4
bfdad5362a27p
+
0
,
0x1
.
5342
b569d4f82p
+
0
,
0x1
.
5
ab07dd485429p
+
0
,
0x1
.
6247
eb03a5585p
+
0
,
0x1
.
6
a09e667f3bcdp
+
0
,
0x1
.
71
f75e8ec5f74p
+
0
,
0x1
.
7
a11473eb0187p
+
0
,
0x1
.
82589994
cce13p
+
0
,
0x1
.
8
ace5422aa0dbp
+
0
,
0x1
.
93737
b0cdc5e5p
+
0
,
0x1
.
9
c49182a3f09p
+
0
,
0x1
.
a5503b23e255dp
+
0
,
0x1
.
ae89f995ad3adp
+
0
,
0x1
.
b7f76f2fb5e47p
+
0
,
0x1
.
c199bdd85529cp
+
0
,
0x1
.
cb720dcef9069p
+
0
,
0x1
.
d5818dcfba487p
+
0
,
0x1
.
dfc97337b9b5fp
+
0
,
0x1
.
ea4afa2a490dap
+
0
,
0x1
.
f50765b6e454p
+
0
};
const
double
iln2
=
0x1
.
71547652
b82fep
+
5
,
big
=
0x1
.
8
p52
;
b32u32_u
t
=
{.
f
=
x
};
double
z
=
x
;
uint32_t
ux
=
t
.
u
,
ax
=
ux
&
(
~
0u
>>
1
);
if
(
__builtin_expect
(
ux
>
0xc18aa123u
,
0
)){
// x < -17.32
if
(
ax
>
(
0xffu
<<
23
))
return
x
;
// nan
return
q
[
1
][
0
]
+
q
[
1
][
1
];
}
else
if
(
__builtin_expect
(
ax
>
0x42b17218u
,
0
)){
// x > 88.72
if
(
ax
>
(
0xffu
<<
23
))
return
x
;
// nan
return
q
[
0
][
0
]
+
q
[
0
][
1
];
}
else
if
(
__builtin_expect
(
ax
<
0x3e000000u
,
1
)){
// x < 0.125
if
(
__builtin_expect
(
ax
<
0x32000000u
,
0
)){
// x < 2^-25
uint32_t
ux
=
t
.
u
,
ax
=
ux
<<
1
;
if
(
__builtin_expect
(
ax
<
0x7c400000u
,
1
)){
// |x| < 0.15625
if
(
__builtin_expect
(
ax
<
0x676a09e8u
,
0
)){
// |x| < 0x1.6a09e8p-24
if
(
__builtin_expect
(
ax
==
0x0u
,
0
))
return
x
;
// x = +-0
return
__builtin_fmaf
(
x
,
x
,
x
);
return
__builtin_fmaf
(
__builtin_fabsf
(
x
),
0x1
p
-
25
f
,
x
);
}
static
const
double
p
[]
=
{
0x1
.
fffffffffff
f6
p
-
2
,
0x1
.
55555555555
72
p
-
3
,
0x1
.
55555555
66
a8
fp
-
5
,
0x1
.
11111110
f18ae
p
-
7
,
0x1
.
6
c16b
f78e5645
p
-
10
,
0x1
.
a01a0
3fd7c6cd
p
-
13
,
0x1
.
a0
439d78f6d66
p
-
16
,
0x1
.
71
de3
8ef84d8c
p
-
19
};
static
const
double
b
[]
=
{
0x1
.
fffffffffff
c2
p
-
2
,
0x1
.
55555555555
fe
p
-
3
,
0x1
.
55555555
9767
fp
-
5
,
0x1
.
11111110
98
dc1
p
-
7
,
0x1
.
6
c16b
ca988aa9
p
-
10
,
0x1
.
a01a0
7658483f
p
-
13
,
0x1
.
a0
5b04d2c3503
p
-
16
,
0x1
.
71
de3
a960b5e3
p
-
19
};
double
z2
=
z
*
z
,
z4
=
z2
*
z2
;
double
c0
=
p
[
0
]
+
z
*
p
[
1
];
double
c2
=
p
[
2
]
+
z
*
p
[
3
];
double
c4
=
p
[
4
]
+
z
*
p
[
5
];
double
c6
=
p
[
6
]
+
z
*
p
[
7
];
c0
+=
z2
*
c2
;
c4
+=
z2
*
c6
;
c0
+=
z4
*
c4
;
return
z
+
z2
*
c0
;
}
else
{
double
a
=
iln2h
*
z
,
ia
=
__builtin_floor
(
a
),
h
=
(
a
-
ia
)
+
iln2l
*
z
;
long
i
=
ia
,
j
=
i
&
0xf
,
e
=
i
-
j
;
e
>>=
4
;
double
s
=
tb
[
j
];
b64u64_u
su
=
{.
u
=
(
e
+
0x3fful
)
<<
52
};
s
*=
su
.
f
;
double
h2
=
h
*
h
;
double
c0
=
c
[
0
]
+
h
*
c
[
1
];
double
c2
=
c
[
2
]
+
h
*
c
[
3
];
double
c4
=
c
[
4
]
+
h
*
c
[
5
];
c0
+=
h2
*
(
c2
+
h2
*
c4
);
double
w
=
s
*
h
;
return
(
s
-
1
.
0
)
+
w
*
c0
;
double
r
=
z
+
z2
*
((
b
[
0
]
+
z
*
b
[
1
])
+
z2
*
(
b
[
2
]
+
z
*
b
[
3
])
+
z4
*
((
b
[
4
]
+
z
*
b
[
5
])
+
z2
*
(
b
[
6
]
+
z
*
b
[
7
])));
return
r
;
}
if
(
__builtin_expect
(
ax
>
0x8562e430u
,
0
)){
// |x| > 88.72
if
(
ax
>
(
0xffu
<<
24
))
return
x
;
// nan
if
(
__builtin_expect
(
ux
>>
31
,
0
)){
// x < 0
if
(
ax
==
(
0xffu
<<
24
))
return
-
1
.
0
f
;
return
-
1
.
0
f
+
0x1
p
-
26
f
;
}
if
(
ax
==
(
0xffu
<<
24
))
return
__builtin_inff
();
float
r
=
0x1
.
fffffep127
*
z
;
if
(
r
>
0x1
.
fffffep127f
)
errno
=
ERANGE
;
return
r
;
}
double
a
=
iln2
*
z
,
ia
=
__builtin_roundeven
(
a
),
h
=
a
-
ia
,
h2
=
h
*
h
;
b64u64_u
u
=
{.
f
=
ia
+
big
};
double
c2
=
c
[
2
]
+
h
*
c
[
3
],
c0
=
c
[
0
]
+
h
*
c
[
1
];
const
unsigned
long
*
tdl
=
(
const
unsigned
long
*
)
td
;
b64u64_u
sv
=
{.
u
=
tdl
[
u
.
u
&
0x1f
]
+
((
u
.
u
>>
5
)
<<
52
)};
double
r
=
(
c0
+
h2
*
c2
)
*
sv
.
f
-
1
.
0
;
float
ub
=
r
,
lb
=
r
-
sv
.
f
*
0x1
.
3
b3p
-
33
;
if
(
__builtin_expect
(
ub
!=
lb
,
0
)){
if
(
__builtin_expect
(
ux
>
0xc18aa123u
,
0
))
// x < -17.32
return
-
1
.
0
f
+
0x1
p
-
26
f
;
const
double
iln2h
=
0x1
.
7154765
p
+
5
,
iln2l
=
0x1
.
5
c17f0bbbe88p
-
26
;
double
h
=
(
iln2h
*
z
-
ia
)
+
iln2l
*
z
,
s
=
sv
.
f
,
h2
=
h
*
h
,
w
=
s
*
h
;
double
r
=
(
s
-
1
)
+
w
*
((
ch
[
0
]
+
h
*
ch
[
1
])
+
h2
*
((
ch
[
2
]
+
h
*
ch
[
3
])
+
h2
*
(
ch
[
4
]
+
h
*
ch
[
5
])));
ub
=
r
;
}
return
ub
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment