Why do binary arithmetic operations sometimes result in different outputs?

  • Thread starter Thread starter megaflop
  • Start date Start date
  • Tags Tags
    Binary Error
Click For Summary

Discussion Overview

The discussion revolves around the differences in outputs when performing binary arithmetic operations, specifically comparing the results of A+B and 2×(A/2 + B/2) when A and B are integers represented in binary. The scope includes conceptual understanding and technical reasoning related to binary addition.

Discussion Character

  • Exploratory, Technical explanation, Conceptual clarification

Main Points Raised

  • One participant questions why the results of A+B and 2×(A/2 + B/2) can differ, specifically in the context of binary addition.
  • Another participant inquires whether the numbers involved are integers or floating-point, suggesting that the issue may arise from using odd integers.
  • A participant confirms that they are indeed using integers, which leads to further exploration of the behavior of binary arithmetic with odd integers.
  • There is a suggestion that the discrepancy in results may only occur when one or both of the integers are odd.

Areas of Agreement / Disagreement

Participants have not reached a consensus on the exact reason for the differing outputs, and multiple viewpoints regarding the influence of odd integers remain present.

Contextual Notes

Participants have not fully explored the implications of integer representation in binary or the specific conditions under which the operations yield different results.

Who May Find This Useful

This discussion may be useful for those interested in binary arithmetic, computer science, and the nuances of integer operations in programming.

megaflop
Messages
10
Reaction score
0
Hello everyone !
I got a problem, I can't figure out why when I compute A+B and 2\times (\frac{A}{2}+\frac{B}{2}) 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:
 

Similar threads

Replies
2
Views
1K
  • · Replies 29 ·
Replies
29
Views
3K
  • · Replies 17 ·
Replies
17
Views
9K
Replies
2
Views
7K
  • · Replies 13 ·
Replies
13
Views
2K
Replies
5
Views
3K
  • · Replies 15 ·
Replies
15
Views
4K
  • · Replies 14 ·
Replies
14
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
Replies
11
Views
2K