what is wrong with the log function in c?


 
Thread Tools Search this Thread
Top Forums Programming what is wrong with the log function in c?
# 1  
Old 05-02-2008
what is wrong with the log function in c?

Hi I looked up the reference but couldn't figure out whats wrong with my log funtions in ANSI C, need this log functions for a memory compiler, please help!!

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


int main(void)
{

double d ;

double logB(double x, double base);

printf(" natural log :\n");
for ( d = 1; d <= 10; d++)
printf(" ln(%f) = %f\n", d, log(d));

printf("\n\n\n 2base log :\n");
for ( d = 1.0; d <= 10.0; d++)
printf(" log2(%f) = %f\n", d, logB(d, 2));

return 0;
}

double logB(double x, double base) {
return( log(x) / log(base));
}
# 2  
Old 05-02-2008
Have you compiled the program with the -lm option?

Code:
cc program.c -o program -lm

Regards
# 3  
Old 05-02-2008
that works, thank you very much!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Wrong test interpretation for simple function.

Hello everyone, I have written simple script below to check if ip is added to interface #!/usr/local/bin/bash IFCONFIG="/sbin/ifconfig" SERVICE="/usr/sbin/service" IP="79.137.X.X" GREP=$(${IFCONFIG} | grep ${IP}) ip_quantity_check () { echo ${GREP} | wc -l } if ];... (2 Replies)
Discussion started by: bryn1u
2 Replies

2. Shell Programming and Scripting

Python - Function print vs return - whats wrong

All, I have a basic buzz program written in python with return function. If i change return with print,it works fine but i want to know whats wrong with return statement.Can anyone help me whats wrong with this #!/usr/bin/python def div4and6(s,e): for i in range(s,e+1): if... (5 Replies)
Discussion started by: oky
5 Replies

3. Shell Programming and Scripting

Why result is wrong here ? whether break statement is wrong ?

Hi ! all I am just trying to check range in my datafile pls tell me why its resulting wrong admin@IEEE:~/Desktop$ cat test.txt 0 28.4 5 28.4 10 28.4 15 28.5 20 28.5 25 28.6 30 28.6 35 28.7 40 28.7 45 28.7 50 28.8 55 28.8 60 28.8 65 28.1... (2 Replies)
Discussion started by: Akshay Hegde
2 Replies

4. Shell Programming and Scripting

Log function.

I have to make a log function which will take any statement and write it to a file along with the time stamp.Right now I have the following code: log() { echo "`date` `hostname`: $1" >> logfile } echo "Some statement." log "Some statement." This way I can see "Some... (7 Replies)
Discussion started by: chacko193
7 Replies

5. Shell Programming and Scripting

Whats wrong in the Function ?

Need your assistance, to find the bug in the function. Function usage erroring out even after passing parameters. usage() { if || ; then echo "************************************************************" echo " CHECK USAGE FOR CORRECT PARAMETERS ... (26 Replies)
Discussion started by: raghunsi
26 Replies

6. Shell Programming and Scripting

Function returns wrong values - solved

Hi I have a small function which returns a wrong value. The function tries to make a connection to oracle database and tries to get the open_mode of the database in the variable status. However when a database is down the value of the status column is set to READWRITE i am not sure why. I... (0 Replies)
Discussion started by: xiamin
0 Replies

7. Programming

Dynamic loader taking function from wrong lib

Hi, I have two dynamically loaded libraries (shared objects), both of which include functions of the same name - foo. When I call 'foo' from libA, it takes it from libB, although it is implemented in libA as well. Since we need the function to be called from libA, we tried linking it with the... (1 Reply)
Discussion started by: rimon
1 Replies

8. Shell Programming and Scripting

Wrong date function

Hi, I am getting some very strange output when using date function in PERL on Solaris. Infact the month portion is wrong and it is 1 less then the current, means today it is responding as month =3 , andthis should be 4 ------> April Any help my code is ($day, $month, $year) =... (3 Replies)
Discussion started by: Asteroid
3 Replies

9. Shell Programming and Scripting

Log function

How do i write a code to convert watt to dBm and vice versa? 1o log(w) + 30 = dBm Thanks! (17 Replies)
Discussion started by: Ernst
17 Replies

10. Shell Programming and Scripting

Whats wrong with my function?? <newbie>

First of all im using Bash, on a Debian-based machine. I tried to write a function that if the ls program found listed more than 25 lines I would automaticly use "ls | less". Its on another computer but if I recall it looked something like this... Note: some code may look strange because im on... (4 Replies)
Discussion started by: riwa
4 Replies
Login or Register to Ask a Question