Skip to content

Floating point subnormals overrounded on output

The following test suggests that GHC is overrounding Float subnormals, when printing them out

Prelude> 2**(-149)
1.401298464324817e-45
Prelude> 2**(-149) :: Float
1.0e-45
Prelude> isDenormalized it
True
Prelude>
Prelude> 2**(-149) * 2**(100) * 2**(49) :: Float
1.0

By comparison

#include <stdio.h>
#include <stdlib.h>

int main (void)
{
 float clang_dec, clang_hex, libc_dec, libc_hex;

 clang_dec = 1.401298464324817e-45;
 clang_hex = 0x0.000002P-126;
 printf("clang (from decimal)   = %a\n",clang_dec);
 printf("clang (from decimal)   = %g\n",clang_dec);
 printf("clang (from hex)       = %a\n",clang_hex);
 printf("clang (from hex)       = %g\n",clang_hex);

 libc_dec = strtod("1.401298464324817e-45",NULL);
 libc_hex = strtod("0x0.000002P-126",NULL);
 printf("libc (from decimal) = %a\n",libc_dec);
 printf("libc (from decimal) = %g\n",libc_dec);
 printf("libc (from hex)     = %a\n",libc_hex);
 printf("libc (from hex)     = %g\n",libc_hex);
}

produces

clang (from decimal)   = 0x1p-149
clang (from decimal)   = 1.4013e-45
clang (from hex)       = 0x1p-149
clang (from hex)       = 1.4013e-45
libc (from decimal) = 0x1p-149
libc (from decimal) = 1.4013e-45
libc (from hex)     = 0x1p-149
libc (from hex)     = 1.4013e-45
Trac metadata
Trac field Value
Version 7.8.3
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Runtime System
Test case
Differential revisions
BlockedBy
Related
Blocking
CC simonmar
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information