473,387 Members | 3,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

calculation problem with math.h predefined methods

121 100+
Okay, I was asked by a friend about the result of this limit:



Not n->zero but n-> + infinite

I really know nothing about advanced math, so I wrote a C program to help me:

(BTW, I guess the result would be ln2.)

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. # include <math.h>
  3.  
  4. int main()
  5. {
  6.   double result;
  7.   double n;
  8.  
  9.   printf("input n, followed by the enter key.\n");
  10.   scanf("%lf", &n);
  11.  
  12.   result = log(2+sqrt(atan(n)*sin(1/n)));
  13.  
  14.   printf("The result for number %f is: %f", n, result);
  15.  
  16.   result = log(2.00);
  17.   printf("The result for ln2 is: %f", result);
  18.  
  19.   return 0;
  20. }
I used the gcc to compile my code, it rejected, saying there were some problems:

bash-3.2$ gcc calculation.c
/tmp/ccyzzqks.o: In function `main':
calculation.c:(.text+0x37): undefined reference to `atan'
calculation.c:(.text+0x49): undefined reference to `sin'
calculation.c:(.text+0x70): undefined reference to `sqrt'
calculation.c:(.text+0x86): undefined reference to `log'
calculation.c:(.text+0xb1): undefined reference to `log'
collect2: ld returned 1 exit status

I googled for the error message and some expert said to use the -lm parameter to compile.

Yeah, this time it worked and I got the results.

But why?




PS. I tried to issue this commands:
bash-3.2$ gcc -lm calculation.c
bash-3.2$ ./a.out

input n, followed by the enter key.
0.0000
The result for number 0.000000 is: nanThe result for ln2 is: 0.693147

input n, followed by the enter key.
0.000001
The result for number 0.000001 is: nanThe result for ln2 is: 0.693147

input n, followed by the enter key.
9999999999999999
The result for number 10000000000000000.000000 is: 0.693147The result for ln2 is: 0.693147

nan = Not a Number ?!

Again, why? (If that is a math question, ignore it plz...)
Sep 22 '07 #1
3 3528
weaknessforcats
9,208 Expert Mod 8TB
Yoiur code compiles and links without error using Visual Studio.NET 2005.
Sep 22 '07 #2
JosAH
11,448 Expert 8TB
Again, why? (If that is a math question, ignore it plz...)
The lim(x->oo, atan(x)) == pi/2, lim(x->oo, sin(1/x)) == 0; so that entire root
has a limit of 0 (zero). Did you want to ask this? Or is it about C/C++ techincalities?

kind regards,

Jos
Sep 22 '07 #3
mattmao
121 100+
The lim(x->oo, atan(x)) == pi/2, lim(x->oo, sin(1/x)) == 0; so that entire root
has a limit of 0 (zero). Did you want to ask this? Or is it about C/C++ techincalities?

kind regards,

Jos
Hello Jos.

It's not about math, my question is for the -lm parameter in gcc. Why would my code be compiled successfully if I use it? I am trying to make my code independent from any compiler restrictions, such as some specific parameters like the "-lm".

I reckon the problems would be with the sin(x) atan(x) methods in math.h.
What would be the "proper" ways for calling them when you want to use them?

Thanks for your help in math :)
Sep 22 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Matthew | last post by:
Hello, For a few days now, I have tried a number of methods that are supposed to provide the a(k) and b(k) coefficients for a Fourier series. These methods are listed at the end of this post (in...
5
by: Michael Hagstrom | last post by:
Good Day - I have written a form which collects input for a fare calculation. The form collects the following: 1) Departure or Destination Group (1,2,or 3) 2) Number of Adults 3) Number of...
22
by: KsAdmin | last post by:
I have a question which has had me stumped for a few days now. I have a form that I add the values of fields together and display the total in a total field. I have the calculations working...
2
by: Nicolas | last post by:
Why does for the same code I got different result the VB code gave me what I want why not the csharp? Thank you for your help... CSHARP CODE int sx, sy; double sdegrees; sdegrees = (90 -...
9
by: Klaus Bonadt | last post by:
I have found strange behaviour in casting floating point values in C++ 6.0 to int: If I enter in the watch window while debugging in version 6.0 the following term: (1.4 - 1.0) * 10.0 the...
5
by: Tamir Khason | last post by:
Someone knows "Arrange All" windows calculation formula used in MDI?
28
by: beach.dk | last post by:
Hi, I'm trying to implement a simple hash algorith called rs_hash in javascript, but I cannot get a correct result. In c the code looks like this:
5
by: The alMIGHTY N | last post by:
Hi all, Let's say I have a simple math formula: sum (x * y / 1000) / (sum z / 1000) I have to do this across 50 items, each with an x, y and z value, when the page first loads AND when a...
5
matheussousuke
by: matheussousuke | last post by:
Hello, I'm using tiny MCE plugin on my oscommerce and it is inserting my website URL when I use insert image function in the emails. The goal is: Make it send the email with the URL...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.