+ 1

why -7 / 3 = -3 in ruby ??

puts (-7/3) produce -3

1st Nov 2016, 8:57 AM
sagar pednekar
sagar pednekar - avatar
2 Answers
+ 5
-7/3 = -3 -7.0/3 = -2.333 Great question :) The rule is that without having the decimal fraction point, ".", all the results are presented in floor function mode, which mathematically is the largest integer smaller than the result: [x] = max{ n ∈ Z | n<= x }
5th Nov 2016, 4:24 AM
Hamidreza Fathi
Hamidreza Fathi - avatar
0
because rule of signs: -/+ = -
2nd Nov 2016, 5:19 AM
Adalberto Vargas
Adalberto Vargas - avatar