help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Wrong 'log' results when using .oct files (more info)


From: Javier Perez
Subject: Wrong 'log' results when using .oct files (more info)
Date: Thu, 11 Jan 2001 11:28:30 +0100 (CET)

Hi again,

I realised that using 'float' instead of 'double' to store the result of
dividing the two logarithms, works perfectly. I mean, writing:

        float j = log(M)/log(2);

So, I guess I should change my question to something like: Could anyone explain
me the differences between 'double' and 'float'? Is because of this differences
the result is different?

Thanks,
Javier

> I'm trying to compute the logarithm in base 2 of a number, in C++, since it's
> part of a .oct file. The code is really simple, and it works fine in a
> standalone program. The problem is that when used inside a .oct file, the file
> "octave/config.h" is included, and the results change. Am I doing some stupid
> mistake? Should I use a different way of computing the logarithm?? 
> 
> This simple code demonstrates my problem:
> 
> <-------- begin: "test_log.cc" ------------>
> #include <octave/config.h>
> 
> #include <iostream>
> #include <math.h>
> 
> int main() {
> 
>     int M = 8;
>     double j = log(M)/log(2);
>     std::cout << "(int) log2(" << M << "): " << j << " " << (int)j << 
> std::endl;
> 
>     return 1;
> }
> 
> <-------- end: "test_log.cc" ------------->

--
Javier Perez

PIPEBEACH AB
Box 240235
SE-104 50 Stockholm, Sweden

Mobile: +46 (0)70 488 13 58
Office: +46 (0)8 545 90 990
Fax:    +46 (0)8 545 90 993

www.pipebeach.com




-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]