News

from math import sin, cos, pi print(sin(pi/2)) # 1.0 print(cos(pi/2)) # 6.123233995736766e-17 The actual methods by which sin and cos are calculated are rather complicated (I’ll return to this in ...
This post is about how sin and cos are calculated in the c language standard math library on a typical Linux system. Because Python floats are really c doubles, what I write here will apply to Python ...
from functools import lru_cache from math import sin @lru_cache def sin_half(x): return sin(x)/2 Now, every time you run the decorated function, lru_cache will check for a cached result for the ...