View previous topic :: View next topic |
Author |
Message |
galatar
Joined: 01 Oct 2008 Posts: 2
|
Mathematical library bug? |
Posted: Fri Nov 20, 2009 7:21 am |
|
|
I noticed the following strange problem:
Z=Y+X;
X is always nonnegative.
Y is usually 0.0
If presentation of Y is "0x00000000" everything is OK, but if presentation is "0x80000000" something very strange happens.
Z=Y+X = -X ??????
For example:
-0.0 + 88.36 = -88.36
I use PCD compiler Version 4.093 with dsPIC33FG128MC804.
My application used a big data stream from PC and it is very uncomfortable to check every time if value is equal to "0x80000000" and change the presentation to "0x00000000". |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Fri Nov 20, 2009 9:03 am |
|
|
Yes, still present with PCD V4.100.
Quote: | float x,y,z
x=-0.0;
y=1.0;
z=x+y; |
z gives -1.0 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Nov 20, 2009 1:29 pm |
|
|
It does work OK in the PCM and PCH compilers with vs. 4.100.
Results are:
Test program:
Code: |
#include <18F452.h>
#fuses XT,NOWDT,PUT,BROWNOUT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
//======================================
int8 main ()
{
float x,y,z;
x=-0.0;
y=1.0;
z=x+y;
printf("%3.2f \n\r", z);
while(1);
} |
|
|
|
|