public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "newbie-02 at gmx dot de" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/113455] ROUNDING: IEEE Standard: Missing decimal rounding mode 'nearest, ties away from zero' for decimalxxx datatypes.
Date: Tue, 06 Feb 2024 00:48:24 +0000	[thread overview]
Message-ID: <bug-113455-4-8yztgzAdTX@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-113455-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113455

--- Comment #5 from newbie-02 <newbie-02 at gmx dot de> ---
> If you're doing arithmetic with constant operands, it might be folded at compile time; make sure you're using -frounding-math to avoid that.  

hmmmmm... that issue is left. From your comment I was in hope the following
program would work:  
````  
// compile with 'gcc -std=gnu99 -I/usr/local/include/dfp -frounding-math -o
round_constants_ties_away round_constants_ties_away.c -ldfp', 

#define __STDC_WANT_DEC_FP__                                                   
        // req. for decimal rounding mode, 
#include <fenv.h>                                                              
        // req. for decimal rounding mode, 
#include <stdio.h>                                                             
        // reg. e.g. printf and perror, 

int main( int argc, char *argv[ ] ) { 
        fe_dec_setround( 4 ); 
        printf( "fe_dec_rounding_mode : %d \n", fe_dec_getround() ); 
        volatile _Decimal64 x1DD = 8.0000000000000015DD; 
        volatile _Decimal64 x2DD = 8.0000000000000025DD; 

        printf( "Read in of 8.0000000000000015 produced : %.17DE \n", x1DD ); 
        printf( "Read in of 8.0000000000000025 produced : %.17DE \n", x2DD ); 
        printf( "In operation it works                  : %.17DE \n", x2DD +
5E-16DD ); 

        return( 0 ); 
} 
````  

It works, but doesn't round the constants as wanted:  

````  
└─$ ./round_constants_ties_away                                                 
fe_dec_rounding_mode : 4 
Read in of 8.0000000000000015 produced : 8.00000000000000200E+00 
Read in of 8.0000000000000025 produced : 8.00000000000000200E+00 
In operation it works                  : 8.00000000000000300E+00 
````

  parent reply	other threads:[~2024-02-06  0:48 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-17 17:41 [Bug c/113455] New: " newbie-02 at gmx dot de
2024-01-17 17:51 ` [Bug c/113455] " jsm28 at gcc dot gnu.org
2024-01-17 23:29 ` newbie-02 at gmx dot de
2024-01-18  0:20 ` jsm28 at gcc dot gnu.org
2024-01-18  6:41 ` newbie-02 at gmx dot de
2024-02-06  0:48 ` newbie-02 at gmx dot de [this message]
2024-02-07 20:28 ` jsm28 at gcc dot gnu.org
2024-02-10 13:43 ` newbie-02 at gmx dot de

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=bug-113455-4-8yztgzAdTX@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /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.
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 read-only IMAP folder(s) and NNTP newsgroup(s).