double roundup(double num,double to){ return (num+to/2-((num+to/2) %
to)) ; }
Compiler error:
error C2296: '%' : illegal, left operand has type 'double' 8 4744
Hi,
Maybe taking the modulus of a real number doesn't make sense?
--
Regards, Ron AF Greve http://moonlit.xs4all.nl
"E.T. Grey" <ne****@alpha-centauri.com> wrote in message
news:di**********@nwrdmz03.dmz.ncs.ea.ibs-infra.bt.com... double roundup(double num,double to){ return (num+to/2-((num+to/2) % to)) ; }
Compiler error:
error C2296: '%' : illegal, left operand has type 'double'
E.T. Grey wrote: double roundup(double num,double to){ return (num+to/2-((num+to/2) % to)) ; }
Compiler error:
error C2296: '%' : illegal, left operand has type 'double'
The operands of the modulo operator must be of integral type.
You can either convert the double value on the left side into an integral
type or you can use fmod function in file math.h to get the remainder of a
fdouble value.
"Moonlit" <news moonlit xs4all nl> wrote in message
news:43***********************@news.xs4all.nl... Maybe taking the modulus of a real number doesn't make sense?
It does, actually -- on every floating-point implementation I've ever seen,
every floating-point number represents a rational number, and modulus is
well defined on rationals. Not only that, but it is generally possible to
represent the result of modulus exactly as a floating-point number.
Nevertheless, this operation is not built into C or C++, so you need to use
the library fmod function if that's what you want.
In article <di**********@nwrdmz03.dmz.ncs.ea.ibs-infra.bt.com>,
E.T. Grey <ne****@alpha-centauri.com> wrote: double roundup(double num,double to){ return (num+to/2-((num+to/2) % to)) ; }
Compiler error:
error C2296: '%' : illegal, left operand has type 'double'
Right, in C++ you can't % a double. You have to use the standard
library to do that, for instance fmod, fmodf and fmodld from math.h/cmath.
I seem to recall they will also let you catch some floating point
exceptions too, which may be why double %ing is not allowed.
BTW, I THINK C99 also has a remainder() function but not C90
so you'd need to check this, and also have a C99 compiler.
--
Greg Comeau / Celebrating 20 years of Comeauity!
Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
In article <43***********************@news.xs4all.nl>,
Moonlit <news moonlit xs4all nl> wrote: "E.T. Grey" <ne****@alpha-centauri.com> wrote in message news:di**********@nwrdmz03.dmz.ncs.ea.ibs-infra.bt.com... double roundup(double num,double to){ return (num+to/2-((num+to/2) % to)) ; }
Compiler error:
error C2296: '%' : illegal, left operand has type 'double'
Maybe taking the modulus of a real number doesn't make sense?
I think we've been training to assume such things (certainly
elementary school does), but otherwise, I see no reason why
that needs to be the case.
--
Greg Comeau / Celebrating 20 years of Comeauity!
Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
In article <di*************@news.t-online.com>,
Sebastian Wiesner <Ba***********@gmx.net> wrote: E.T. Grey wrote:
double roundup(double num,double to){ return (num+to/2-((num+to/2) % to)) ; }
Compiler error:
error C2296: '%' : illegal, left operand has type 'double' The operands of the modulo operator must be of integral type.
or enum.
You can either convert the double value on the left side into an integral type or you can use fmod function in file math.h to get the remainder of a fdouble value.
--
Greg Comeau / Celebrating 20 years of Comeauity!
Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
Hi,
Oops, thank you guys, for pointing out my mistake.
Yes, now I think about it, it actually does make sense :-0
Sorry OP.
Anyway the percent operator only works with integral types
--
Regards, Ron AF Greve http://moonlit.xs4all.nl
"Greg Comeau" <co****@panix.com> wrote in message
news:di**********@panix2.panix.com... In article <43***********************@news.xs4all.nl>, Moonlit <news moonlit xs4all nl> wrote:"E.T. Grey" <ne****@alpha-centauri.com> wrote in message news:di**********@nwrdmz03.dmz.ncs.ea.ibs-infra.bt.com... double roundup(double num,double to){ return (num+to/2-((num+to/2) % to)) ; }
Compiler error:
error C2296: '%' : illegal, left operand has type 'double'
Maybe taking the modulus of a real number doesn't make sense?
I think we've been training to assume such things (certainly elementary school does), but otherwise, I see no reason why that needs to be the case. -- Greg Comeau / Celebrating 20 years of Comeauity! Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90. Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
In article <43***********************@news.xs4all.nl>,
Moonlit <news moonlit xs4all nl> wrote: "Greg Comeau" <co****@panix.com> wrote in message news:di**********@panix2.panix.com... In article <43***********************@news.xs4all.nl>, Moonlit <news moonlit xs4all nl> wrote:"E.T. Grey" <ne****@alpha-centauri.com> wrote in message news:di**********@nwrdmz03.dmz.ncs.ea.ibs-infra.bt.com... double roundup(double num,double to){ return (num+to/2-((num+to/2) % to)) ; }
Compiler error:
error C2296: '%' : illegal, left operand has type 'double'
Maybe taking the modulus of a real number doesn't make sense?
I think we've been training to assume such things (certainly elementary school does), but otherwise, I see no reason why that needs to be the case.
Oops, thank you guys, for pointing out my mistake.
Yes, now I think about it, it actually does make sense :-0
Sorry OP.
Anyway the percent operator only works with integral types
Still:
And enum's.
--
Greg Comeau / Celebrating 20 years of Comeauity!
Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it? This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: penguinman |
last post by:
I type ./a.out and the shell just sits there. It doesnt hang it just
sits there looking pretty.
I run the program with the ddd option and executed it from
ddd...execution window comes up and...
|
by: John Baker |
last post by:
Hi:
Stuck on another thing.
On a report I am creating, I want to make the detail section one line vertically. However,
in design view, I click on the page Footer Bar ,grab it with the "double...
|
by: Christine |
last post by:
My code has a split function that should split the text file of numbers.
I've run this in previous programs as it is here and it worked, but now it
wont work for some reason and returns...
|
by: dhnriverside |
last post by:
HI guys
I've just written my first independent namespace for my library (yay me!).
However, on trying to add it to my website project, it causes an error when I
look at the website. It compiles...
|
by: Mr Newbie |
last post by:
Debug.Assert( False, "Why wont I display ??")
I am trying to use this in my code but it wont display. The app is running
on my local machine and the above code under a button click event.
What...
|
by: rossum |
last post by:
I want to declare a const multi-line string inside a method, and I am
having some problems using Environment.NewLine.
I started out with:
class foo {
public void PrintStuff() {
const...
|
by: jamaicaboy |
last post by:
This is the code that i need some help with...........
#include<iostream.h>
#include<iomanip.h>
class test
{
public:
void store( int);
|
by: qutspan |
last post by:
When I create taskbox on the form the line beside the box wont show up.
it show up untill I have MouseEnter event occur.
Also when I have 2 taskbox on the form it does draw the line around the...
|
by: xiaolim |
last post by:
ok, after i put these code n compile n run, gt some error :
"
undefined reference to `addstudentMODULE(int)'
undefined reference to `displayMODULE(int)'
ld returned 1 exit status
"
here...
|
by: H1TM4N |
last post by:
can someone help? Its the following code it just wont compile
thanks :)
PROGRAM Store (INPUT, OUTPUT);
VAR
Change, AmountPaid, TotalPrice :REAL;
IntChange, Dollars, Quarters, Dimes,...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |