Back to problems

Implement sin(x) with precision constraints

Algorithm · Snapchat · Hard

Write a function that accepts a radian angle x and a positive tolerance epsilon, and returns a double value y approximating sin(x) such that: $$\lvert y - \sin(x) \rvert \le \epsilon$$ You may not call built-in trigonometric functions such as sin, cos, or tan. Only basic arithmetic operations and numeric constants are allowed. Treat all arithmetic as IEEE-754 double operations. The checker accepts any floating-point output whose absolute error is within epsilon; the output…

Checking your access…