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

log10

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 function is a double.
Thanks for any advice.

RBS

Apr 15 '06 #1
2 3972
In article <6Sb0g.101579$zI1.33994
@fe2.news.blueyonder.co.uk>,
ba***********@blueyonder.co.uk says...
Just starting with C++ in MS VC6++.

Why does this:

return (log10(70));

produce 1 and not 1.845098 ?


It's virtually impossible for us to guess without seeing
your actual code. As written, it shouldn't compile --
log10 is overloaded for float, double and long double
arguments. You're passing an int, so all of these are
equally acceptable possibilities, creating an ambiguity.
To get this to compile as C++, you could use something
like 'return log10(70.0);' instead. Since you're passing
a double, the overload taking a double becomes preferred
and the ambiguity is removed.

If it's compiling as-is, you're probably compiling the
code as C. In this case, my first guess at the problem is
that you're not including <math.h>, so the proper return
type for the function isn't known (to the compiler). In
that case, it assumes the function returns an int. That
means the compiler will take whatever bit pattern it
returns and assume it's an int. Since you defined your
function to return a double, it's then converting that
bit pattern to a double. The fact that it's close to the
value you expected is mostly accidental.

Both of these seem to give correct answers:

// C++
#include <math.h>
#include <iostream>

int main() {
std::cout << log10(70.0);
return 0;
}

// C (won't compile as C++)
#include <math.h>
#include <stdio.h>

int main() {
printf("%f\n", log10(70));
return 0;
}

--
Later,
Jerry.

The universe is a figment of its own imagination.
Apr 15 '06 #2
Ignore this, I had declared a variable as int in Main.

RBS

"RB Smissaert" <ba***********@blueyonder.co.uk> wrote in message
news:6S********************@fe2.news.blueyonder.co .uk...
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 function is a double.
Thanks for any advice.

RBS


Apr 15 '06 #3

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

Similar topics

1
by: bblochl | last post by:
I found a solution for the simulation of access modifier "static final " in python: class Mytest: LOGE_10=(2.302585092994046,) #Klassenkonstante (static final) use a tuple :-) #def...
181
by: Tom Anderson | last post by:
Comrades, During our current discussion of the fate of functional constructs in python, someone brought up Guido's bull on the matter: http://www.artima.com/weblogs/viewpost.jsp?thread=98196 ...
17
by: Filipe Martins | last post by:
Hello. I've read somewhere that the executable is smaller if we use a source file for each function! So, I tested this with gcc and it seams to confirm! What seams to happen is that if we call...
7
by: a.dheeraj.kumar | last post by:
i know that there is a function to find the logarithm of a number, sin, cos, tan etc. but are there which can find sin^-1, cos^-1, tan^-1 and antilog of a given number? PS: sin^-1 means sin...
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...
14
by: Peter Sprenger | last post by:
Hello, I want to efficient convert floating point numbers (IEEE754) into a string. I have no library routines that do the job (like sprintf etc.), because I work in an embedded environment. ...
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):...
17
by: spooler123 | last post by:
Just a small little program. Can not figure out what am I doing wrong. #include <stdio.h> #include <limits.h> #include <float.h> int main() { double max = FLT_MAX;
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
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
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.