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
🌐
Code-reference
code-reference.com › c › math.h › fabs
c math.h fabs Programming | Library | Reference - Code-Reference.com
fabs double fabs(double); calculates the absolute number of a given value C Sourcecode Example compile in linux with: gcc fabs.c -o fabs -lm -Wall #include /* including standard library */ //#include /* uncomment this for Windows */ #include /* including math library */ int main ( void ) { ...
🌐
Codecademy
codecademy.com › docs › c++ › math functions › fabs()
C++ (C Plus Plus) | Math Functions | fabs() | Codecademy
April 13, 2025 - The fabs() function in C++ calculates and returns the absolute value of a floating-point number. It returns the non-negative value of the input, effectively converting any negative number to its positive equivalent.
Discussions

why is abs() and fabs() defined in two different headers in C - Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most. Learn more about Collectives ... Bring the best of human thought and AI automation together at your work. Explore Stack Internal ... The standard library function abs() is declared in stdlib.h, while fabs() is ... More on stackoverflow.com
🌐 stackoverflow.com
Simple C Question on abs() and fabs()
It is just truncating for you and returning an int. What behavior were you expecting? More on reddit.com
🌐 r/AskProgramming
8
5
October 24, 2020
Difference between abs() and fabs(), and can i replace with each other in the program?? And abs() fn is kinda not working.....
fabs is one of a family of type-specific names from C. The C++ standard libraries provide these names, fabsf for float, fabs for double and fabsl for long double, for compatibility with C, so that barring other issues C code that uses these names can be compiled as C++. However, the C++ library provides corresponding overloads of the single name abs, which one should use in C++. There is an issue with abs, namely that the overloads for integral argument types reside in (or for the name placed in the std namespace, in ). So, for using abs one should better include both and . And since in C++17 and later the header provides some functions that are not provided by , if one writes a wrapper to include standard library numerical stuff headers then it should best include also . More on reddit.com
🌐 r/cpp_questions
9
1
November 26, 2019
why is abs() in cmath also getting rid of my decimals?
You're calling the C abs, not the one from the C++ stdlib. More on reddit.com
🌐 r/cpp_questions
16
13
October 26, 2022
🌐
GitHub
gist.github.com › 3568862
fabs.c
Instantly share code, notes, and snippets.
🌐
Sketchfab
sketchfab.com
Sketchfab - The best 3D viewer on the web
With a community of over one million creators, we are the world’s largest platform to publish, share, and discover 3D content on web, mobile, AR, and VR.
🌐
Wikibooks
en.wikibooks.org › wiki › C++_Programming › Code › Standard_C_Library › Functions › fabs
C++ Programming/Code/Standard C Library/Functions/fabs - Wikibooks, open books for an open world
Code/Standard C Library | Functions · [edit | edit source] The function fabs() returns the absolute value of arg. Related topics · abs - fmod - labs · Retrieved from "https://en.wikibooks.org/w/index.php?title=C++_Programming/Code/Standard_C_Library/Functions/fabs&oldid=3676787" Category: ...
Find elsewhere
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.

🌐
Cplusplus
cplusplus.com › reference › cmath › fabs
fabs
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).
🌐
Programiz
programiz.com › c-programming › library-function › math.h › fabs
C fabs() - C Standard Library
Become a certified C programmer. Try Programiz PRO! ... The fabs() function takes a single argument (in double) and returns the absolute value of that number (also in double).
🌐
Blurt
blurt.blog › c-programming › @theindiantrader › c-program-let-us-learn-about-fabs-function
C Program : let us learn about fabs function — Blurt
April 24, 2023 - Welcome back, In today's blog we will learn about fabs function that is a predefined function in C programming. It is used to perform one of the mathematical operations and we will just explore… by theindiantrader
🌐
SAS
support.sas.com › documentation › onlinedoc › sasc › doc700 › html › lr1 › z2054998.htm
Function Descriptions : fabs
fabs is implemented as a built-in function unless it is undefined by an #undef statement. #include <math.h> #include <stdio.h> main() { double a, b, c; puts("Enter values for a & b"); scanf("%lf %lf", &a, &b); c = fabs(a-b); printf("The absolute value of their difference = %f", c ); } abs , labs ·
🌐
Qnx
qnx.com › developers › docs › 8.0 › com.qnx.doc.neutrino.lib_ref › topic › f › fabs.html
fabs(), fabsf(), fabsl()
Compile your program with the -fno-builtin option to prevent the compiler from using a built-in version of the function. The fabs(), fabsf(), and fabsl() functions compute the absolute value of x.
🌐
W3Resource
w3resource.com › c-programming › math › c-fabs.php
C fabs() function
December 24, 2022 - C fabs() function (math.h): The fabs() function is used to calculate the absolute value of the floating-point argument x.
🌐
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.
🌐
Cppreference
en.cppreference.com › w › c › numeric › math › fabs.html
fabs, fabsf, fabsl, fabsd32, fabsd64, fabsd128 - cppreference.com
December 20, 2024 - #include <math.h> #include <stdio.h> #define PI 3.14159 // This numerical integration assumes all area is positive. 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)); }
🌐
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
🌐
Educative
educative.io › answers › what-is-the-fabs-function-in-cpp
What is the fabs() function in C++?
The fabs() function in C++ is used to return the absolute value of an argument passed to the function.
🌐
O'Reilly
oreilly.com › library › view › c-in-a › 0596006977 › re57.html
fabs - C in a Nutshell [Book]
December 16, 2005 - The fabs() function returns the absolute value of its floating-point argument x; if x is greater than or equal to 0, the return value is equal to x.
Authors   Peter PrinzTony Crawford
Published   2005
Pages   618
🌐
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.
🌐
Blogger
see-programming.blogspot.com › 2012 › 04 › fabs.html
Computer Programming And Technology For Dummies: fabs example in C
April 30, 2012 - see-programming is a popular blog that provides information on C programming basics, data structure, advanced unix programming, network programming, basic linux commands, interview question for freshers, video tutorials and essential softwares for students. ... Returns the absolute value of x. ... ...