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 18 '26
You have it backwards—people used to implement these directly in the ISA, back in the days of the x87 FPU and some others. Modern hardware mostly has basic arithmetic, and the functions in libm are software.
There are a couple exceptions (sqrt is often part of the ISA).