newby - error: 'rint' was not declared in this scope

D

Darren L. Weber

I am trying to compile a utility to create .avi files. See
http://cpbotha.net/im2avi
I'm working on Debian etch (a mix of testing/unstable).

dweber@dnlweber:~/im2avi-0.4$ g++ --version
g++ (GCC) 4.0.4 20060507 (prerelease) (Debian 4.0.3-3)
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is
NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.


When I try to compile, I am getting a lot of scope errors. I've fixed
a lot of them by just using std:: where it is missing. However, I
don't know a fix for this one:

im2avi_t.cxx: In member function 'void
im2avi_t::update_image_width(bool)':
im2avi_t.cxx:338: error: 'rint' was not declared in this scope

The program source named im2avi_t.cxx includes, among others:

#include <math.h> // where I assume we get rint()

The section of code, among others, that has this error is:

void im2avi_t::update_image_width(bool ignore_aspect)
{
// update class variable
image_width = (int)main_window->im_width_input->value();
// update modulus ui elements
main_window->wm4_output->value(image_width % 4);
main_window->wm8_output->value(image_width % 8);
main_window->wm16_output->value(image_width % 16);
// update height if allowed
if (!ignore_aspect && main_window->constrain_aspect_check->value())
{
main_window->im_height_input->value(rint(image_width /
image_aspect_ratio));
update_image_height(true);
}
// we only update the image aspect ratio if the user has told us NOT
to constrain it, but the programmer has NOT
// told us to ignore it, else we get strange interaction when width
changes affect height and vice versa
if (!main_window->constrain_aspect_check->value() && !ignore_aspect
&& image_width > 0 && image_height > 0)
{
update_image_aspect_ratio((float) image_width / (float)
image_height);
}
}


How do I fix this error related to rint()

Thanks in advance, Darren
 
S

shadowman615

Darren said:
I am trying to compile a utility to create .avi files. See
http://cpbotha.net/im2avi
I'm working on Debian etch (a mix of testing/unstable).

dweber@dnlweber:~/im2avi-0.4$ g++ --version
g++ (GCC) 4.0.4 20060507 (prerelease) (Debian 4.0.3-3)
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is
NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.


When I try to compile, I am getting a lot of scope errors. I've fixed
a lot of them by just using std:: where it is missing. However, I
don't know a fix for this one:

im2avi_t.cxx: In member function 'void
im2avi_t::update_image_width(bool)':
im2avi_t.cxx:338: error: 'rint' was not declared in this scope

The program source named im2avi_t.cxx includes, among others:

#include <math.h> // where I assume we get rint()
How do I fix this error related to rint()


did you try :
#include <cmath>
and
std::rint()

??
 
P

Pete Becker

Scratch that -- rint() is a C function and not a c++ function -- isn't
in <cmath> or <math.h> at all.

It's in C99's <math.h>, and TR1 adds it to C++'s <math.h> and <cmath>.
So it's worth trying.
 
D

Darren L. Weber

did you try :
#include <cmath>
and
std::rint()

??


Yes, more problems with that:

/usr/lib/gcc/i486-linux-gnu/4.0.4/../../../../include/c++/4.0.4/cmath:99:
error: '::acos' has not been declared
/usr/lib/gcc/i486-linux-gnu/4.0.4/../../../../include/c++/4.0.4/cmath:116:
error: '::asin' has not been declared
/usr/lib/gcc/i486-linux-gnu/4.0.4/../../../../include/c++/4.0.4/cmath:131:
error: '::atan' has not been declared
/usr/lib/gcc/i486-linux-gnu/4.0.4/../../../../include/c++/4.0.4/cmath:146:
error: '::atan2' has not been declared
/usr/lib/gcc/i486-linux-gnu/4.0.4/../../../../include/c++/4.0.4/cmath:162:
error: '::ceil' has not been declared
/usr/lib/gcc/i486-linux-gnu/4.0.4/../../../../include/c++/4.0.4/cmath:177:
error: '::cos' has not been declared
/usr/lib/gcc/i486-linux-gnu/4.0.4/../../../../include/c++/4.0.4/cmath:192:
error: '::cosh' has not been declared
/usr/lib/gcc/i486-linux-gnu/4.0.4/../../../../include/c++/4.0.4/cmath:207:
error: '::exp' has not been declared
/usr/lib/gcc/i486-linux-gnu/4.0.4/../../../../include/c++/4.0.4/cmath:222:
error: '::fabs' has not been declared
/usr/lib/gcc/i486-linux-gnu/4.0.4/../../../../include/c++/4.0.4/cmath:237:
error: '::floor' has not been declared
/usr/lib/gcc/i486-linux-gnu/4.0.4/../../../../include/c++/4.0.4/cmath:252:
error: '::fmod' has not been declared
/usr/lib/gcc/i486-linux-gnu/4.0.4/../../../../include/c++/4.0.4/cmath:262:
error: '::frexp' has not been declared
/usr/lib/gcc/i486-linux-gnu/4.0.4/../../../../include/c++/4.0.4/cmath:277:
error: '::ldexp' has not been declared
/usr/lib/gcc/i486-linux-gnu/4.0.4/../../../../include/c++/4.0.4/cmath:292:
error: '::log' has not been declared
/usr/lib/gcc/i486-linux-gnu/4.0.4/../../../../include/c++/4.0.4/cmath:307:
error: '::log10' has not been declared
/usr/lib/gcc/i486-linux-gnu/4.0.4/../../../../include/c++/4.0.4/cmath:322:
error: '::modf' has not been declared
/usr/lib/gcc/i486-linux-gnu/4.0.4/../../../../include/c++/4.0.4/cmath:341:
error: '::pow' has not been declared
/usr/lib/gcc/i486-linux-gnu/4.0.4/../../../../include/c++/4.0.4/cmath:363:
error: '::sin' has not been declared
/usr/lib/gcc/i486-linux-gnu/4.0.4/../../../../include/c++/4.0.4/cmath:378:
error: '::sinh' has not been declared
/usr/lib/gcc/i486-linux-gnu/4.0.4/../../../../include/c++/4.0.4/cmath:393:
error: '::sqrt' has not been declared
/usr/lib/gcc/i486-linux-gnu/4.0.4/../../../../include/c++/4.0.4/cmath:408:
error: '::tan' has not been declared
/usr/lib/gcc/i486-linux-gnu/4.0.4/../../../../include/c++/4.0.4/cmath:423:
error: '::tanh' has not been declared
im2avi_t.cxx: In member function 'void
im2avi_t::update_image_width(bool)':
im2avi_t.cxx:339: error: 'rint' is not a member of 'std'


Should I switch to an older compiler? I wonder if these problems are
related to gcc4.0.4
 
D

Darren L. Weber

Darren said:
Yes, more problems with that:

/usr/lib/gcc/i486-linux-gnu/4.0.4/../../../../include/c++/4.0.4/cmath:99:
error: '::acos' has not been declared
/usr/lib/gcc/i486-linux-gnu/4.0.4/../../../../include/c++/4.0.4/cmath:116:
error: '::asin' has not been declared
/usr/lib/gcc/i486-linux-gnu/4.0.4/../../../../include/c++/4.0.4/cmath:131:
error: '::atan' has not been declared
/usr/lib/gcc/i486-linux-gnu/4.0.4/../../../../include/c++/4.0.4/cmath:146:
error: '::atan2' has not been declared
/usr/lib/gcc/i486-linux-gnu/4.0.4/../../../../include/c++/4.0.4/cmath:162:
error: '::ceil' has not been declared
/usr/lib/gcc/i486-linux-gnu/4.0.4/../../../../include/c++/4.0.4/cmath:177:
error: '::cos' has not been declared
/usr/lib/gcc/i486-linux-gnu/4.0.4/../../../../include/c++/4.0.4/cmath:192:
error: '::cosh' has not been declared
/usr/lib/gcc/i486-linux-gnu/4.0.4/../../../../include/c++/4.0.4/cmath:207:
error: '::exp' has not been declared
/usr/lib/gcc/i486-linux-gnu/4.0.4/../../../../include/c++/4.0.4/cmath:222:
error: '::fabs' has not been declared
/usr/lib/gcc/i486-linux-gnu/4.0.4/../../../../include/c++/4.0.4/cmath:237:
error: '::floor' has not been declared
/usr/lib/gcc/i486-linux-gnu/4.0.4/../../../../include/c++/4.0.4/cmath:252:
error: '::fmod' has not been declared
/usr/lib/gcc/i486-linux-gnu/4.0.4/../../../../include/c++/4.0.4/cmath:262:
error: '::frexp' has not been declared
/usr/lib/gcc/i486-linux-gnu/4.0.4/../../../../include/c++/4.0.4/cmath:277:
error: '::ldexp' has not been declared
/usr/lib/gcc/i486-linux-gnu/4.0.4/../../../../include/c++/4.0.4/cmath:292:
error: '::log' has not been declared
/usr/lib/gcc/i486-linux-gnu/4.0.4/../../../../include/c++/4.0.4/cmath:307:
error: '::log10' has not been declared
/usr/lib/gcc/i486-linux-gnu/4.0.4/../../../../include/c++/4.0.4/cmath:322:
error: '::modf' has not been declared
/usr/lib/gcc/i486-linux-gnu/4.0.4/../../../../include/c++/4.0.4/cmath:341:
error: '::pow' has not been declared
/usr/lib/gcc/i486-linux-gnu/4.0.4/../../../../include/c++/4.0.4/cmath:363:
error: '::sin' has not been declared
/usr/lib/gcc/i486-linux-gnu/4.0.4/../../../../include/c++/4.0.4/cmath:378:
error: '::sinh' has not been declared
/usr/lib/gcc/i486-linux-gnu/4.0.4/../../../../include/c++/4.0.4/cmath:393:
error: '::sqrt' has not been declared
/usr/lib/gcc/i486-linux-gnu/4.0.4/../../../../include/c++/4.0.4/cmath:408:
error: '::tan' has not been declared
/usr/lib/gcc/i486-linux-gnu/4.0.4/../../../../include/c++/4.0.4/cmath:423:
error: '::tanh' has not been declared
im2avi_t.cxx: In member function 'void
im2avi_t::update_image_width(bool)':
im2avi_t.cxx:339: error: 'rint' is not a member of 'std'


Should I switch to an older compiler? I wonder if these problems are
related to gcc4.0.4


I also tried math::rint() and it doesn't work. I don't know where
rint() comes from. How can I trace or find where rint() belongs (I've
already tried google, to no avail)?
 
S

shadowman615

Darren L. Weber wrote:
I also tried math::rint() and it doesn't work. I don't know where
rint() comes from. How can I trace or find where rint() belongs (I've
already tried google, to no avail)?

rint() is supposed to round to the nearest integer. Cmath includes a
floor and ceiling function, although this won't do exactly what you're
looking for. Perhaps the simplest thing to do is to define your own
rint() function that takes whatever type
image_width / image_aspect_ratio yeilds and returns that number
rounded to the nearest int.

As long as that's the only place that rint() occurs in your code. You
may need to define versions for other type parameters also, if
necessary.
 
F

Frederick Gotham

Shadowman posted:

rint() is supposed to round to the nearest integer.


Trivial:

template<class IntType,class FloatType>
inline IntType rint(FloatType const val)
{
return (IntType)(val + 0.5);

/* Cast used to suppress truncation warning */
}
 
S

shadowman615

Frederick said:
Shadowman posted:




Trivial:

template<class IntType,class FloatType>
inline IntType rint(FloatType const val)
{
return (IntType)(val + 0.5);

/* Cast used to suppress truncation warning */
}
You may want to extend that to work for negative numbers as well, if
necessary. Also trivial.
 
F

Frederick Gotham

Shadowman posted:
You may want to extend that to work for negative numbers as well, if
necessary. Also trivial.


val ? val + 0.5 : val - 0.5


Or perhaps:

val + (val ? 0.5 : -0.5)


I'd hazard a guess that the former would be more efficient...
 
P

Pete Becker

Frederick said:
Shadowman posted:

It's supposed to round using the current rounding mode, which can be any
of downward, to nearest, toward zero, upward, or an
implementation-defined set of additional modes.
Trivial:

template<class IntType,class FloatType>
inline IntType rint(FloatType const val)
{
return (IntType)(val + 0.5);

/* Cast used to suppress truncation warning */
}

With round to nearest, rint(-1.1) should be -1. This function return 0.
 
R

Richard Herring

Pete Becker said:
It's supposed to round using the current rounding mode, which can be
any of downward, to nearest, toward zero, upward, or an
implementation-defined set of additional modes.

Shouldn't modal libraries be considered Evil?
 
R

Richard Herring

Pete Becker said:

I was rather hoping to provoke more discussion than that ;-)

Global modes mean that if I link third-party code that uses this
library, it can alter the semantics of my code. Of course, I can protect
my code by wrapping it with appropriate constructs to preserve and
restore the mode, but there are costs in both program complexity and
runtime performance.

I need to be convinced that that's not a bad thing, or that the
alternatives are worse.
 
P

Pete Becker

Richard said:
I was rather hoping to provoke more discussion than that ;-)

Then you should have said more. said:
Global modes mean that if I link third-party code that uses this
library, it can alter the semantics of my code. Of course, I can protect
my code by wrapping it with appropriate constructs to preserve and
restore the mode, but there are costs in both program complexity and
runtime performance.

I need to be convinced that that's not a bad thing, or that the
alternatives are worse.

Sweeping generalizations are always wrong. Except this one.

The floating-point processor is modal. It has internal registers that
hold flags that tell it how to do things. The math libraries reflect
that design. Doing otherwise slows everything down.

Using modal resources correctly requires application-level design.
That's not inherently bad, but many programmers are uncomfortable with
it. They've heard the slogans about always solving problems in code, so
they write code with redundant low-level "safety" checks, lots of
setting and getting, and multiple short statements instead of terse,
tight code, then they rely on the mystical powers of the optimiser to
make the application acceptably fast and small. Sometimes it produces
something acceptable.

The right approach is not hacking in localized protection in case
someone does something wrong, but deciding how the application will use
that resource, and ensuring that that decision is followed. If that
means getting rid of a third-party library that doesn't play by the
rules, then get rid of it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top