FreeBSD Bugzilla – Attachment 188840 Details for
Bug 224326
double subnormals are not well printed on printing with printf (and friends)
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
program to display correct values (except for rounding errors)
subnormal.c (text/x-csrc), 837 bytes, created by
Luis Colorado
on 2017-12-14 20:49:56 UTC
(
hide
)
Description:
program to display correct values (except for rounding errors)
Filename:
MIME Type:
Creator:
Luis Colorado
Created:
2017-12-14 20:49:56 UTC
Size:
837 bytes
patch
obsolete
>#include <stdio.h> >#include <float.h> >#include <stdint.h> > >size_t print_double(FILE*out, double x) >{ > double tab[] = { > 1.0e256, > 1.0e128, > 1.0e64, > 1.0e32, > 1.0e16, > 1.0e8, > 1.0e4, > 1.0e2, > 1.0e1, > }; > size_t tab_n = sizeof tab / sizeof tab[0]; > > uint64_t *uintref = (uint64_t *)&x; > if (x != 0.0 && (*uintref >> 52 & 0x7ff) == 0) { > /* get the 10's exponent */ > int i; > int exp = 0; > for (i = 0; i < tab_n; i++) { > exp <<= 1; > if (x * tab[i] < 1.0) { > exp |= 1; > x *= tab[i]; > } /* if */ > } /* for */ > exp++; > x *= 10.0; > return fprintf(out, "%0.17lgd%+d\n", x, -exp); > } > return fprintf(out, "%0.17lg\n", x); >} > >int main() >{ > double x = 1.0; > uint64_t *ival = (uint64_t *)&x; > while (x != 0.0) { > printf("0x%016llx ", *ival); > print_double(stdout, x); > x /= 2.0; > } /* while */ > return 0; >} /* main */
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 224326
:
188809
| 188840