<p>This is due to a macOS bug in 64bits libm! (Hard to believe, isn't it?)</p>
<p>I've opened a ticket <a href="https://bugreport.apple.com/web/?problemID=48021471" rel="nofollow">https://bugreport.apple.com/web/?problemID=48021471</a></p>
<blockquote>
<p>Area:<br>
Something not on this list</p>
<p>Summary: ldexp incorrectly rounds gradual underflow for some specific values.</p>
<p>Steps to Reproduce:<br>
#include <math.h><br>
#include <stdio.h><br>
int main() {<br>
int exp=-54; double y=ldexp(11.0,exp); /* y is binary 1.011<em>2^-51 <em>/<br>
double u=ldexp(1.0,-1074); /</em> u is the minimal denormalized IEEE754 double <em>/<br>
double v=ldexp(y,-1023); /</em> v is binary 1.011</em>2^-1074 and should round to u */<br>
printf("u=%g v=%g\n",u,v);<br>
return 0;<br>
}</p>
<p>Expected Results:<br>
v should be rounded to 1.0*2^-1074 (round to nearest, tie to even default rule)<br>
Thus we should have u == v.</p>
<p>Actual Results:<br>
v is rounded upward to binary 10.0<em>2^-1074 = 1.0</em>2^-1073<br>
output is u=4.94066e-324 v=9.88131e-324</p>
<p>Note 1: this fails for 4 different values of exp -54,-53,+968,+969<br>
(replace exponent -1023 by -1074-3-exp, that is  -1023,-1024,-2045,-2046)<br>
Note 2: this did not happen previously with 32bits libm version.<br>
Note 3: this sounds a bit like this bug <a href="https://stackoverflow.com/questions/32150888/should-ldexp-round-correctly" rel="nofollow">https://stackoverflow.com/questions/32150888/should-ldexp-round-correctly</a></p>
<p>Version/Build:<br>
macOS HighSierra 10.13.16</p>
<p>Configuration:<br>
compiled with<br>
clang --version<br>
Apple LLVM version 10.0.0 (clang-1000.11.45.5)<br>
Target: x86_64-apple-darwin17.7.0<br>
Thread model: posix<br>
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin<br>
Xcode Version 10.1 (10B61)</p>
</blockquote>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/383">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AhLyW1OB9X3gMiO9VT2vx0yiEa3tR3ejks5vapcxgaJpZM4cMh8Z">mute the thread</a>.<img src="https://github.com/notifications/beacon/AhLyWwSYKtnI0zWaFmLQ8jsq9OeTHb_7ks5vapcxgaJpZM4cMh8Z.gif" height="1" width="1" alt="" /></p>
<script type="application/json" data-scope="inboxmarkup">{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/OpenSmalltalk/opensmalltalk-vm","title":"OpenSmalltalk/opensmalltalk-vm","subtitle":"GitHub repository","main_image_url":"https://github.githubassets.com/images/email/message_cards/header.png","avatar_image_url":"https://github.githubassets.com/images/email/message_cards/avatar.png","action":{"name":"Open in GitHub","url":"https://github.com/OpenSmalltalk/opensmalltalk-vm"}},"updates":{"snippets":[{"icon":"DESCRIPTION","message":"primitives 54 and 554 for timesTwoPower: answer incorrect result on 64bits macOS VM (#383)"}],"action":{"name":"View Issue","url":"https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/383"}}}</script>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/383",
"url": "https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/383",
"name": "View Issue"
},
"description": "View this Issue on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>