0

I'm trying to find which angle has this sin but it's not working!!!

I wanted to find which angle has this sin value, I didn't find anything useful online so I decided to automate it myself. As you can see everything is in order I converted to radians and every thing seems fine except no! I tried to test it using 0.5 (sin(30) = 0.5) as input but it didn't work! I figured it's a floating point problem which is 0.1 + 0.2 == 0.3 returns false If want to learn more see below But I want to make sure it's not me and there's no way to fix it, so if anyone can tell me I'm wrong or how to fix it I'd be very grateful https://code.sololearn.com/cVy7WLjPFw54/?ref=app https://stackoverflow.com/questions/588004/is-floating-point-math-broken#:~:text=The%20expression%200.1%20%2B%200.2%20%3D%3D%3D,can%20be%20avoided%20by%20scaling.

2nd Jun 2020, 3:30 PM
12ksins
12ksins - avatar
2 Antworten
+ 3
Try using the round function. When rounding to 2 decimal places and entering 0.5 for input I received this as output; 30 the sun is 0.4999999999999 inp = round(float(input()), 2) if inp == round(math.sin(t), 2):
2nd Jun 2020, 4:05 PM
ChaoticDawg
ChaoticDawg - avatar
+ 1
ChaoticDawg thanks it works till 15, really thought round is going to bring the same problem, thanks again!
2nd Jun 2020, 4:26 PM
12ksins
12ksins - avatar