r/C_Programming • u/New_Telephone926 • Aug 18 '26
Question How are functions in libm actually implemented ?
I'm trying to gather information for a school project about how elementary functions (exp, log, cos, sin, etc.) are implemented on computers, for maximum accuracy and efficiency.
I've already found some information about techniques that can be used to implement these functions, such as range reduction, Taylor series, polynomial approximations or minimax approximations. However, most of what I've found remains fairly theoretical, and I have no idea of what is actually used in the real world.
I tried to reverse-engineer the exp implementation in libm, but my knowledge of C and its intricacies is still fairly limited (though I'm working on improving it).
I'm particularly interested in understanding which approximation methods are actually used, how polynomial coefficients are chosen (Taylor, minimax/Remez, or other), and how implementations balance speed and accuracy.
But really, if you have any information whatsoever, it would be great.
If anyone has documentation, papers, or personal experience with this kind of subject, it would be really helpful.
Thanks in advance!
Edit : Thanks a lot to everyone ! You gave me exactly what I was looking for
View all comments
Show parent comment
2
u/FUZxxl Aug 18 '26
The first FPU was built by Konrad Zuse in 1942 (Zuse Z3). It could do addition, subtraction, multiplication, division, square-root, and conversion from and to decimal on normalised binary floating point numbers. It had support for trapping on overflow, division by zero, and square-root of negative numbers.
Subsequently many different floating point units were built, slowly converging on a normalised binary representation. Kahan than introduced a fast way to do denormal numbers in the 8087 and agreed to share how its done with the competition in exchange for that becoming the standard. Many of the earlier FPUs are otherwise very similar to modern ones, just using a different floating-point representation. For example, S/360 famously used decimal or hexadecimal floating-point.