math.h first appears in 7th Research Unix. It is hard to tell how it got there. For example, [1] claims that bits of C library were merged from "PWB/Unix" which included troff and C compiler pcc, but I cannot prove it.

Another interesting piece of information is library manual from V7 Unix: intro.3:

(3)   These functions, together with those of section 2 and those marked (3S),
      constitute library libc, which is automatically loaded by the C compiler
      cc(1) and the Fortran compiler f77(1).  The link editor  ld(1)  searches
      this  library  under  the  `-lc' option.  Declarations for some of these
      functions may be obtained from include files indicated on the  appropri-
      ate pages.

<...>

(3M)  These  functions  constitute the math library, libm.  They are automati-
      cally loaded as needed by the Fortran compiler f77(1).  The link  editor
      searches  this  library  under the `-lm' option.  Declarations for these
      functions may be obtained from the include file <math.h>.

If you look into V7 commands makefiles, only few C programs are linked with -lm flag. So my conclusion is speculative:

  1. libm.a (and math.h) was primarily needed for FORTRAN programs mostly, so it was separated into library to reduce binary footprint (note that it was linked statically).
  2. Not many machines had floating point support. For example, you would need to buy an optional FPP for PDP-11 [2], there is also libfpsim simulation library in Unix to mitigate that, so floating point can be hardly used in early C programs.

1. A History of UNIX before Berkeley: UNIX Evolution: 1975-1984

2. PDP-11 architecture

Answer from myaut on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › c language › fabs-function-in-c
fabs() Function in C - GeeksforGeeks
July 23, 2025 - fabs() function of math.h header file in C programming is used to get the absolute value of a floating point number.
🌐
TutorialsPoint
tutorialspoint.com › c_standard_library › c_function_fabs.htm
C library - fabs() function
The C math library fabs() function accepts the parameter(x) of type double that returns the absolute value of x. This function is defined under the header <math.h> that calculates the absolute value of a float point number.
🌐
Programiz
programiz.com › c-programming › library-function › math.h › fabs
C fabs() - C Standard Library
To find absolute value of an integer or a float, you can explicitly convert the number to double. int x = 0; double result; result = fabs(double(x)); The fabs() function is defined in math.h header file ·
🌐
Scaler
scaler.com › home › topics › fabs() function in c
fabs() Function in C - Scaler Topics
November 7, 2023 - The fabs in C is a library function provided within the math.h header file of the C programming language.
🌐
TechOnTheNet
techonthenet.com › c_language › standard_library_functions › math_h › fabs.php
C Language: fabs function (Absolute Value of Floating-Point Number)
/* Example using fabs by TechOnTheNet.com */ #include <stdio.h> #include <math.h> int main(int argc, const char * argv[]) { /* Define temporary variables */ double value; double result; /* Assign the value we will find the fabs of */ value = -2.1; /* Calculate the absolute value of value */ result = fabs(value); /* Display the result of the calculation */ printf("The Absolute Value of %f is %f\n", value, result); return 0; } When compiled and run, this application will output:
Top answer
1 of 2
5

math.h first appears in 7th Research Unix. It is hard to tell how it got there. For example, [1] claims that bits of C library were merged from "PWB/Unix" which included troff and C compiler pcc, but I cannot prove it.

Another interesting piece of information is library manual from V7 Unix: intro.3:

(3)   These functions, together with those of section 2 and those marked (3S),
      constitute library libc, which is automatically loaded by the C compiler
      cc(1) and the Fortran compiler f77(1).  The link editor  ld(1)  searches
      this  library  under  the  `-lc' option.  Declarations for some of these
      functions may be obtained from include files indicated on the  appropri-
      ate pages.

<...>

(3M)  These  functions  constitute the math library, libm.  They are automati-
      cally loaded as needed by the Fortran compiler f77(1).  The link  editor
      searches  this  library  under the `-lm' option.  Declarations for these
      functions may be obtained from the include file <math.h>.

If you look into V7 commands makefiles, only few C programs are linked with -lm flag. So my conclusion is speculative:

  1. libm.a (and math.h) was primarily needed for FORTRAN programs mostly, so it was separated into library to reduce binary footprint (note that it was linked statically).
  2. Not many machines had floating point support. For example, you would need to buy an optional FPP for PDP-11 [2], there is also libfpsim simulation library in Unix to mitigate that, so floating point can be hardly used in early C programs.

1. A History of UNIX before Berkeley: UNIX Evolution: 1975-1984

2. PDP-11 architecture

2 of 2
-1

Most operators like + - / * are also math operators yet these are also readily available. When programming you use so much math, that developers have started to differentiate between math that is needed for everyday stuff and math that is more specialized that you only use some of the time. Abs is one of those functions that are just used to often. Like with pointer arithmetic when you just want to know the difference to calculate the size of a memory block. But you are not interested in knowing which is higher in memory and which is lower.

So to sum up: abs is used often because it calculates the difference of two integers. The difference between two pointers for instance is also an integer. And so it is in stdlib.h. fabs how ever is not something you will need much unless you are doing math specific stuff. Thus it is in math.h.

🌐
CodeVsColor
codevscolor.com › fabs function in c with example - codevscolor
fabs function in C with example - CodeVsColor
November 22, 2018 - It is used to find out the absolute value of a number. fabs takes one double number as argument and returns the absolute value of that number. In this tutorial , we will show you how to use fabs function in C with examples.
🌐
Vultr
docs.vultr.com › clang › standard-library › math-h › fabs
C math.h fabs() - Get Absolute Value | Vultr Docs
December 12, 2024 - The fabs() function from the C standard library's math.h header file is used to compute the absolute value of a floating-point number. This function is essential in various programming scenarios, particularly in fields requiring precise mathematical ...
🌐
Cprogramming.com
cprogramming.com › fod › fabs.html
fabs - C++ Function Reference - Cprogramming.com
How to begin Get the book · C tutorial C++ tutorial Game programming Graphics programming Algorithms More tutorials
Find elsewhere
🌐
Digibeatrix
cmastery.digibeatrix.com › home › standard library functions › c language fabs() function: usage, examples, and best practices
C Language fabs() Function: Usage, Examples, and Best Practices - C Programming for System Development
April 5, 2025 - The fabs function is a mathematical function in C used to calculate the absolute value of floating-point numbers. It is included in the standard library <math.h>. If a negative value is passed, the function returns its absolute (positive) value. For example, if -5.67 is passed as input, this function returns 5.67. To use the fabs function, you must include the <math.h> header file at the beginning of your code...
🌐
W3Schools
w3schools.com › c › ref_math_fabs.php
C Math fabs() Function
C Examples C Real-Life Examples C Exercises C Quiz C Code Challenges C Compiler C Syllabus C Study Plan C Interview Q&A C Certificate ... The fabs() function returns the absolute (positive) value of a number. The fabs() function is defined in ...
🌐
Scholarsoul
scholarsoul.com › fabs-in-c
fabs in c
We cannot provide a description for this page right now
🌐
Try to Program
trytoprogram.com › home › learn c programming – easy c tutorials › c programming math library functions › c math library function fabs()
C Math Library Function fabs() - Explanation And Example
September 22, 2017 - /*Use of math library function fabs*/ #include<stdio.h> #include<math.h> int main() { double x, y; x = 22.3; y = -22.3; //displaying actual value printf("Value of x = %.2lf\n" "Value of y = %.2lf\n\n", x, y); //calculating absolute value printf("Absolute value of x = %.2lf\n" "Absolute value of y = %.2lf\n", fabs(x), fabs(y)); return 0; }
🌐
Cppreference
en.cppreference.com › w › c › numeric › math › fabs
fabs, fabsf, fabsl, fabsd32, fabsd64, fabsd128 - cppreference.com
December 20, 2024 - double integrate(double f(double), double a, double b, // assume a < b unsigned steps) // assume steps > 0 { const double dx = (b - a) / steps; double sum = 0.0; for (double x = a; x < b; x += dx) sum += fabs(f(x)); return dx * sum; } int main(void) { printf("fabs(+3) = %f\n", fabs(+3.0)); printf("fabs(-3) = %f\n", fabs(-3.0)); // special values printf("fabs(-0) = %f\n", fabs(-0.0)); printf("fabs(-Inf) = %f\n", fabs(-INFINITY)); printf("Area under sin(x) in [-PI, PI] = %f\n", integrate(sin, -PI, PI, 5101)); }
🌐
Cplusplus
cplusplus.com › reference › cmath › fabs
fabs
November 12, 2024 - double fabs (double x); float fabs (float x);long double fabs (long double x); double fabs (T x); // additional overloads for integral types ... Returns the absolute value of x: |x|. Header <tgmath.h> provides a type-generic macro version of this function. Additional overloads are provided in this header (<cmath>) for the integral types: These overloads effectively cast x to a double (defined for T being any integral type).
🌐
Microsoft Learn
learn.microsoft.com › en-us › cpp › c-runtime-library › reference › fabs-fabsf-fabsl
fabs, fabsf, fabsl | Microsoft Learn
July 28, 2025 - ... Calculates the absolute value of the floating-point argument. double fabs( double x ); float fabs( float x ); // C++ only long double fabs( long double x ); // C++ only float fabsf( float x ); long double fabsl( long double x ); #define ...
🌐
Sarthaks eConnect
sarthaks.com › 3511074 › explain-fabs-math-function-in-c
Explain fabs() Math Function in C - Sarthaks eConnect | Largest Online Education Community
LIVE Course for free · In the C programming language, the fabs() function is a mathematical function used to calculate the absolute value of a floating-point number. It is defined in the <math.h> header file and can be used to find the magnitude ...
🌐
GeeksforGeeks
geeksforgeeks.org › c++ › fabs-in-c
fabs() in C++ - GeeksforGeeks
January 31, 2023 - The fabs() function returns the absolute value of the argument. Mathematically |a|. If a is value given in the argument.