#1336 powf(x,y) calculates wrong result

closed-duplicate
nobody
5
2007-05-22
2007-05-22
Björn
No

The function powf(x,2) calculates negative results when x > 0 and the result is in [0.5 to 1.0[.
Same with powf(x,5), so I guess it is the general behaviour with results in this range.

Code (file "main.c"):
--------------------------------------

#include "c8051f410.h" // SFR declarations
#include "math.h" // For float calculations

unsigned char _sdcc_external_startup (void)
{
// Disable watchdog
PCA0MD &= (unsigned char)(~0x40);
// Perform statics initialisation
return (0);
} /** _sdcc_external_startup **/

void main (void)
{
static volatile unsigned int i = 0;
static volatile float vfs2;

// VREF
P1_2 = 1;
// AIN1
P1_6 = 1;
// AIN0
P1_7 = 1;
// MISO
P0_1 = 1;
// RxD
P0_5 = 1;

// Debug code
vfs2 = powf (0.70, 2.0);
vfs2 = powf (0.71, 2.0);
vfs2 = powf (0.99, 2.0);
vfs2 = powf (1.00, 2.0);

while (1)
{
i++;
}
} // *** main ***

--------------------------------------

Results vfs2:
0.4900 = powf (0.70, 2.0);
-0.5041 = powf (0.71, 2.0);
-0.9801 = powf (0.99, 2.0);
1.0000 = powf (1.00, 2.0);
The results of this sample code have only been checked as watch variables in the debugger, but the same happens inside a bigger calculation with RS232 output of the result, so I don't think it's the debugger.

Program version:
2.6.0 #4309 (Jul 28 2006) (MINGW32)

Compile: \SDCC\bin\sdcc.exe -c --debug --use-stdout -V --opt-code-speed --model-large -dD -I\SDCC\Projects\bug \SDCC\Projects\bug\main.c

Link: \SDCC\bin\sdcc.exe --debug --use-stdout --model-large -V -I\SDCC\Projects\bug -o\SDCC\Projects\bug\main.hex \SDCC\Projects\bug\main.rel

Target: Cygnal/SiLabs C8051F410
Debugger: SiLabs IDE 2.91

Discussion

  • Jesus Calvino-Fraga

    • status: open --> closed-duplicate
     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks