Sponsored Content
Full Discussion: something about <math.h>
Top Forums Programming something about <math.h> Post 101576 by botao on Thursday 9th of March 2006 09:37:02 PM
Old 03-09-2006
Tools fix the type and the compilation environment

### first : the sqrt function requires a "double" parameter , and returns a double .

just like this :

/* ---- snip ---- */

double x = 2.0 ;
double y ;

y = sqrt (x) ;

/* ---- snip ---- */

### second : make sure the math library will be found :

$ find / -name libm.a

(it normally will be found in /lib or /usr/lib )

$ echo $LIBPATH or $LD_LIBRARY_PATH (depending on your o.s.) and
make sure the parent dir that contains libm.a is included in it .

### and finally , compile you program as follows :

$ cc -o yourprog yourprog.c -lm

(put the '-lm' at the end of the line)

good luck , and success !
 

10 More Discussions You Might Find Interesting

1. Programming

math.h not working? o.0

Alright, umm i cant get this to work. im looking at some example and a book i have. when i try to compile my program i get an error message. ld: 0711-317 ERROR: Undefined symbol: .sqrt ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more information. I did #include<math.h> after my... (2 Replies)
Discussion started by: primal
2 Replies

2. Programming

some math problems in C

I want to calculate secant method using C language That is a program----> #include<stdio.h> #include<math.h> #include<stdlib.h> main() { double fx(double x); double x0,x1,x2,f0,f1,f2,err; int n,i; printf("\n\n f(x) =x*x*x-5*x-7"); printf("\n\nEnter an interval in" ... (4 Replies)
Discussion started by: cdfd123
4 Replies

3. Programming

math.h in makefile

Hey all, How do I link the math library in a gnu make makefile? I have tried using -lm with the CFLAGS varibale - flags like -Wall and -ggdb work, but -lm does not. I am running gcc - 4.1.2 on a linux machine. (2 Replies)
Discussion started by: kermit
2 Replies

4. UNIX for Dummies Questions & Answers

math in unix

I have 2 variables a=2 b=1 i want to add a and b how do i do this in unix using just the echo command and by assigning it to a different variable like c? (13 Replies)
Discussion started by: khestoi
13 Replies

5. Shell Programming and Scripting

math help

$ x=1 $ y=1.5 $ z=$((x*y)) bash: 1.5: syntax error: invalid arithmetic operator (error token is ".5") What's wrong? (2 Replies)
Discussion started by: rockbike
2 Replies

6. Shell Programming and Scripting

Need help with AWK math

I am trying to do some math, so that I can compare the average of six numbers to a variable. Here is what it looks like (note that when I divide really big numbers, it isn't a real number): $ tail -n 6 named.stats | awk -F\, '{print$1}' 1141804 1140566 1139429 1134210 1084682 895045... (3 Replies)
Discussion started by: brianjb
3 Replies

7. Shell Programming and Scripting

Math Tool

Hi all, I am new to PERL scripts, and i have made my first script which i am posting here. This math tool performs all basic arithmatic functions. #!/usr/bin/perl print "\t----------Welcome to Maths Tool-----------\n"; do { print "Enter your choice :"; print... (2 Replies)
Discussion started by: PranavEcstasy
2 Replies

8. Programming

Math function with C

I have int miles, yards; float kilometers; float kilometers2; miles = 26; yards = 385; kilometers = 1.609 * (miles + yards / 1760.0); where int/float remains a float. How ever if I change it to kilometers = 1.609 * (miles + yards / 1760); ... (7 Replies)
Discussion started by: Fingerz
7 Replies

9. UNIX for Dummies Questions & Answers

Linux Math Help

I am struggling with scripting this challenge a friend and I have. You have file1 and its contents is a single number you have file 2 and its contents are a different number you want to add file1 to file2 and have the output be put into file3 (3 Replies)
Discussion started by: minkyboodle
3 Replies

10. UNIX for Dummies Questions & Answers

Math

i have file (my_file.txt) that looks like this: 000000000000010000 000000000000010000 000000000000005000 000000000000005000 000000000000005000 000000000000005000 000000000000005000 000000000000005000 000000000000005000 000000000000005000 all said and one, it should look... (11 Replies)
Discussion started by: lawsongeek
11 Replies
HYPOT(3)						   BSD Library Functions Manual 						  HYPOT(3)

NAME
hypot, hypotf, hypotl, cabs, cabsf, cabsl -- Euclidean distance and complex absolute value functions LIBRARY
Math Library (libm, -lm) SYNOPSIS
#include <math.h> double hypot(double x, double y); float hypotf(float x, float y); long double hypotl(long double x, long double y); #include <complex.h> double cabs(double complex z); float cabsf(float complex z); long double cabsl(long double complex z); DESCRIPTION
The hypot(), hypotf() and hypotl() functions compute the sqrt(x*x+y*y) in such a way that underflow will not happen, and overflow occurs only if the final result deserves it. The cabs(), cabsf() and cabsl() functions compute the complex absolute value of z. hypot(infinity, v) = hypot(v, infinity) = +infinity for all v, including NaN. ERROR (due to Roundoff, etc.) Below 0.97 ulps. Consequently hypot(5.0, 12.0) = 13.0 exactly; in general, hypot and cabs return an integer whenever an integer might be expected. NOTES
As might be expected, hypot(v, NaN) and hypot(NaN, v) are NaN for all finite v. But programmers might be surprised at first to discover that hypot(+-infinity, NaN) = +infinity. This is intentional; it happens because hypot(infinity, v) = +infinity for all v, finite or infinite. Hence hypot(infinity, v) is independent of v. Unlike the reserved operand fault on a VAX, the IEEE NaN is designed to disappear when it turns out to be irrelevant, as it does in hypot(infinity, NaN). SEE ALSO
carg(3), math(3), sqrt(3) STANDARDS
The hypot(), hypotf(), hypotl(), cabs(), cabsf(), and cabsl() functions conform to ISO/IEC 9899:1999 (``ISO C99''). HISTORY
Both a hypot() function and a cabs() function appeared in Version 7 AT&T UNIX. BSD
March 30, 2008 BSD
All times are GMT -4. The time now is 07:50 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy