Odd Math
-
Can anyone explain the results of this snippet?
model = Sketchup.active_model entities = model.entities selection = model.selection camera = model.active_view.camera cdir = camera.direction puts "camera dir; #{ cdir.inspect}" sum = cdir.x.abs + cdir.y.abs + cdir.z.abs puts "sum; #{sum.inspect}" puts "sum == 1? #{sum == 1}"Results:
camera dir; Vector3d(0, 1, 0) sum; 1 sum == 1? false -
Yes. .to_s / .inspect print an approximation of the Float value. When it prints (0,1,0), thats just the answer to 4 significant figures. Your Float(1) comparison simply shows that difference.
-
Thanks Adam. I still don't understand why sum (which is a Float)shown as 1 instead of 1.0
Might the .inspect method be over-ridden?
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better π
Register LoginAdvertisement