473,624 Members | 2,475 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

calculation problem with math.h predefined methods

121 New Member
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.
999999999999999 9
The result for number 100000000000000 00.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 3546
weaknessforcats
9,208 Recognized Expert Moderator Expert
Yoiur code compiles and links without error using Visual Studio.NET 2005.
Sep 22 '07 #2
JosAH
11,448 Recognized Expert MVP
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 New Member
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
2837
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 Java). However, not one of these methods seems to provide the correct coefficients for the following function; f(x) = 2 - 2 * cos(x)
5
3317
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 Children aged 4 to 12 4) Number of Children under age 4
22
1780
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 correctly. My problem is that I would like to change the format of the total from 1234567 to 1,234,567 . Is this possible using javascript? Here is the code that I use to do the calculations. I have edited out all the code that I use to validate the...
2
3949
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 - (5/15) * 90) * (System.Math.PI / 180);
9
2227
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 result will be 4.0 - as expected. But if I cast the same to int: (int)((1.4 - 1.0) * 10.0)
5
1578
by: Tamir Khason | last post by:
Someone knows "Arrange All" windows calculation formula used in MDI?
28
2640
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
6236
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 user modifies any of the x, y and z values.
5
13347
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 http://mghospedagem.com/images/controlpanel.jpg instead of http://mghospedagem.comhttp://mghospedagem.com/images/controlpanel.jpg As u see, there's the website URL before the image URL.
0
8179
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8685
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8631
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8490
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6112
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4184
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2612
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1796
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1489
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.