473,804 Members | 3,038 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

problem with round

m
all,
i am trying to use the function round() which I found through google
to be declared in math.h (
http://www.gnu.org/software/libc/man...unctions.html).
this function does not work and i get an unreferenced symbol error. the
function rint() works when math.h is included.
is round() not found in all math.h files? if so what might be an
alternative. i work on a machine that runs a sparc-sun-solaris operating
system with gcc version 2.95.2.
thanks
Nov 14 '05 #1
14 4631
m <ma**@mschumach er.com> writes:
i am trying to use the function round() which I found through
google to be declared in math.h (
http://www.gnu.org/software/libc/man...unctions.html). this
function does not work and i get an unreferenced symbol error. the
function rint() works when math.h is included.


This is in the C FAQ.

14.3: I'm trying to do some simple trig, and I am #including <math.h>,
but I keep getting "undefined: sin" compilation errors.

A: Make sure you're actually linking with the math library. For
instance, under Unix, you usually need to use the -lm option, at
the *end* of the command line, when compiling/linking. See also
questions 13.25, 13.26, and 14.2.
--
int main(void){char p[]="ABCDEFGHIJKLM NOPQRSTUVWXYZab cdefghijklmnopq rstuvwxyz.\
\n",*q="kl BIcNBFr.NKEzjwC IxNJC";int i=sizeof p/2;char *strchr();int putchar(\
);while(*q){i+= strchr(p,*q++)-p;if(i>=(int)si zeof p)i-=sizeof p-1;putchar(p[i]\
);}return 0;}
Nov 14 '05 #2
m
Ben Pfaff wrote:
m <ma**@mschumach er.com> writes:

i am trying to use the function round() which I found through
google to be declared in math.h (
http://www.gnu.org/software/libc/man...unctions.html). this
function does not work and i get an unreferenced symbol error. the
function rint() works when math.h is included.

This is in the C FAQ.

14.3: I'm trying to do some simple trig, and I am #including <math.h>,
but I keep getting "undefined: sin" compilation errors.

A: Make sure you're actually linking with the math library. For
instance, under Unix, you usually need to use the -lm option, at
the *end* of the command line, when compiling/linking. See also
questions 13.25, 13.26, and 14.2.

sorry for not having read the FAQ first. thanks for the reply. i worked
around that using
#define round(x) ((x)>=0)?(int)( (x)+0.5):(int)( (x)-0.5)
am new to C but seems mighty strange.this kind of linking just beats
using something like a header file. i am sure i am missing something.

thanks
Nov 14 '05 #3
m <ma**@mschumach er.com> writes:
sorry for not having read the FAQ first. thanks for the reply. i
worked around that using
#define round(x) ((x)>=0)?(int)( (x)+0.5):(int)( (x)-0.5)


For what it's worth, that should work okay, but only if `x'
rounds to a value in the range of `int'.
--
int main(void){char p[]="ABCDEFGHIJKLM NOPQRSTUVWXYZab cdefghijklmnopq rstuvwxyz.\
\n",*q="kl BIcNBFr.NKEzjwC IxNJC";int i=sizeof p/2;char *strchr();int putchar(\
);while(*q){i+= strchr(p,*q++)-p;if(i>=(int)si zeof p)i-=sizeof p-1;putchar(p[i]\
);}return 0;}
Nov 14 '05 #4
m
Ben Pfaff wrote:
m <ma**@mschumach er.com> writes:

sorry for not having read the FAQ first. thanks for the reply. i
worked around that using
#define round(x) ((x)>=0)?(int)( (x)+0.5):(int)( (x)-0.5)

For what it's worth, that should work okay, but only if `x'
rounds to a value in the range of `int'.

yes its a pgm image that "should" contain values in 0 to 255.

Nov 14 '05 #5
Ben Pfaff wrote:
m <ma**@mschumach er.com> writes:

i am trying to use the function round() which I found through
google to be declared in math.h (
http://www.gnu.org/software/libc/man...unctions.html). this
function does not work and i get an unreferenced symbol error. the
function rint() works when math.h is included.

This is in the C FAQ.

14.3: I'm trying to do some simple trig, and I am #including <math.h>,
but I keep getting "undefined: sin" compilation errors.

A: Make sure you're actually linking with the math library. For
instance, under Unix, you usually need to use the -lm option, at
the *end* of the command line, when compiling/linking. See also
questions 13.25, 13.26, and 14.2.


Open letter to the gcc developers:

Dear Sirs:

Subject:

Gcc should link with the math library by default.

Rationale:
In comp.lang.c we receive since many many years the
same question posed always by beginners:

Why is my "sin" not linking? (Or "cos" whatever)

Most compilers now include a default library set
that includes the C run time, to which the math
library belongs.

The math library can be left out if you disable
this, what the 0.000000001% of users writing new
replacement math libraries for gcc will appreciate.

Implementation:
When parsing command line arguments, gcc searches for
--no_math_library . If found, the math library will
be deleted from the default library list. An argument
of --no_default_libs (or similar) could be used
for self-contained programs that do not use
any external library.

The default library list has two members at least:

The C run time library
The math library.

Other libraries could be specified somehow by
the user to avoid remembering to include them,
but at least those two should belong to the
default setting.

Rationale:

Beginners do not grasp the need to add a library,
and many do not know at all what a library is.

It is better to leave learning this fact after you
have done your first program.

Dennis Ritchie proposed a # preprocessor directive
in his Plan9 system to force the inclusion of the
library when you include the header file.

Lcc-win32 implements this with
#pragma lib "Absolute path"
#pragma lib <standard lib path>

This improves the language since it is no longer
necessary to figure out which library is used
with which header file. They are documented in
the header file with those constructs.

But I disgress

This is easy to do. Just a small change in the
gcc parsing routine, and a flag that saves the
info when generating the linker command line,
that is decorated automatically with

"-lm"

BY DEFAULT :-)

This will save thousands of questions from
the beginners. Yes, you are advanced and
you wrote a compiler, but some day you were a
plain beginner and didn't even know that
you had to write that, isn't it?

Just add it up and make your system more
beginner friendly.

jacob
Nov 14 '05 #6
On Thu, 20 Jan 2005 12:55:52 -0600, m wrote:
Ben Pfaff wrote:
m <ma**@mschumach er.com> writes:

sorry for not having read the FAQ first. thanks for the reply. i
worked around that using
#define round(x) ((x)>=0)?(int)( (x)+0.5):(int)( (x)-0.5)

For what it's worth, that should work okay, but only if `x'
rounds to a value in the range of `int'.

yes its a pgm image that "should" contain values in 0 to 255.


Why is it testing for and rounding negative values?

Lawrence
Nov 14 '05 #7
m
m wrote:
Ben Pfaff wrote:
m <ma**@mschumach er.com> writes:

i am trying to use the function round() which I found through
google to be declared in math.h (
http://www.gnu.org/software/libc/man...unctions.html).
this
function does not work and i get an unreferenced symbol error. the
function rint() works when math.h is included.


This is in the C FAQ.

14.3: I'm trying to do some simple trig, and I am #including <math.h>,
but I keep getting "undefined: sin" compilation errors.

A: Make sure you're actually linking with the math library. For
instance, under Unix, you usually need to use the -lm option, at
the *end* of the command line, when compiling/linking. See also
questions 13.25, 13.26, and 14.2.

i did gcc test.c -lm (wrote a program gcc which included math.h with
log2 and round in it) it jst gave me the same errors. unreferenced symbol.


shudd read -wrote a program and then did gcc.
Nov 14 '05 #8
m
Lawrence Kirby wrote:
On Thu, 20 Jan 2005 12:55:52 -0600, m wrote:

Ben Pfaff wrote:
m <ma**@mschumach er.com> writes:

sorry for not having read the FAQ first. thanks for the reply. i
worked around that using
#define round(x) ((x)>=0)?(int)( (x)+0.5):(int)( (x)-0.5)
For what it's worth, that should work okay, but only if `x'
rounds to a value in the range of `int'.


yes its a pgm image that "should" contain values in 0 to 255.

Why is it testing for and rounding negative values?

Lawrence


its testing and rouding all values and it does it because the
calculations are in double. round and then clip between 0 and 255 if needed
Nov 14 '05 #9
m
Ben Pfaff wrote:
m <ma**@mschumach er.com> writes:

i am trying to use the function round() which I found through
google to be declared in math.h (
http://www.gnu.org/software/libc/man...unctions.html). this
function does not work and i get an unreferenced symbol error. the
function rint() works when math.h is included.

This is in the C FAQ.

14.3: I'm trying to do some simple trig, and I am #including <math.h>,
but I keep getting "undefined: sin" compilation errors.

A: Make sure you're actually linking with the math library. For
instance, under Unix, you usually need to use the -lm option, at
the *end* of the command line, when compiling/linking. See also
questions 13.25, 13.26, and 14.2.


i did gcc test.c -lm (wrote a program gcc which included math.h with
log2 and round in it) it jst gave me the same errors. unreferenced symbol.
Nov 14 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
4412
by: Jack | last post by:
I have a problem that I can't seem to solve. I have checked the round, ceil and floor functions and they don't seem to do what I want. I have an entry like this <?php $tax = .065; $ad2day = 104.50; $ad2day = round(($ad2day * $tax)+ $ad2day, 2);
3
2045
by: Robert Dell | last post by:
I have a problem comparing strings in an order form i'm writing. I want to give a running total at the bottom of the page and it appears to be working except it doesn't compare correctly (it always adds things up when you didn't select them) so i only added 2 of the items until I got it worked out. here's the page source (you can look at it yourself at http://robertdell.dyndns.org/shifts/ <!DOCTYPE HTML PUBLIC> <html> <head>
9
7387
by: Ronald W. Roberts | last post by:
I'm having a problem understanding the Round function. Below are quotes from two books on VB.NET. The first book shows examples with one argument and how it rounds. The second book something different. Programming Microsoft Windows with Microsoft Visual Basic.NET "The Round method with a single argument return the whole number nearest to the argument. If the argument to Round is midway between two whole numbers,
3
2305
by: Mark Szlazak | last post by:
The following page simulates a pool cue and cue ball: http://members.aol.com/myscript/cue.html Mouse cursor position around the cue ball determines where a roll-over of 179 pool cue images is placed around the ball and which one of those images is displayed. Each pool cue image is in a slightly different orientation and the correct one is chosen to match the orientation of the cursor around the ball. Holding down the left mouse button...
5
2260
by: Jason | last post by:
I am having a rounding problem in a value i am trying to display in VB.NET. If I have the following code: Dim x As Single = 2726.795 Dim y As Single = Math.Round(2726.795, 2) Dim s as String = String.Format("{0:0.00}", y) The value of s is 2726.79 If I have the following code: Dim y As Single = Math.Round(2726.795, 2)
10
16038
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) 0.74
1
1145
by: wojwoj17 | last post by:
hello everyone... can you help me to program this problem? i'm from philippines. Problem: TWENTY LOVELY LADIES ARE COMPETING IN A BEAUTY CONTEST. THEY ARE RATED FROM 1 TO 10. A SCORE EQUAL OR GREATER THAN 8 QUALIFIES A CANDIDATE FOR THE SEMI-FINAL ROUND. PREPARE A PROGRAM THAT WILL PRODUCE THE FOLLOWING REQUIREMENTS: a. Find out WHO and HOW many have qualified for the semi-final round. b. Find out WHO and HOW many are not qualified for...
16
1949
by: =?Utf-8?B?R1ROMTcwNzc3?= | last post by:
Hi All, I have a neat little script that calculates price based on quantity without refreshing the page.. the script is - <script type="text/javascript"> function OpenWin(url) { window.open(url,'win','scrollbars=1,status=0,resizable=0,width=200,height=265'); }
1
1350
by: Adrienne Boswell | last post by:
Gazing into my crystal ball I observed =?Utf-8?B?R1ROMTcwNzc3?= <GTN170777@discussions.microsoft.comwriting in news:443E2509-7F0E-4CEC-B243-D6EDC931DB7F@microsoft.com: ASP has no knowledge of the client, this is a client side issue. Followups set to comp.lang.javascript. 0,widt
0
10571
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...
1
10317
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10075
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...
0
9143
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6851
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5520
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4295
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
2
3815
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2990
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.