[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: GURU NEEDED : macro SQUARE(x) for any type x
From: |
luser- -droog |
Subject: |
Re: GURU NEEDED : macro SQUARE(x) for any type x |
Date: |
Fri, 14 Jan 2011 01:04:02 -0800 (PST) |
User-agent: |
G2/1.0 |
On Jan 14, 2:14 am, Hans Vlems <hvl...@freenet.de> wrote:
> On 14 jan, 08:15, luser- -droog <mijo...@yahoo.com> wrote:
>
>
>
> > On Jan 14, 12:46 am, bolega <gnuist...@gmail.com> wrote:
>
> > > Basically, I have spent a few hours experimenting and searching on the
> > > comp.lang.c/c++
>
> > > Let me use SQR for brevity and saving line
>
> > > Here are progressively refined macros :
>
> > > #define SQR(x) ((x)*(x))
>
> > > #define SQR(x) ({typedef xtype=x; xtype xval=x; xval*xval}) // NOTE,
> > > closure or {} inside () is a valid idea in C, and thus no return is
> > > needed.
>
> > > this macro is given in several posts like
>
> > >http://groups.google.com/group/comp.lang.lisp/browse_frm/thread/38ef2...
>
> > > there is a problem with typedef
>
> > > Bolega
>
> > OIK
>
> > #define SQR(x) pow((x),2)
> > or
> > #define SQR(x) exp(2 * log(x))- Tekst uit oorspronkelijk bericht niet
> > weergeven -
>
> > - Tekst uit oorspronkelijk bericht weergeven -
>
> What happens for x=0 in the second example?
Rats! And you can't do a ternary 'cause you'd have to
mention x twice.
But that would be a penalty in lisp, too wouldn't it?
An expression with a side-effect would perform the
side-effect twice, right?