• Home   /  
  • Archive by category "1"

C Language Reference Math Homework

math.h is a header file in the standard library of the C programming language designed for basic mathematical operations. Most of the functions involve the use of floating point numbers. C++ also implements these functions for compatibility reasons and declares them in the header (the C99 functions are not available in the current C++ standard, C++ 98).

All functions that take or return an angle work in radians.

All functions take s for floating-point arguments, unless otherwise specified. In C99, to work with s or s, append an or an to the name, respectively.

Mathematical library functions that operate on integers, such as , , , and , are instead specified in the stdlib.h header.

Pre-C99 functions[edit]

inverse cosine
inverse sine
one-parameter inverse tangent
two-parameter inverse tangent
ceiling, the smallest integer not less than parameter
hyperbolic cosine
exponential function
absolute value (of a floating-point number)
floor, the largest integer not greater than parameter
floating-point remainder:
break floating-point number down into mantissa and exponent
scale floating-point number by exponent (see article)
natural logarithm
base-10 logarithm
returns fractional part of x and stores integral part where pointer p points to
raise x to the power of y, xy
hyperbolic sine
square root
hyperbolic tangent]]

(For functions to convert strings to floating point numbers (atof(), strtod(), etc.), see C Programming/C Reference/stdlib.h.)

(For functions to convert floating point numbers to strings (snprintf(), itoa(), etc.), see C Programming/C Reference/stdio.h and C_Programming/C_Reference/stdlib.h#itoa.)

C99 functions[edit]

inverse hyperbolic cosine
inverse hyperbolic sine
inverse hyperbolic tangent
cube root
returns the value of x with the sign of y
error function
complementary error function
raise 2 to the power of x, 2x
one less than the exponential of x, ex − 1
positive difference between x and y, fmax(xy, 0)
multiply and add, (x * y) + z
largest value of x and y
smallest value of x and y
hypotenuse, sqrt(x2 + y2)
the exponent of a floating-point value, converted to an
natural log of the absolute value of the gamma function
round to integer (returns ) using current rounding mode
round to integer (returns ) using current rounding mode
round to integer (returns )
round to integer (returns )
natural logarithm of 1 + x
base-2 logarithm
extract exponent from floating-point number
returns NaN, possibly using string argument
round floating-point number to nearest integer
returns next representable value after x (towards y)
same as , except y is always a
calculates remainder, as required by IEC 60559
same as , but store quotient (as ) at target of pointer p
round to integer (returns ) using current rounding mode
round to integer (returns ), rounding halfway cases away from zero
x * n (n is )
x * n (n is )
gamma function
truncate floating-point number

XSI Extensions[edit]

Extra functions may be available as X/Open System Interfaces Extensions. These are not present in any ANSI or ISO C standard.

Bessel function of x of the first kind of order 0
Bessel function of x of the first kind of order 1
Bessel function of x of the first kind of order n
x * y (x and y are s)
Bessel function of x of the second kind of order 0
Bessel function of x of the second kind of order 1
Bessel function of x of the second kind of order n

The -to-string conversion functions , and have been deprecated in favour of .

Mathematical constants (not standard)[edit]

The base of natural logarithms.
The logarithm to base 2 of M_E.
The logarithm to base 10 of M_E.
The natural logarithm of 2.
The natural logarithm of 10.
Pi, the ratio of a circle's circumference to its diameter.
Pi divided by two.
Pi divided by four.
The reciprocal of pi (1/pi).
Two times the reciprocal of pi.
Two times the reciprocal of the square root of pi.
The square root of two.
The reciprocal of the square root of two (also the square root of 1/2).

All values are of type double. As an extension, the GNU C library also defines these constants with type long double. The long double macros have a lowercase ‘l’ appended to their names: M_El, M_PIl, and so forth. These are only available if _GNU_SOURCE is defined.

Note: Some programs use a constant named PI which has the same value as M_PI. This constant is not standard; it may have appeared in some old AT&T headers, and is mentioned in Stroustrup's book on C++. It infringes on the user's name space, so the GNU C library does not define it. Fixing programs written to expect it is simple: replace PI with M_PI throughout, or put ‘-DPI=M_PI’ on the compiler command line.

While these constants are common, they are not part of the C standard, so most modern compilers require an explicit definition (such as _USE_MATH_DEFINES in Microsoft Visual C++ [1]) for them to be defined when including math.h.

External links[edit]


  1. ↑Math Constants, MSDN.

The C Library Reference Guide

by Eric Huss
© Copyright 1997 Eric Huss

Release 1

Introduction 1. Language 1.1 Characters 1.1.1 Trigraph Characters 1.1.2 Escape Sequences 1.1.3 Comments 1.2 Identifiers 1.2.1 Keywords 1.2.2 Variables 1.2.3 Enumerated Tags 1.2.4 Arrays 1.2.5 Structures and Unions 1.2.6 Constants 1.2.7 Strings 1.2.8 sizeof Keyword 1.3 Functions 1.3.1 Definition 1.3.2 Program Startup 1.4 References 1.4.1 Pointers and the Address Operator 1.4.2 Typecasting 1.5 Operators 1.5.1 Postfix 1.5.2 Unary and Prefix 1.5.3 Normal 1.5.4 Boolean 1.5.5 Assignment 1.5.6 Precedence 1.6 Statements 1.6.1 if 1.6.2 switch 1.6.3 while 1.6.4 do 1.6.5 for 1.6.6 goto 1.6.7 continue 1.6.8 break 1.6.9 return 1.7 Preprocessing Directives 1.7.1 #if, #elif, #else, #endif 1.7.2 #define, #undef, #ifdef, #ifndef 1.7.3 #include 1.7.4 #line 1.7.5 #error 1.7.6 #pragma 1.7.7 Predefined Macros 2. Library 2.1 assert.h 2.1.1 assert 2.2 ctype.h 2.2.1 is... Functions 2.2.2 to... Functions 2.3 errno.h 2.3.1 EDOM 2.3.2 ERANGE 2.3.3 errno 2.4 float.h 2.4.1 Defined Values 2.5 limits.h 2.5.1 Defined Values 2.6 locale.h 2.6.1 Variables and Definitions 2.6.2 setlocale 2.6.3 localeconv 2.7 math.h 2.7.1 Error Conditions 2.7.2 Trigonometric Functions acos asin atan atan2 cos cosh sin sinh tan tanh 2.7.3 Exponential, Logarithmic, and Power Functions exp frexp ldexp log log10 modf pow sqrt 2.7.4 Other Math Functions ceil fabs floor fmod 2.8 setjmp.h 2.8.1 Variables and Definitions 2.8.2 setjmp 2.8.3 longjmp 2.9 signal.h 2.9.1 Variables and Definitions 2.9.2 signal 2.9.3 raise 2.10 stdarg.h 2.10.1 Variables and Definitions 2.10.2 va_start 2.10.3 va_arg 2.10.4 va_end 2.11 stddef.h 2.11.1 Variables and Definitions 2.12 stdio.h 2.12.1 Variables and Definitions 2.12.2 Streams and Files 2.12.3 File Functions clearerr fclose feof ferror fflush fgetpos fopen fread freopen fseek fsetpos ftell fwrite remove rename rewind setbuf setvbuf tmpfile tmpnam 2.12.4 Formatted I/O Functions ...printf Functions ...scanf Functions 2.12.5 Character I/O Functions fgetc fgets fputc fputs getc getchar gets putc putchar puts ungetc 2.12.7 Error Functions perror 2.13 stdlib.h 2.13.1 Variables and Definitions 2.13.2 String Functions atof atoi atol strtod strtol strtoul 2.13.3 Memory Functions calloc free malloc realloc 2.13.4 Environment Functions abort atexit exit getenv system 2.13.5 Searching and Sorting Functions bsearch qsort 2.13.6 Math Functions abs div labs ldiv rand srand 2.13.7 Multibyte Functions mblen mbstowcs mbtowc wcstombs wctomb 2.14 string.h 2.14.1 Variables and Definitions 2.14.2 memchr 2.14.3 memcmp 2.14.4 memcpy 2.14.5 memmove 2.14.6 memset 2.14.7 strcat 2.14.8 strncat 2.14.9 strchr 2.14.10 strcmp 2.14.11 strncmp 2.14.12 strcoll 2.14.13 strcpy 2.14.14 strncpy 2.14.15 strcspn 2.14.16 strerror 2.14.17 strlen 2.14.18 strpbrk 2.14.19 strrchr 2.14.20 strspn 2.14.21 strstr 2.14.22 strtok 2.14.23 strxfrm 2.15 time.h 2.15.1 Variables and Definitions 2.15.2 asctime 2.15.3 clock 2.15.4 ctime 2.15.5 difftime 2.15.6 gmtime 2.15.7 localtime 2.15.8 mktime 2.15.9 strftime 2.15.10 timeAppendix AASCII ChartIndexIndex
Questions, comments, or error reports? Please send them to Eric Huss

One thought on “C Language Reference Math Homework

Leave a comment

L'indirizzo email non verrà pubblicato. I campi obbligatori sono contrassegnati *