Consider this code
x = 0.109354682484;
IntegerPart[x/(x/2)]
(* 1 *)
Precision[x]
(* MachinePrecision *)
Why does it give 1 ?
Version number: 9.0 on Mac 10.9.2
screenshot
Update:
If we use an undefined variable, IntegerPart[x0/(x0/2)]
gives 2. Since Mathematica never gives warnings about this x0
, I'm assuming for any x0
it is true.
If we calculate the same integer part using fortran, we get 2 instead of 1.
program main
implicit none
real(8):: x=0.109354682484
real(8):: y=1.4
write(*,*) int(x/(x/2))
write(*,*) nint(x/(x/2))
write(*,*) int(y)
end program main
compiled with ifort -O0 main.f90
output of above fortran code is
2
2
1
according to here, int is a fortran intrinsic function that calculate the integer part.
Is this a bug?
FullForm
of the result ofx/(x/2)
. $\endgroup$IntegerPart[1.9999999999999998]
to return? $\endgroup$x/(x/2)
? $\endgroup$