473,398 Members | 2,343 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,398 software developers and data experts.

ceil() and log10() - undefined?

ptn
Hi everyone,

I was messing around with math.h and I got this error:

"""
/tmp/ccefZYYN.o: In function `digcount':
itos.c:(.text+0x103): undefined reference to `log10'
itos.c:(.text+0x111): undefined reference to `ceil'
collect2: ld returned 1 exit status

shell returned 1
"""

It can't be that log10() and ceil() aren't defined, because math.h
takes care of that. I admit that I have no idea what .text+0x111/.text
+0x103 means

The complete code is here:

# include <stdio.h>
# include <malloc.h>
# include <math.h>

int digcount(int num); // counts the digits of <num>

main()
// transform a number to a string
{
int num, fact, dig, digits, i;
char *s;

scanf("%d", &num);
digits = digcount(num);
s = (char *) malloc((digits + 1) * sizeof(char)); // assign just
enough space
s += (digits - 1); // go to the last address of the memory space
assigned
*s-- = '\0'; // mark the end of the string
for (i = 0; i < digits; i++) {
dig = num % 10;
num /= 10;
*s-- = '0' + dig; // store digit by digit
}
printf("\"%s\"\n", ++s); // after the for, s is pointing to the
addres before the start of the string
}

int digcount(int num)
/* N = trunc(log(x), 0) + 1, where N is the number of digits of x */
{
double ans;

ans = log10(num);
ans = ceil(ans);
return (int) ans;
}

Any ideas are welcome.
(I'm using Vim + gcc under Ubuntu Feisty Fawn)

Thanks,

Pablo Torres Navarrete

Oct 3 '07 #1
1 4890
On Oct 3, 8:55 am, ptn <tn.pa...@gmail.comwrote:
Hi everyone,

I was messing around with math.h and I got this error:

"""
/tmp/ccefZYYN.o: In function `digcount':
itos.c:(.text+0x103): undefined reference to `log10'
itos.c:(.text+0x111): undefined reference to `ceil'
collect2: ld returned 1 exit status

shell returned 1
"""

It can't be that log10() and ceil() aren't defined, because math.h
takes care of that. I admit that I have no idea what .text+0x111/.text
+0x103 means

The complete code is here:

# include <stdio.h>
# include <malloc.h>
# include <math.h>

int digcount(int num); // counts the digits of <num>

main()
// transform a number to a string
{
int num, fact, dig, digits, i;
char *s;

scanf("%d", &num);
digits = digcount(num);
s = (char *) malloc((digits + 1) * sizeof(char)); // assign just
enough space
s += (digits - 1); // go to the last address of the memory space
assigned
*s-- = '\0'; // mark the end of the string
for (i = 0; i < digits; i++) {
dig = num % 10;
num /= 10;
*s-- = '0' + dig; // store digit by digit
}
printf("\"%s\"\n", ++s); // after the for, s is pointing to the
addres before the start of the string

}

int digcount(int num)
/* N = trunc(log(x), 0) + 1, where N is the number of digits of x */
{
double ans;
Too difficult question for me
ans = log10(num);
ans = ceil(ans);
return (int) ans;

}

Any ideas are welcome.
(I'm using Vim + gcc under Ubuntu Feisty Fawn)

Thanks,

Pablo Torres Navarrete

Oct 3 '07 #2

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

Similar topics

4
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 =...
6
by: RobG | last post by:
I am writing a script to move an absolutely positioned element on a page by a factor using style.top & style.left. The amount to move by is always some fraction, so I was tossing up between...
0
by: BuddyWork | last post by:
Hello, Here is an update. There is no differences with the function System.Math.Log10 under any operating system. The problem is with the casting of the datatype double and value Infinite...
3
by: BernsteinVsTheDb | last post by:
Hello all, I have a table that contains 100+ rows. I'm trying to run a query that looks like this: SELECT ..., log10(...) as Rank FROM Table and the resultset contains only the first row of...
20
by: mikael.liljeroth | last post by:
Why do I get NO as result from this ?? double du = (double)3.1415; du = ceil(du); if(du == (double)4) printf("YES\n"); else printf("NO\n");
2
by: RB Smissaert | last post by:
Just starting with C++ in MS VC6++. Why does this: return (log10(70)); produce 1 and not 1.845098 ? I can see it is giving me the rounded integer number, but why? The return type of the...
14
by: yansong1990 | last post by:
Uhm..it's my 1st time using this fuction...could someone provide anexample for me please? thanks
13
by: ptn | last post by:
Hi everyone, I was messing around with math.h and I got this error: """ /tmp/ccefZYYN.o: In function `digcount': itos.c:(.text+0x103): undefined reference to `log10' itos.c:(.text+0x111):...
7
by: MrIncognito | last post by:
Am I using this correctly? This line of code is supposed to find the number of bytes in one line of a 16 color bitmap, but it doesn't seem to work most of the time. long linesize = ceil((double)...
7
by: mingke | last post by:
I've learned that we can round up and down a float number by using Ceil and floor function. But, is this function still able to work if I the number I want to round up (or down) is zero? I have...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
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,...
0
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...
0
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...
0
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,...
0
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...

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.