From: erik quanstrom <quanstro@quanstro.net>
To: 9fans@cse.psu.edu
Subject: Re: [9fans] fun and scary evil C code
Date: Thu, 20 Dec 2007 08:02:22 -0500 [thread overview]
Message-ID: <8031fba473b2f8f2d904869083bd3f74@quanstro.net> (raw)
In-Reply-To: <df49a7370712200129u355998bbq18073b9421fc65d@mail.gmail.com>
as long as the conversion you're after has an exact ieee representation,
i can't see how two compliant implementations could come up with
differing representations. (two different numbers can't have the same
ieee representation, except -0 and +0.) the conversion process doesn't
need any floating point itself and the only interpolation comes when
numbers don't have exact representations.
it didn't occur to me immediately after russ' post that what he said
was literally correct:
#include<u.h>
#include<libc.h>
#define Magici(x) (((uchar*)&magic)[7-(x)])
static double magic = 7.949928895127363e-275;
void
main(void)
{
uint sign, exp;
uvlong sig, *v;
v = (uvlong*)&magic;
sign = *v>>63;
exp = *v>>52;
sig = *v&~(4096-1LL<<52);
print("%b*%b*%ullx\n", sign, exp, sig);
print("%ullx\n", *v);
}
- erik
next prev parent reply other threads:[~2007-12-20 13:02 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-12-19 15:15 David Leimbach
2007-12-19 20:37 ` Russ Cox
2007-12-19 22:32 ` Robert William Fuller
2007-12-19 22:38 ` erik quanstrom
2007-12-19 22:51 ` Bakul Shah
2007-12-20 0:18 ` dave.l
2007-12-20 0:33 ` dave.l
2007-12-20 0:51 ` erik quanstrom
2007-12-20 9:29 ` roger peppe
2007-12-20 13:02 ` erik quanstrom [this message]
2007-12-20 16:29 Russ Cox
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=8031fba473b2f8f2d904869083bd3f74@quanstro.net \
--to=quanstro@quanstro.net \
--cc=9fans@cse.psu.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).