From: Rich Felker <dalias@aerifal.cx>
To: musl@lists.openwall.com
Subject: Re: libm
Date: Fri, 9 Mar 2012 22:28:44 -0500 [thread overview]
Message-ID: <20120310032844.GH184@brightrain.aerifal.cx> (raw)
In-Reply-To: <20120309170254.GG184@brightrain.aerifal.cx>
On Fri, Mar 09, 2012 at 12:02:54PM -0500, Rich Felker wrote:
> On Fri, Mar 09, 2012 at 10:56:55AM -0500, Rich Felker wrote:
> > > > Then add __RETCAST((x)), __RETCAST((x)+(y)), etc. Some trick will be
> > > > needed to make integer types result in a cast to double, though.
> > >
> > > hm the int->double and complex/real cases are tricky
> > >
> > > i thought +1.0 or +I would solve these, but that's wrong
> >
> > I think +0.0f might solve it. Isn't the promoted type of any integer
> > type with float double?
>
> Nope, it results in float. glibc has a trick involving obscure
> interactions of null pointer constants and the ?: operator that
> generates the right type using __typeof__, which is no big deal
> because this code is already only used when __typeof__ is available,
> anyway.
>
> There's a good blog article on it somewhere which I can't seem to find
> at the moment...
Try this:
#define __RETCAST(x) (__typeof__(*(0 \
? (__typeof__(0 ? (double *)0 : (void *)__IS_FP(x)))0 \
: (__typeof__(0 ? (__typeof__(x) *)0 : (void *)!__IS_FP(x)))0 )))
In the outer conditional operator, the second operand is a pointer to
double if (void *)__IS_FP(x) is a null pointer constant (which is true
iff __IS_FP(x)==0) and otherwise is a pointer to void.
Conversely, the third operand of the outer conditional is a pointer to
__typeof__(x) iff __IS_FP(x)!=0, and otherwise a pointer to void.
Thus the outer conditional sees either "double *" and "void *", or
else "void *" and "__typeof__(x) *", resulting it in having type
"double *" or "__typeof__(x)", reflecting whether x was an integer or
floating point type.
Rich
next prev parent reply other threads:[~2012-03-10 3:28 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-23 16:41 libm Szabolcs Nagy
2012-01-23 17:07 ` libm Rich Felker
2012-01-23 19:12 ` libm Szabolcs Nagy
2012-01-27 16:02 ` libm Szabolcs Nagy
2012-01-27 19:01 ` libm Pascal Cuoq
2012-01-27 19:34 ` libm Rich Felker
2012-01-29 16:34 ` libm Szabolcs Nagy
2012-02-27 21:02 ` libm Szabolcs Nagy
2012-02-27 22:24 ` libm Rich Felker
2012-03-03 22:57 ` libm Szabolcs Nagy
2012-03-04 6:53 ` libm Rich Felker
2012-03-04 14:50 ` libm Szabolcs Nagy
2012-03-04 18:43 ` libm Rich Felker
2012-03-05 8:51 ` libm Szabolcs Nagy
2012-03-05 14:04 ` libm Rich Felker
2012-03-05 15:17 ` libm Szabolcs Nagy
2012-03-05 15:25 ` libm Rich Felker
2012-03-09 10:22 ` libm Rich Felker
2012-03-09 10:57 ` libm Szabolcs Nagy
2012-03-09 16:01 ` libm Rich Felker
2012-03-09 11:09 ` libm Szabolcs Nagy
2012-03-09 15:56 ` libm Rich Felker
2012-03-09 17:02 ` libm Rich Felker
2012-03-10 3:28 ` Rich Felker [this message]
2012-03-10 12:45 ` libm Szabolcs Nagy
2012-03-10 13:12 ` libm Rich Felker
2012-03-10 16:38 ` libm Szabolcs Nagy
2012-03-05 11:08 ` libm Szabolcs Nagy
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=20120310032844.GH184@brightrain.aerifal.cx \
--to=dalias@aerifal.cx \
--cc=musl@lists.openwall.com \
/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.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
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).