Talk:Square root

From Kolmafia
Revision as of 20:10, 29 June 2010 by imported>Bale (A function is not an operator!)
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)

  • Whoa, whoa, WHOA! What the heck are you going on about? square_root() is a function that returns a float. It's not a mathematical operator. Like any other function it will always return a value of the appropriate type, even if its parameters are integers. Do you think it is somehow tricky for a function that takes integer parameters to return a float? That's just silly. --Bale 20:10, 29 June 2010 (UTC)