#1243 expf() broken

closed-fixed
nobody
5
2006-11-21
2006-11-20
No

The code listed below was compiled using

sdcc --model-large expfbug.c

SDCC : mcs51/gbz80/z80/avr/ds390/pic16/pic14/TININative/xa51/ds400/hc08 2.6.1 #4472 (Oct 21 2006) (MSVC)

The function expf gives wrong sign for small negative values of x:

expf( 0.00)= 1.00000000
expf(-0.10)= -0.90483751
expf(-0.20)= -0.81873074
expf(-0.30)= -0.74081826
expf(-0.40)= -0.67032003
expf(-0.50)= -0.60653067
expf(-0.60)= -0.54881163
expf(-0.70)= 0.49658532
expf(-0.80)= 0.44932899
expf(-0.90)= 0.40656967
expf(-1.00)= 0.36787944

The code:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <serial_io.h>

void main (void)
{
float x;
unsigned char i;

for(i=0; i<10; i++)
{
x=i*(-1.0/10.0);
printf("expf(%5.2f)=%12.8f\n", x, expf(x));
}
}

The right answer should be:

expf( 0.00)= 1.00000000
expf(-0.10)= 0.90483742
expf(-0.20)= 0.81873074
expf(-0.30)= 0.74081821
expf(-0.40)= 0.67032003
expf(-0.50)= 0.60653067
expf(-0.60)= 0.54881163
expf(-0.70)= 0.49658532
expf(-0.80)= 0.44932899
expf(-0.90)= 0.40656962
expf(-1.00)= 0.36787944

Discussion

  • Jesus Calvino-Fraga

    Logged In: YES
    user_id=603650
    Originator: YES

    Fixed in revision 4475.

     
  • Jesus Calvino-Fraga

    • status: open --> closed-fixed
     

Log in to post a comment.

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

Sign up for the SourceForge newsletter:





No, thanks