# Why sin() and cos() Can Be Slow: Range Reduction, C Library Calls, and FPU Trigonometry

DevFeed: [Why sin() and cos() Can Be Slow: Range Reduction, C Library Calls, and FPU Trigonometry](<https://devfeed.tech/articles/help-my-sin-is-slow-and-my-fpu-is-inaccurate-36426.md>)

Original publisher: [Read original article](<https://berthub.eu/articles/posts/help-my-sin-is-slow-and-my-fpu-is-inaccurate/>)

Published: 2021-06-19T12:53:25Z

Content type: tutorial

Language: en

Sources: [Bert Hubert's writings](<https://devfeed.tech/sources/bert-hubert-s-writings.md>)

Topics: [C](<https://devfeed.tech/topics/c.md>), [cpu](<https://devfeed.tech/topics/cpu.md>), [Linux](<https://devfeed.tech/topics/linux.md>), [Algorithm](<https://devfeed.tech/topics/algorithm.md>)

Tags: [algorithm](<https://devfeed.tech/tags/algorithm.md>), [c](<https://devfeed.tech/tags/c.md>), [cpu](<https://devfeed.tech/tags/cpu.md>), [floating-point](<https://devfeed.tech/tags/floating-point.md>), [fpu](<https://devfeed.tech/tags/fpu.md>), [linux](<https://devfeed.tech/tags/linux.md>), [programming](<https://devfeed.tech/tags/programming.md>)

## AI overview

This technical article investigates why a C simulation became unexpectedly slow when calling sin(). Experiments showed that replacing sin() with cos() or changing M_PI altered performance, leading to an examination of generated assembly and C library calls. The article explains range reduction and approximation methods such as Taylor series, lookup tables, and CORDIC as factors in trigonometric performance and accuracy.

## Source excerpt

Afer 8 years, I have updated this this post for 2021-era Linux (and also to fix bitrotted links). I am extremely joyful to report that the (hard) problem from 2013 appears to have been solved! There is a small addendum at the end to reflect this happy news. Back in 2013, I started writing code to do a simulation of biological system, and I got stuck after 20 lines. My test code tried to go through a million time steps doing basically nothing, and it was taking a minute to do it.