473,387 Members | 1,611 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.

math.h problems

newbie warning

OS Ubuntu, I use a couple of different IDEs and most of them give different compiling warnings for this when compiled as c, as c++ it works

undefined reference to `trunc'
warning: implicit declaration of function ‘trunc’
warning: incompatible implicit declaration of built-in function ‘trunc’

and trunc is not the only one, I have problems with round(), floor() and exp()
I searched around, but can't seem to find a solution

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. double cio(double a);
  5.  
  6. int main(void)
  7. {
  8.   ///
  9.   return 0;
  10. }
  11.  
  12. double cio(double a)
  13. {
  14.   double c1=trunc(a);
  15.   while(c1>1)
  16.     c1/=10;
  17.   return c1;
  18. }
Nov 30 '09 #1
3 6721
Banfa
9,065 Expert Mod 8TB
There is no trunc or round function in the standard library which is why you are getting the errors which are

undefined reference to `trunc'
The linker could not find a trunc function when it tried to resolve all references in the program.

warning: implicit declaration of function ‘trunc’
trunc has been called without being declared in a header file.

warning: incompatible implicit declaration of built-in function ‘trunc’
Seems to be that there is a function trunc but that the implicit declaration supplied above goesn't match the actual declaration of trunc.


I suspect you are using a third part library or platform specific library but have forgotten to include the required header.

Why it then works in C++ I could not say given the current information.
Nov 30 '09 #2
warning language (as in having problems expressing/explaining the situation correctly )

The problem with this is that it is a homework assignment, and that I have to post the answer(code) on the web. Then it gets compiled there and shows the same warnings as the ones listed above. It's not a judge, but I'm afraid they wont look at the code if it has warnings in it.

I tried it on Win, ide Dev c++ and it works without the warnings
Nov 30 '09 #3
RRick
463 Expert 256MB
Add the -lm option (i.e. -l=link, m=math library) to your compiler command. This will link in the math library during the link stage of compilation.

Don't feel bad, you are not the first person have this problem. This is one of the oddities of the unix/linux development.
Nov 30 '09 #4

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

Similar topics

6
by: Bibby | last post by:
I'm interesting in studying OOP programming languages on my own: C, C++, Java. I haven't studied the big 4 math subjects in my last year of high school, Calculus, Algebra, Geometry, Statistics....
0
by: Jussi Mononen | last post by:
Hi, I'm having problems to successfully execute the test scripts on a Compaq host ( OSF1 tr51bdev V5.1 2650 alpha ). Almost all tests end up with the following error message "PARI: *** ...
12
by: xeys_00 | last post by:
I decided I need to understand math more to help me with programming. Not to mention, eventually in my degree plan I will need to do it anyway. How much math have people in this forum taken, and...
17
by: cwdjrxyz | last post by:
Javascript has a very small math function list. However there is no reason that this list can not be extended greatly. Speed is not an issue, unless you nest complicated calculations several levels...
110
by: Gregory Pietsch | last post by:
I'm writing a portable implementation of the C standard library for http://www.clc-wiki.net and I was wondering if someone could check the functions in math.h for sanity/portability/whatever. I'm...
10
by: David Coleman | last post by:
I am running VS 2003 and have applied SP1. (On WinXP SP2, .Net 1.1) In the Command Window I get the following ? Math.Round(0.715, 2) 0.72 ? Math.Round(0.725, 2) 0.72 ? Math.Round(0.735, 2)...
4
by: =?Utf-8?B?UmVuZQ==?= | last post by:
Hello everyone I have a problem with Math.Round, it´s ocurring some strange: Math.Round(12.985) = 12.98, it´s wrong. It should be: 12.99 Why?? What is the problem? Help ME !!!!
2
by: TurtleGuy910 | last post by:
I made a math game and wanted it to print out which questions you got right at the end. How do i do that? This is my code. # Welcome To The Math Game print "Welcome To The Math Game." print...
5
by: aguirre.adolfo | last post by:
Hi, I am a very newbie who would very much appreciate some hints. Python 2.52. on Windows XP for now. Soon on Ubuntu 8 I am teaching myself Python following free tutorials. I can solve...
5
by: Tzury Bar Yochay | last post by:
What is the reason math.pow yields OverflowError while python itself can calculate these large numbers. e.g: 1e+308 Traceback (most recent call last): File "<stdin>", line 1, in <module>...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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
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...
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.