This is the mail archive of the libc-hacker@sourceware.cygnus.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

[comp.std.c] tgmath.h macros: problems with implementation



On comp.std.c is a small thread about problems implementing
<tgmath.h>.  I'm appending the articles that appeared so far since I
guess we face the same problem (and even more) as the following simple 
program shows:.
#include <tgmath.h>

int main(void) 
{

  sin(sin(1.0f));
}

gcc -g test-tgmath.c
test-tgmath.c: In function `main':
test-tgmath.c:6: type mismatch in conditional expression
[..]

Btw. even using:
  sin(1.0f);

gives the above error message (just not as often).  

I hope to find some time over the coming weekend to look more closely
into <tgmath.h> and provide some tests.

Andreas
-- 
 Andreas Jaeger   aj@arthur.rhein-neckar.de    jaeger@informatik.uni-kl.de
  for pgp-key finger ajaeger@aixd1.rhrk.uni-kl.de


Topics:
   tgmath.h macros: problems with implementation
   Re: tgmath.h macros: problems with implementation
   Re: tgmath.h macros: problems with implementation
   Re: tgmath.h macros: problems with implementation


----------------------------------------------------------------------

Date: 19 Oct 1998 16:32:50 -0500
From: Ben Combee <bcombee@metrowerks.com>
Subject: tgmath.h macros: problems with implementation
Message-ID: <u3e8kme4d.fsf@austin.metrowerks.com>

We're trying to implement the <tgmath.h> macros defined in C9X, but we
are having some problems with types.

Consider this possible implementation:

#define sin(x) ((sizeof((x))==sizeof(float) ? (sinf((x))) : (sin)((x)))

This works for the simple cases

    sin(1.0f)
    sin(1.0)
    sin(float_returning_func())
    sin(double_returning_func())

but this fails in the case where it interacts with itself or similar macros:

    sin(sin(1.0f))

which becomes

    sin(sinf(1.0f))

This is because the conditional operator has the type double, since
its two result operands are both arithmetic types, and float converts
to double to make the two operands the same type. (6.5.15)

Any other ideas out there on implementing this?

- - 
Ben Combee <bcombee@metrowerks.com> -- x86/Win32/NetWare CompilerWarrior

------------------------------

Date: Tue, 20 Oct 1998 03:31:41 GMT
From: "Douglas A. Gwyn" <DAGwyn@null.net>
Subject: Re: tgmath.h macros: problems with implementation
Message-ID: <362C03E8.474BA549@null.net>
References: <u3e8kme4d.fsf@austin.metrowerks.com>
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Ben Combee wrote:
> We're trying to implement the <tgmath.h> macros defined in C9X, but we
> are having some problems with types.
> #define sin(x) ((sizeof((x))==sizeof(float) ? (sinf((x))) : (sin)((x)))
> but this fails in the case where it interacts with itself or similar macros:
>     sin(sin(1.0f))
> Any other ideas out there on implementing this?

Yes, so far as I can see the only way to implement <tgmath.h>
(except in the lucky case where all floating types have the
same representation) is to have a special "generic-type" hook
that the compiler understands.  Only the compiler itself is
in a position to properly figure out the proper type(s).

------------------------------

Date: Mon, 19 Oct 1998 22:24:42 GMT
From: seebs@plethora.net (Peter Seebach)
Subject: Re: tgmath.h macros: problems with implementation
Message-ID: <K_OW1.330$a6.1165741@ptah.visi.com>
References: <u3e8kme4d.fsf@austin.metrowerks.com>

In article <u3e8kme4d.fsf@austin.metrowerks.com>,
Ben Combee  <bcombee@metrowerks.com> wrote:
>We're trying to implement the <tgmath.h> macros defined in C9X, but we
>are having some problems with types.

I'm not *sure*, but I seem to recall that the committee discussion implied
that <tgmath.h> required deeper magic.

>Any other ideas out there on implementing this?

Sure!  Create an operator-like-sizeof that is considered a constant expression
and which can be used at compile time in constant expressions, and a special
conditional operator-lookalike which doesn't do the promotions.

:(

I'm just glad *I* don't have to implement that one.  I'm not especially fond
of it.  I guess it's probably a pretty cool feature for the math users, but...

- s
- - 
Copyright 1998, All rights reserved.  Peter Seebach / seebs@plethora.net
C/Unix wizard, Pro-commerce radical, Spam fighter.  Boycott Spamazon!
Seeking interesting programming projects.  Not interested in commuting.
Visit my new ISP <URL:http://www.plethora.net/> --- More Net, Less Spam!

------------------------------

Date: Tue, 20 Oct 1998 17:20:02 +0100
From: "Clive D.W. Feather" <clive@on-the-train.demon.co.uk>
Subject: Re: tgmath.h macros: problems with implementation
Message-ID: <k6WcLCAygLL2EwPy@on-the-train.demon.co.uk>
References: <u3e8kme4d.fsf@austin.metrowerks.com>
 <K_OW1.330$a6.1165741@ptah.visi.com>

In article <K_OW1.330$a6.1165741@ptah.visi.com>, Peter Seebach
<seebs@plethora.net> writes
>>We're trying to implement the <tgmath.h> macros defined in C9X, but we
>>are having some problems with types.
>
>I'm not *sure*, but I seem to recall that the committee discussion implied
>that <tgmath.h> required deeper magic.

It does.

>>Any other ideas out there on implementing this?
>
>Sure!  Create an operator-like-sizeof that is considered a constant expression
>and which can be used at compile time in constant expressions, and a special
>conditional operator-lookalike which doesn't do the promotions.

Or simply define a magic macro, so at least all the magic is in one
place:

    #define sin(x) __fp_generic ((x), sinf, sin, sinl)

- - 
Clive D.W. Feather   | Regulation Officer, LINX | Work: <clive@linx.org>
Tel: +44 1733 705000 | (on secondment from      | Home: <cdwf@i.am>
Fax: +44 1733 353929 |  Demon Internet)         | <http://i.am/davros>
Written on my laptop; please observe the Reply-To address

------------------------------

End of forwardq2AYrx Digest
***************************



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]