By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,939 Members | 1,638 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,939 IT Pros & Developers. It's quick & easy.

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

P: n/a

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

Jul 20 '06 #1
Share this Question
Share on Google+
14 Replies


P: n/a

Darren L. Weber wrote:
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()
< snip >

How do I fix this error related to rint()

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

??

Jul 20 '06 #2

P: n/a

shadowman...@comcast.net wrote:
Darren L. Weber wrote:
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()
< snip >

How do I fix this error related to rint()


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

??
Scratch that -- rint() is a C function and not a c++ function -- isn't
in <cmathor <math.hat all.

Jul 20 '06 #3

P: n/a
sh**********@comcast.net wrote:
>
Scratch that -- rint() is a C function and not a c++ function -- isn't
in <cmathor <math.hat all.
It's in C99's <math.h>, and TR1 adds it to C++'s <math.hand <cmath>.
So it's worth trying.
Jul 20 '06 #4

P: n/a

sh**********@comcast.net wrote:
Darren L. Weber wrote:
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()
< snip >

How do I fix this error related to rint()


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

Jul 20 '06 #5

P: n/a

Darren L. Weber wrote:
sh**********@comcast.net wrote:
Darren L. Weber wrote:
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()
< snip >

How do I fix this error related to rint()

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

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)?

Jul 20 '06 #6

P: n/a

Darren L. Weber wrote:
<Snipped Errors>
>
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.

Jul 21 '06 #7

P: n/a
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 */
}
--

Frederick Gotham
Jul 21 '06 #8

P: n/a

Frederick Gotham wrote:
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 */
}
You may want to extend that to work for negative numbers as well, if
necessary. Also trivial.

Jul 21 '06 #9

P: n/a
Shadowman posted:
>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.

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...
--

Frederick Gotham
Jul 21 '06 #10

P: n/a
Frederick Gotham wrote:
Shadowman posted:
>>rint() is supposed to round to the nearest integer.
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.
Jul 21 '06 #11

P: n/a
In message <l9******************************@giganews.com>, Pete Becker
<pe********@acm.orgwrites
>Frederick Gotham wrote:
>Shadowman posted:
>>>rint() is supposed to round to the nearest integer.

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?

--
Richard Herring
Jul 21 '06 #12

P: n/a
Richard Herring wrote:
In message <l9******************************@giganews.com>, Pete Becker
<pe********@acm.orgwrites
>Frederick Gotham wrote:
>>Shadowman posted:

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


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?
No.
Jul 21 '06 #13

P: n/a
In message <q6******************************@giganews.com>, Pete Becker
<pe********@acm.orgwrites
>Richard Herring wrote:
>In message <l9******************************@giganews.com>, Pete
Becker <pe********@acm.orgwrites
>>Frederick Gotham wrote:

Shadowman posted:

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

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?

No.
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.

--
Richard Herring
Jul 24 '06 #14

P: n/a
Richard Herring wrote:
In message <q6******************************@giganews.com>, Pete Becker
<pe********@acm.orgwrites
>Richard Herring wrote:
>>In message <l9******************************@giganews.com>, Pete
Becker <pe********@acm.orgwrites

Frederick Gotham wrote:

Shadowman posted:
>
>rint() is supposed to round to the nearest integer.
>
>
>

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?

No.


I was rather hoping to provoke more discussion than that ;-)
Then you should have said more. <g>
>
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.
Jul 24 '06 #15

This discussion thread is closed

Replies have been disabled for this discussion.