This shows you the differences between two versions of the page.
— |
c:math.h:fabs [2024/02/16 01:05] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | {{keywords>wiki library source code example reference}} | ||
+ | ===== fabs ===== | ||
+ | <code c> | ||
+ | double fabs(double); | ||
+ | </code> | ||
+ | calculates the absolute number of a given value | ||
+ | ===== C Sourcecode Example ===== | ||
+ | compile in linux with: gcc fabs.c -o fabs **-lm** -Wall | ||
+ | <code c> | ||
+ | #include <stdio.h> /* including standard library */ | ||
+ | //#include <windows.h> /* uncomment this for Windows */ | ||
+ | |||
+ | #include <math.h> /* including math library */ | ||
+ | |||
+ | int main ( void ) | ||
+ | { | ||
+ | double y,x; | ||
+ | x = 4.2422; | ||
+ | y = -3284.2; | ||
+ | printf("the fabs of 4.2422 is %f\n", fabs(x) ); | ||
+ | printf("and the fabs of -3284.2 is %f\n ", fabs(y) ); | ||
+ | return 0; | ||
+ | } | ||
+ | |||
+ | </code> | ||
+ | |||
+ | ==== output ==== | ||
+ | output: | ||
+ | user@host:~$ ./fabs | ||
+ | the fabs of 4.2422 is 4.242200 | ||
+ | and the fabs of -3284.2 is 3284.200000 |