0 votes

zero returned by trigonometric functions are greater than zero

func _ready():
        print('--------')
        print(sin(PI))
        print(sin(PI)>0)
        print('--------')
        print(cos(PI/2))
        print(cos(PI/2)>0)
        print('--------')

output

--------
0
True
--------
0
True

Is this expected behavior?

Godot version v3.2.3
in Engine by (12 points)

1 Answer

0 votes

While I don't know if it's expected, I wouldn't say it's unexpected. Floating point values are a nasty business under the covers... For example, if I print one of your samples out to a sufficient number of decimals, I do see some positive lean. So...

print("%.20f" % sin(PI))

returns 0.00000000000000010000

by (16,666 points)

Moreover, see the is_equal_approx function if you need some well-behaved comparisons

https://docs.godotengine.org/en/stable/classes/[email protected]#class-gdscript-method-is-equal-approx

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.