Google Groups Home
Help | Sign in
concatenation of power of negative number
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Expand all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
a...@servocomm.freeserve.co.uk  
View profile  
 More options Jan 20 2006, 1:18 pm
Newsgroups: comp.std.c++
From: a...@servocomm.freeserve.co.uk
Date: Fri, 20 Jan 2006 12:18:03 CST
Local: Fri, Jan 20 2006 1:18 pm
Subject: concatenation of power of negative number
Hi,

Using gcc3.2  the concatenation of  1##Num  where Num is negative
leaves a space
eg 1e#-1  --> 1e -1 as can be seen by the preprocessed output below.
The only
way round it  that I can see is to simply not use a macro for this
compiler, which means producing some 200 specialisations by hand

Is this  the correct behaviour? I believe that  the relevant part is
16.3.3.-3 where it says that "if the result (of concatenation) is not a
valid preprocessing token the behaviour is undefined." I think that the
relevent production is:

pp_number <- pp_number e sign

pp_number <-pp_number digit

So  (though my dealings with grammars are often suspect) I would expect
this to be a valid preprocessor operation. Now if it isnt, it is
awfully inconvenient when trying to use this particular number format
in this way. Any help on this would be appreciated.

#define POW_EVAL(Num, Float_type)\
       template <>\
       struct pow_eval< \
            Float_type BOOST_PP_COMMA()  Num  BOOST_PP_COMMA()\
             1 BOOST_PP_COMMA() false\
             >{\
           enum{ required = true};\
           typedef Float_type result_type;\
           result_type operator()()const\
           {    result_type result\
                = static_cast< Float_type > (1e ## Num);\
                return result;\
            }\
       };

POW_EVAL(-60, double)
POW_EVAL(-59, double)
POW_EVAL(58, double)
POW_EVAL(57, double)

// preprocessor output.  note the space in e.g static_cast<double>(1e-
60)

template <> struct pow_eval< double , -60 , 1 , false >{ enum{ required
= true};
typedef double result_type; result_type operator()()const { result_type
result =
static_cast< double > (1e- 60); return result; } };
template <> struct pow_eval< double , -59 , 1 , false >{ enum{ required
= true};
typedef double result_type; result_type operator()()const { result_type
result =
static_cast< double > (1e- 59); return result; } };
template <> struct pow_eval< double , 58 , 1 , false >{ enum{ required
= true};
typedef double result_type; result_type operator()()const { result_type
result =
static_cast< double > (1e58); return result; } };
template <> struct pow_eval< double , 57 , 1 , false >{ enum{ required
= true};
typedef double result_type; result_type operator()()const { result_type
result =
static_cast< double > (1e57); return result; } };

regards
Andy Little

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-...@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
"Paul Mensonides"  
View profile  
 More options Jan 20 2006, 6:00 pm
Newsgroups: comp.std.c++
From: pmens...@comcast.net ("Paul Mensonides")
Date: Fri, 20 Jan 2006 23:00:12 GMT
Local: Fri, Jan 20 2006 6:00 pm
Subject: Re: concatenation of power of negative number

<a...@servocomm.freeserve.co.uk> wrote in message

news:1137779816.702282.199460@g43g2000cwa.googlegroups.com...

> Hi,

> Using gcc3.2  the concatenation of  1##Num  where Num is negative
> leaves a space
> eg 1e#-1  --> 1e -1 as can be seen by the preprocessed output below.

gcc gives 1e- 1 which is correct.  You aren't concatenating 1e to the "token" -1
(-1 is two tokens) you're concatenating 1e just the - token.  I.e.

 <1e> ## <-> <1>
|___________|
      |
      token pasting only affects these two preprocessing tokens

There is no way to do this directly, but you can form (e.g) 1e-1 by a double
concatenation:

#define CAT(a, b) PRIMITIVE_CAT(a, b)
#define PRIMITIVE_CAT(a, b) a ## b

CAT(PRIMITIVE_CAT(1e, -), 1) // 1e-1

Regards,
Paul Mensonides

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-...@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google