Why do binary arithmetic operations sometimes result in different outputs?

  • Thread starter Thread starter megaflop
  • Start date Start date
  • Tags Tags
    Binary Error
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
5 replies · 2K views
megaflop
Messages
10
Reaction score
0
Hello everyone !
I got a problem, I can't figure out why when I compute [itex]A+B[/itex] and [itex]2\times (\frac{A}{2}+\frac{B}{2})[/itex] the result is sometimes different.
Can anyone explain why the results of the two operations are different ?

Edit : A and B are coded in binary of course and we compute a binary addition.
 
Engineering news on Phys.org
Are you using integer or floating point ?

My guess is former , and one of the numerators is an odd number.
 
Integers I forgot to mention sorry.
 
Well there you go.

Got Basic?

FOR I = 1 , 10 , 1
PRINT I, INT( I/2)
NEXT I
END
 
jim hardy said:
Well there you go.

Got Basic?

FOR I = 1 , 10 , 1
PRINT I, INT( I/2)
NEXT I
END

I see thank you :) .
 
megaflop said:
Integers I forgot to mention sorry.
Does only "misbehave" if you're using one or more odd integers? :rolleyes: