[Bug c/88451] No rounding in fixed-point arithmetic (Decimal to fixed-point conversion, multiplication)

2019-08-05 Thread mantas.mikaitis at manchester dot ac.uk
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88451

--- Comment #5 from Mantas Mikaitis  
---
Hello,

I am raising this again. Has anyone had a change to confirm my testcases fail
in the latest version of the compiler?

Kind regards,
Mantas Mikaitis

[Bug c/88451] New: No rounding in fixed-point arithmetic (Decimal to fixed-point conversion, multiplication)

2018-12-11 Thread mantas.mikaitis at manchester dot ac.uk
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88451

Bug ID: 88451
   Summary: No rounding in fixed-point arithmetic (Decimal to
fixed-point conversion, multiplication)
   Product: gcc
   Version: 6.3.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: mantas.mikaitis at manchester dot ac.uk
  Target Milestone: ---

Hello,

This bug report is about that there is no rounding in various parts of the
fixed-point arithmetic. Here are some cases run on ARM968:

1)

accum x = 0.04k; // This ends up as 0.03997802734375.



2)

double x = 0.04;
accum y = x; // This ends up as 0.03997802734375.



As you can notice, 0.04 is rounded down to 0.03997802734375, however, the
nearest accum to the 0.04 is 0.040008544921875.

3)

Multiplication of two accums results in a 63-bit value which needs to be
shifted right to put the result back to the accum type. Upon a shift, there is
no rounding and 15 bottom bits are truncated.



It seems to be doing binary truncation instead of rounding, which is also
mathematically legal operation, but introduces a larger error. Looking into the
ISO draft standard for fixed-point arithmetic, it specifies that
FX_FULL_PRECISION pragma can be used to obtain full precision:
http://www.open-std.org/jtc1/sc22/wg14/www/docs/n968.pdf, but it seems to have
no effect when I turn it on.

I am working with gcc version 6.3.1 20170620 (release) [ARM/embedded-6-branch
revision 249437] (GNU MCU Eclipse ARM Embedded GCC, 64-bits).

Many thanks,
Mantas M.

[Bug target/88451] No rounding in fixed-point arithmetic (Decimal to fixed-point conversion, multiplication)

2018-12-12 Thread mantas.mikaitis at manchester dot ac.uk
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88451

--- Comment #2 from Mantas Mikaitis  
---
Created attachment 45212
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=45212&action=edit
3 simple testcases

[Bug target/88451] No rounding in fixed-point arithmetic (Decimal to fixed-point conversion, multiplication)

2018-12-12 Thread mantas.mikaitis at manchester dot ac.uk
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88451

--- Comment #3 from Mantas Mikaitis  
---
Also confirmed on GCC version 7.3.0.

[Bug target/88451] No rounding in fixed-point arithmetic (Decimal to fixed-point conversion, multiplication)

2018-12-12 Thread mantas.mikaitis at manchester dot ac.uk
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88451

Mantas Mikaitis  changed:

   What|Removed |Added

 CC||mantas.mikaitis@manchester.
   ||ac.uk

--- Comment #4 from Mantas Mikaitis  
---
Created attachment 45214
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=45214&action=edit
Fixed testcases

Uploaded an update to the testcase - compare as accums not integers.