cgccdebianheader-filesmath.h

How can I find the declaration of sin function in math.h file of GCC in Debian Linux?


I read about C programming language in Yashwant Kanetkar's book Let us C. In Functions chapter I read about sin, cos, tan and pow functions of math.h file. But in this chapter it is written that:

You can even open this math.h file and look at the prototypes. They would appear as shown below:

double sin ( double ) ; 
double cos ( double ) ; 
double tan ( double ) ; 
double pow ( double, double ) ;

I am using the Debian Linux and the math.h file is present in /usr/include folder. I opened this math.h file in this folder and read the whole file but I don't get this declaration.

Can you help me where can I find the declaration of sin function of math.h file. If this declaration is not written directly in this file but is linked to another math library file then let me know about that file. I would like to see the exact declaration of the sin function of the math.h header file of the C programming language.

When I opened the math.h file present in the /usr/include folder of my Debian Linux I did not see any lines that looked like declaration of sin function or any other functions like cos,tan,sqrt etc. I can only see the values ​​of constants like M_PI, M_LOG2E etc.

The first few lines of the math.h file in my system are as follows:

#ifndef _MATH_H
#define _MATH_H 1

#define __GLIBC_INTERNAL_STARTING_HEADER_IMPLEMENTATION
#include <bits/libc-header-start.h>

#if defined log && defined __GNUC__
# warning A macro called log was already defined when <math.h> was included.
# warning This will cause compilation problems.
#endif

__BEGIN_DECLS

/* Get definitions of __intmax_t and __uintmax_t.  */
#include <bits/types.h>

/* Get machine-dependent vector math functions declarations.  */
#include <bits/math-vector.h>

/* Gather machine dependent type support.  */
#include <bits/floatn.h>

/* Value returned on overflow.  With IEEE 754 floating point, this is
   +Infinity, otherwise the largest representable positive value.  */
#if __GNUC_PREREQ (3, 3)
# define HUGE_VAL (__builtin_huge_val ())
#else
/* This may provoke compiler warnings, and may not be rounded to
   +Infinity in all IEEE 754 rounding modes, but is the best that can
   be done in ISO C while remaining a constant expression.  10,000 is
   greater than the maximum (decimal) exponent for all supported
   floating-point formats and widths.  */
# define HUGE_VAL 1e10000
#endif
#ifdef __USE_ISOC99
# if __GNUC_PREREQ (3, 3)
#  define HUGE_VALF (__builtin_huge_valf ())
#  define HUGE_VALL (__builtin_huge_vall ())
# else
#  define HUGE_VALF 1e10000f
#  define HUGE_VALL 1e10000L
# endif
#endif
#if __HAVE_FLOAT16 && __GLIBC_USE (IEC_60559_TYPES_EXT)
# define HUGE_VAL_F16 (__builtin_huge_valf16 ())
#endif
#if __HAVE_FLOAT32 && __GLIBC_USE (IEC_60559_TYPES_EXT)
# define HUGE_VAL_F32 (__builtin_huge_valf32 ())
#endif
#if __HAVE_FLOAT64 && __GLIBC_USE (IEC_60559_TYPES_EXT)
# define HUGE_VAL_F64 (__builtin_huge_valf64 ())
#endif
#if __HAVE_FLOAT128 && __GLIBC_USE (IEC_60559_TYPES_EXT)
# define HUGE_VAL_F128 (__builtin_huge_valf128 ())
#endif
#if __HAVE_FLOAT32X && __GLIBC_USE (IEC_60559_TYPES_EXT)
# define HUGE_VAL_F32X (__builtin_huge_valf32x ())
#endif
#if __HAVE_FLOAT64X && __GLIBC_USE (IEC_60559_TYPES_EXT)
# define HUGE_VAL_F64X (__builtin_huge_valf64x ())
#endif
#if __HAVE_FLOAT128X && __GLIBC_USE (IEC_60559_TYPES_EXT)
# define HUGE_VAL_F128X (__builtin_huge_valf128x ())
#endif

#ifdef __USE_ISOC99
/* IEEE positive infinity.  */
# if __GNUC_PREREQ (3, 3)
#  define INFINITY (__builtin_inff ())
# else
#  define INFINITY HUGE_VALF
# endif

/* IEEE Not A Number.  */
# if __GNUC_PREREQ (3, 3)
#  define NAN (__builtin_nanf (""))
# else
/* This will raise an "invalid" exception outside static initializers,
   but is the best that can be done in ISO C while remaining a
   constant expression.  */
#  define NAN (0.0f / 0.0f)
# endif
#endif /* __USE_ISOC99 */


Solution

  • You can even open this math.h file and look at the prototypes.

    This is by no means certain. The C language does not require

    Can you help me where can I find the declaration of sin function of math.h file.

    On Debian Linux, you're almost certainly using the GNU C library. In its math.h, you will find some directives of the form

    #include <bits/mathcalls.h>
    

    These each bring in the contents of the designated file, expanded according to different sets of macro definitions. The resulting macro-expanded declarations in my copy of Glibc include (reformatted):

    extern double cos(double __x) __attribute__ ((__nothrow__ , __leaf__));
    extern double sin(double __x) __attribute__ ((__nothrow__ , __leaf__));
    extern double tan(double __x) __attribute__ ((__nothrow__ , __leaf__));
    extern double pow(double __x, double __y) __attribute__ ((__nothrow__ , __leaf__));
    

    Do not concern yourself with the __attribute__ stuff. That's a GNU extension that you don't need to know or care about at this point in your journey.