Skip to content

Conversation

kinke
Copy link
Contributor

@kinke kinke commented May 15, 2015

No description provided.

// Invalid and div by zero shouldn't be affected.
assert(!f.invalid);
assert(!f.divByZero);
assert(feqrel(x, pair[1]) >= real.mant_dig-13);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

13 lowest mantissa bits allowed to diverge - 13 has been chosen based on an LDC run on Linux x64 with LLVM 3.6 llvm.exp.f80 intrinsic (supposedly following libm implementation).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add as comment in code

@WalterBright
Copy link
Member

Please explain what is meant by "proper" 64 bit support. Does it mean reducing precision from 80 bits for intermediate results to 64 bits?

@ibuclaw
Copy link
Member

ibuclaw commented May 16, 2015

I assume this allows targets whose real type have a maximum significand precision of 53 bits to pass these tests?

@kinke
Copy link
Contributor Author

kinke commented May 16, 2015

I thought the changes are pretty self-explaining, but here's a quick summary:

The 1st commit fixes a serious bug in feqrel() wrt. subnormal diffs, an issue which arised when preparing the 2nd commit, which mainly fixes exp() for double-precision real by (1) using proper over-/underflow limits for exp() and (2) adding a proper test set for that precision. Additionally, the 2nd commit relaxes the tests a bit by NOT checking for bitwise equality of the exp() results and NOT caring about whether the overflow bit was set when the input was real.infinity (based on the LLVM intrinsic which is supposed to mimic the libm implementation).

There are other places assuming 80-bit reals, so that's only a start for platforms/targets without x87 support.

@kinke kinke force-pushed the exp branch 2 times, most recently from 48111c8 to c85f529 Compare May 17, 2015 18:02
kinke added 2 commits May 17, 2015 20:30
For subnormal diffs, the old code used the whole ushort containing
the exponent bits as exponent, without masking and shifting. This
seems to have worked for 80-bit reals so far and the single unit-
test was only enabled for x87 reals.
@kinke
Copy link
Contributor Author

kinke commented May 17, 2015

I've added some appropriate comments and tightened the tests again, this time allowing a relative diff of max 2 mantissa bits (3 ulp). That limit is declared as variable so that other backends like LDC may easily relax them.

@WalterBright
Copy link
Member

Auto-merge toggled on

WalterBright added a commit that referenced this pull request May 19, 2015
std.math: proper support for 64-bit real in exp()
@WalterBright WalterBright merged commit e8f1e6b into dlang:master May 19, 2015
@ibuclaw
Copy link
Member

ibuclaw commented Jun 7, 2015

I've just had another look, and I found something wrong, see comment.

[ 0x1p+80L, real.infinity ], // far overflow
[ real.infinity, real.infinity ],
[-0x1.6p+9L, 0x1.44a3824e5285fp-1016L ], // near underflow
[-0x1.64p+9L, 0x0.06f84920bb2d3p-1022L ], // near underflow - subnormal
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested this (albeit on 64bit) with -mlong-double-64 and get slightly different result to here. I even double-checked against libm, and it agrees with me.

expected = 0x0.06f84920bb2d300p-1022 (6.05799464199889e-310)
std.math = 0x0.06f84920bb2d400p-1022 (6.05799464199894e-310)
libm     = 0x0.06f84920bb2d400p-1022 (6.05799464199894e-310)

@ibuclaw
Copy link
Member

ibuclaw commented Jun 25, 2015

Ping on the failing unittest!

@ibuclaw
Copy link
Member

ibuclaw commented Jun 25, 2015

Regression raised https://issues.dlang.org/show_bug.cgi?id=14732

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants