Talk:Square root

From Kolmafia
Revision as of 15:32, 29 June 2010 by imported>StDoodle
Jump to navigation Jump to search

It won't truncate -- integer truncation only occurs when you have one integer divided by another. If one of the two terms is a float, then the other will be automatically converted to a float before performing the operation. --Heeheehee 17:43, 26 June 2010 (UTC)

It can be a bit confusing for some. square_root() works a little differently than most math operations. For example:

float f; f = 5 / 2;

will return 2.0

This is, of course, because the operation has only integers to use, and thus computes an integer result; THEN it converts this to a float. If either of the two numbers is a float (ie "5.0 / 2" or "5 / 2.0") the result would be 2.5, as "expected," because when two different datatypes are used, an implicit conversion to the most precise type is the norm. So it is a bit "unexpected" that square_root() will accept an int, and make an automatic float conversion. We should probably note this somewhere... --StDoodle (#1059825) 15:32, 29 June 2010 (UTC)