Why does 1019/250*250-1019 not equal 0 in Matlab?

  • Context: MATLAB 
  • Thread starter Thread starter gerben
  • Start date Start date
  • Tags Tags
    Integers Matlab
Join the discussion
Registration is free. Start your own thread to ask a follow-up.
1 reply · 38K views
gerben
Messages
511
Reaction score
1
Does anyone have an idea why this expression in Matlab with integers does not give zero as an answer:

>> 1019 / 250 * 250 - 1019
ans = -1.1369e-013
 
Physics news on Phys.org
AFAIK, MATLAB doesn't specifically store an integer variable type.

If you need to be sure you have an integer output, use either:

fix(input)

or

floor(input)

to round it to the nearest or down to the next lowest integer.

Functions such as int2str automatically have a fix() in the command definition.