#865 erroneous addition

closed-rejected
nobody
5
2013-05-25
2005-01-19
Anonymous
No

hello

I found this bug while handling big numbers on 8051
with sdcc.

an addition with huge numbers in some conditions
doesn't give the expected result ...

I'm sorry i couldn't put out all the library code coz
the bug is visible only at execution time, but if you
have an available printf, you can use the lines 29 to 54.

command for compiling main.c :
> sdcc --model-large -c main.c -I ../../modules_8051 -I .
and the project :
> sdcc --model-large main.rel lcd.rel i2c.rel
wait.rel utils.rel --xram-loc 0x7000

my sdcc version :
mcs51/gbz80/z80/avr/ds390/pic16/pic14/TININative/xa51/ds400/hc08
2.4.7 #9
28 (Jan 18 2005) (MINGW32)

so in main.c i simply add a value to a structure
member, and the result is false ( 451000000 + 12500
gives 451012512)

regards

Christophe
riehl@enseirb.fr

Discussion

  • Nobody/Anonymous

    main program

     
  • Maarten Brock

    Maarten Brock - 2005-01-19
    • milestone: --> non_bugs
    • status: open --> closed-rejected
     
  • Maarten Brock

    Maarten Brock - 2005-01-19

    Logged In: YES
    user_id=888171

    Cristophe,

    There are only 22 bits of accuracy in a float. Your code
    expects more:

    signed long rx_freq = 451000000; // the error appears only on
    some huge numbers
    rx_freq += 12.5 * 1000l; // the error seems to come from the
    way entering the constant, using "12500" is ok

    means:
    signed long rx_freq = 451000000;
    rx_freq = (long)( (float)rx_freq + ((float)12.5 * (long)1000) );

    This is no bug, but specified behaviour

     

Log in to post a comment.