Sponsored Content
Full Discussion: Math function with C
Top Forums Programming Math function with C Post 302722259 by Fingerz on Friday 26th of October 2012 03:01:22 PM
Old 10-26-2012
Compiler is gcc 4.5.2 on Solaris11 Box

It prints fine however given the 2 different formulas it prints 2 different results.

kilometers = 1.609 * (miles + yards / 1760.0);
end result = A marathon is 42.185970 kilometers.


kilometers1 = 1.609 * (miles + yards / 1760);
end result = A marathon is 41.834000 kilometers.

From what I gather when yards is divided by a float it results in a float.
When yards is divided by an int it results in a int
As a float 385/1760 = .218
As an int .218 = 0
 

9 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

something about <math.h>

Hi, I got an easy problem for you but really difficult for me 'cause I am pretty new to this field I got header file <math.h> included in my .c file , then I write the code as below: k = sqrt(i); /* both variables k and i are int */ then I cc temp.c it says like this undefined... (4 Replies)
Discussion started by: blf0
4 Replies

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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
exp(3m) 																   exp(3m)

Name
       exp, expm1, log, log10, log1p, pow - exponential, logarithm, power

Syntax
       #include <math.h>

       double exp(x)
       double x;

       float fexp(x)
       float x;

       double expm1(x)
       double x;

       float fexpm1(x)
       float x;

       double log(x)
       double x;

       float flog(x)
       float x;

       double log10(x)
       double x;

       float flog10(x)
       float x;

       double log1p(x)
       double x;

       float flog1p(x)
       float x;

       double pow(x,y)
       double x,y;

Description
       The and functions return the exponential function of x for double and float data types, respectively.

       The and functions return exp(x-1 accurately, including tiny x for double and float data types, respectively.

       The and functions return the natural logarithm of x for double and float data types, respectively.

       The and functions return the logarithm of x to base 10 for double and float data types, respectively.

       The and functions return log(1+x) accurately, including tiny x for double and float data types, respectively.

       The function returns x**y.

   Error (due to roundoff)
       The and functions are accurate to within an ulp, and is accurate to within approximately 2 ulps; an ulp is one Unit in the Last Place.

       The  function  is accurate to within 2 ulps when its magnitude is moderate, but becomes less accurate as the result approaches the overflow
       or underflow thresholds.  Theoretically, as these thresholds are approached, almost as many bits could be lost from the result as are indi-
       cated  in  the exponent field of the floating-point format for the resultant number.  In other words, up to 11 bits for an IEEE 754 double-
       precision floating-point number.  However, testing has never verified loss of precision as drastic as 11 bits.  The worst cases have  shown
       accuracy  of  results  to within 300 ulps for IEEE 754 double-precision floating-point numbers.	In general, a (integer, integer) result is
       exact until it is larger than 2**53 (for IEEE 754 double-precision floating-point).

Return Values
       All of the double precision functions return NaN if x or y is NaN.

       The function returns HUGE_VAL when the correct value would overflow, and zero when the correct value would underflow.

       The and functions return NaN when x is less than or equal to zero or when the correct value would overflow.

       The function returns NaN if x or y is NaN.  When both x and y are zero, 1.0 is returned.  When x is negative and y is not an  integer,  NaN
       is returned.  If x is zero and y is negative, -HUGE_VAL is returned.

       The function returns NaN when x is negative.

See Also
       math(3m)

								       RISC								   exp(3m)
All times are GMT -4. The time now is 11:48 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy