[Top][All Lists]

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

Wrong 'log' results when using .oct files

From: Javier Perez
Subject: Wrong 'log' results when using .oct files
Date: Wed, 10 Jan 2001 17:47:55 +0100 (CET)

Hi all.

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: "" ------------>
#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: "" ------------->

I'm compiling using:

gcc -O3 -mcpu=k6 -mieee-fp -fno-rtti -fno-exceptions -fPIC
-fno-implicit-templates -o test_log -lg++
-I/home/jape/local//include/octave-2.1.32/octave -I/home/jape/local//include

Commenting out the line 
        #include <octave/config.h>
everything works fine, and I obtain the result "3". 

        address@hidden:~/cur/# ./test_log 
        (int) log2(8): 3 3

The problem is when including that file, because the result is "2".

        address@hidden:~/cur/# ./test_log
        (int) log2(8): 3 2

Any idea why is this way?

Thanks in advance

I include the results of the bug report tool:

Subject: [50 character or so descriptive subject here (for reference)]
Bug report for Octave 2.1.32 configured for %OCTAVE_CANONICAL_HOST_TYPE%

Configuration (please do not edit this section):

uname output:     Linux shiraz 2.2.14 #5 SMP Tue Mar 14 22:11:28 CET 2000 i586
configure opts:   --prefix=/home/jape/local/ --enable-shared
Fortran compiler: g77
FFLAGS:           -O3 -mcpu=k6
FLIBS:            -lg2c -lm -L/usr/lib/gcc-lib/i386-linux/2.95.2 -lm
INCFLAGS:         -I. -I. -I./liboctave -I./src -I./libcruft/misc  -I./glob
C compiler:       gcc, version 2.95.2 20000220 (Debian GNU/Linux)
CFLAGS:           -O3 -mcpu=k6
CPICFLAG:         -fPIC
C++ compiler:     c++, version 2.95.2 20000220 (Debian GNU/Linux)
CXXFLAGS:         -O3 -mcpu=k6
LDFLAGS:          -g
LIBFLAGS:         -L.
RLD_FLAG:         -Xlinker -rpath -Xlinker /home/jape/local//lib/octave-2.1.32
TERMLIBS:         -lncurses
LIBS:             -ldl -lhdf5 -lm 
LIBGLOB:          ./glob/glob.o ./glob/fnmatch.o

  -DHAVE_ALLOCA=1 -DNPOS=std::string::npos -DSTDC_HEADERS=1

Javier Perez

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

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

Octave's home on the web:
How to fund new projects:
Subscription information:

reply via email to

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