Newbie ActionScript 3 question: why does
(Math.sqrt((r * r - (r - i) * (r - i)) as Number) * 2) as int
give me a different result from
int(Math.sqrt((r * r - (r - i) * (r - i)) as Number) * 2)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The
asoperator is a direct cast, whereasint()implicitly finds the floor of the Number (note that it doesn’t actually callMath.floor, though). The Adobe docs forassay it checks that the “first operand is a member of the data type specified by the second operand.” Since 9.59 is not representable as an int, theascast fails a returns null, whileint()first finds the floor of the number, then casts it to int.You could do
Math.floor(blah) as int, and it should work, though it would be slower. Assuming you want a rounded int,Math.round(blah) as intwould be more correct, butint(blah + .5)would be fastest and round correctly.