Skip to content

Commit

Permalink
msun: Fix math error in comment explaining y reduction
Browse files Browse the repository at this point in the history
x = k + y for some integer k and |y| < 1/2
exp2(x) = exp2(k + y) = exp2(k) * exp2(y)
which can be written as 2**k * exp2(y)

The original had x = 2**k + y, which is has an extra 2** in it which
isn't correct.

Confirmed by forumula 2 in Gal and Bachelis referenced in the comments
for the source of this method
	https://dl.acm.org/doi/pdf/10.1145/103147.103151

The actual code is correct.

Reviewed by: imp (who added s_exp2.c and wrote the commit message)
Pull Request: freebsd#1127
  • Loading branch information
hchataing authored and bsdimp committed Apr 12, 2024
1 parent 2cf0c51 commit 2b2cd97
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/msun/src/s_exp2.c
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ static const double tbl[TBLSIZE * 2] = {
* Method: (accurate tables)
*
* Reduce x:
* x = 2**k + y, for integer k and |y| <= 1/2.
* x = k + y, for integer k and |y| <= 1/2.
* Thus we have exp2(x) = 2**k * exp2(y).
*
* Reduce y:
Expand Down
2 changes: 1 addition & 1 deletion lib/msun/src/s_exp2f.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ static const double exp2ft[TBLSIZE] = {
* Method: (equally-spaced tables)
*
* Reduce x:
* x = 2**k + y, for integer k and |y| <= 1/2.
* x = k + y, for integer k and |y| <= 1/2.
* Thus we have exp2f(x) = 2**k * exp2(y).
*
* Reduce y:
Expand Down

0 comments on commit 2b2cd97

Please sign in to comment.