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
1
u/EpochVanquisher Aug 19 '26
In my mind, if it’s an FPU, it’s a part of a larger system, like how a CPU or an ALU are.
If it’s “modern”, then it’s IEEE 754, or close to it. If you want to strip away the IEEE 754 requirement then I’d say a “modern” design has correct rounding, binary radix, infinities, and denormals, at the very least. It would also execute instructions in a stream mixed with non-FPU instructions, rather than a separate stream of floating-point instructions.
By this sense, 1980 is the rough demarcation between modern FPU designs and older designs. By coincidence, this coincides with the design trend to limit what processors do per instruction, so the newer FPU designs don’t have transcendental functions, but some old ones do.