[Cfp-interest] C operators

Ian McIntosh ianm at ca.ibm.com
Mon Mar 18 12:25:12 PDT 2013


Comparing a BFP and a DFP value for equality requires converting one to the
other.  With BFP to BFP or DFP to DFP, if they are different precisions you
can widen the lower precision to match the other.  BFP to DFP or DFP to BFP
is troublesome because when the formats are the same size one has a larger
exponent range but the other has more precision.  Which way should you
convert?  The decision was to make the user convert and do a same-base
comparison, with the hope that the user will know more about the
application's needs and whether exponent range or fraction precision is
more important than a compiler would.

If you really cared enough you could get a better result by checking
whether an overflow will or won't happen and doing a different conversion
and comparison depending on that.

- Ian McIntosh          IBM Canada Lab         Compiler Back End Support
and Development



|------------>
| From:      |
|------------>
  >--------------------------------------------------------------------------------------------------------------------------------------------------|
  |"Mike Cowlishaw" <mfc at speleotrove.com>                                                                                                            |
  >--------------------------------------------------------------------------------------------------------------------------------------------------|
|------------>
| To:        |
|------------>
  >--------------------------------------------------------------------------------------------------------------------------------------------------|
  |"'CFP'" <cfp-interest at ucbtest.org>                                                                                                                |
  >--------------------------------------------------------------------------------------------------------------------------------------------------|
|------------>
| Date:      |
|------------>
  >--------------------------------------------------------------------------------------------------------------------------------------------------|
  |03/18/2013 10:25 AM                                                                                                                               |
  >--------------------------------------------------------------------------------------------------------------------------------------------------|
|------------>
| Subject:   |
|------------>
  >--------------------------------------------------------------------------------------------------------------------------------------------------|
  |[Cfp-interest] C operators                                                                                                                        |
  >--------------------------------------------------------------------------------------------------------------------------------------------------|
|------------>
| Sent by:   |
|------------>
  >--------------------------------------------------------------------------------------------------------------------------------------------------|
  |cfp-interest-bounces at oakapple.net                                                                                                                 |
  >--------------------------------------------------------------------------------------------------------------------------------------------------|





Just got the attached request from someone implementing a decimal
arithmetic library; I think it's a C/C++ question really.  But I'm not sure
where to 'point him to'.  Any suggestions appreciated.

Mike

The C++ decimal FP TR defines, well, everything, in terms of IEEE-754.
 Also operations like this: lhs == rhs where lhs or rhs are integers or
binary FP types.  I am trying to interpret IEEE-754 to see if it indeed
defines such operations.  (With a quick look I could not find.)

I have no problem defining the return value, however I am not sure if and
what exceptions are to be raised?  For example, if I compare a
decimal32 to a double, and the double is larger that dec32_max, should I
set overflow?  (Because I have tried to convert the double to
dec32.)  Or perhaps I should set inexact, because I have tried to convert
the Dec32 to double first, and it may not be exactly representable?

Could you give me a hint on what sections of the IEEE-754 I should read to
find out those things?  Thanks in advance.  Oh, and feel free to tell me if
I ask too much._______________________________________________
Cfp-interest mailing list
Cfp-interest at oakapple.net
http://mailman.oakapple.net/mailman/listinfo/cfp-interest

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.oakapple.net/pipermail/cfp-interest/attachments/20130318/a34e2a57/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: graycol.gif
Type: image/gif
Size: 105 bytes
Desc: not available
Url : http://mailman.oakapple.net/pipermail/cfp-interest/attachments/20130318/a34e2a57/attachment.gif 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ecblank.gif
Type: image/gif
Size: 45 bytes
Desc: not available
Url : http://mailman.oakapple.net/pipermail/cfp-interest/attachments/20130318/a34e2a57/attachment-0001.gif 


More information about the Cfp-interest mailing list