Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

145
Views
Why is JavaScript calculating some cosine and sine values as a decimal, but for others an integer?

I'm using x + (distance * Math.cos(orientation * Math.PI)) and y + (distance * Math.sin(orientation * Math.PI)) to calculate xx and yy respectively.

50 + (20 * Math.sin(1 * Math.PI)) and 50 + (20 * Math.cos(0.5 * Math.PI)) equal 50

but

50 + (20 * Math.sin(2 * Math.PI)) and 50 + (20 * Math.cos(1.5 * Math.PI)) equal 49.99999999999999?

I expected 50 here too. Is it a javascript quirk I need to use Math.ceil() with (calculating coords on a canvas)?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!