The Wayback Machine - https://web.archive.org/web/20200422183803/http://cplusplus.com/forum/general/269810/

 
Is the math.h library written in binary or c language?

Can anyone tell me if the implementation of functions of cmath library is in binary or C?
Last edited on
Math.h is a header file. Thus, it is written in C. Also, this forum is for C++.
glibc actually may have platform-specific ASM for some functionality. Not necessarily fully written in ASM, but some internal functions may be.

https://ftp.gnu.org/gnu/libc/
For example, in
glibc-2.31/sysdeps/x86_64/fpu

There is assembly.

e_sqrt.c
1
2
3
4
5
6
7
8
9
double
__ieee754_sqrt (double x)
{
  double res;

  asm ("sqrtsd %1, %0" : "=x" (res) : "xm" (x));

  return res;
}
Last edited on
@TheToaster
C++ is a proper superset of C. I see no reason why C-related questions would be unwelcome here.

@shubham1355
New thread for the same question? Or are we following an X-Y problem? (What is is you are really trying to do?)

@Ganado
That example is just the C-to-assembly interface for using the processor sqrt function over doubles.

Every compiler vendor will generally provide assembly routines for math functions on the architectures it compiles for. Some functions, like cube root, are unlikely to have a direct processor instruction to compute, necessitating a simple, tight assembly routine. Everything else will, as you posted, simply have a small function that simply frobs the assembler.
Sorry, but did I claim it was something else? Maybe my terminology was incorrect.
The directory I posted has many other assembly examples, btw (view with dutch's link)
Last edited on
Registered users can post here. Sign in or register to post.