mod - rest of a division

J

Jo

Hi Guys!

I'm sorry for my stupid question.

I want to use the operator "mod" (perhaps mod is pascal and not c++)

to calculate the rest of a division, to separate the odd and even number of
an array.

do you know what is the name of operator I need ? ("mod" is pascal ?)

do I need some libraries ? math.h or wath ?

Thank you

Jo
 
R

Rolf Magnus

Jo said:
Hi Guys!

I'm sorry for my stupid question.

I want to use the operator "mod" (perhaps mod is pascal and not c++) to
calculate the rest of a division, to separate the odd and even number
of an array.

do you know what is the name of operator I need ? ("mod" is pascal ?)
%

do I need some libraries ? math.h or wath ?

No.
 
?

=?ISO-8859-1?Q?Sacha_Sch=E4r?=

Jo said:
Hi Guys!

I'm sorry for my stupid question.

I want to use the operator "mod" (perhaps mod is pascal and not c++)

to calculate the rest of a division, to separate the odd and even number of
an array.

do you know what is the name of operator I need ? ("mod" is pascal ?)

do I need some libraries ? math.h or wath ?

Thank you

Jo

The operator is '%', there is no library required...

-Sacha
 
G

Gernot Frisch

Jo said:
Hi Guys!

I'm sorry for my stupid question.

I want to use the operator "mod" (perhaps mod is pascal and not c++)

to calculate the rest of a division, to separate the odd and even
number of an array.

do you know what is the name of operator I need ? ("mod" is pascal
?)

do I need some libraries ? math.h or wath ?


if you want to do this on floats, you must use:
#include <math.h>

mod_val = fmod(number, divisor);

-Gernot
 
J

Jakob Bieling

if you want to do this on floats, you must use:
#include <math.h>

mod_val = fmod(number, divisor);

Iirc, that should read

#include <cmath>

mod_val = std::fmod (number, divisor);

?

regards
 
J

Jakob Bieling

Jakob Bieling wrote:
Both are legal and both do the same thing.

Oh, did not know you can actually use math.h etc.

After a little more reading, I am now confused, though. I read 26.5/1-6
and D.5/2 of the Standard. In the former, they write about cmath/cstdlib
containing the same things as math.h/stdlib.h, _plus_ some additional
overloads. But in the latter, they write name.h includes the same thing as
cname, but places them in both the std and the global namespace.

Did I fail to see something? Afaik, it might make a difference, if
math.h includes those additions or not (ie. the long double overload, which
you need to avoid possible down-casting).

regards
 
P

Pete Becker

Jakob said:
After a little more reading, I am now confused, though. I read 26.5/1-6
and D.5/2 of the Standard. In the former, they write about cmath/cstdlib
containing the same things as math.h/stdlib.h, _plus_ some additional
overloads. But in the latter, they write name.h includes the same thing as
cname, but places them in both the std and the global namespace.

Did I fail to see something? Afaik, it might make a difference, if
math.h includes those additions or not (ie. the long double overload, which
you need to avoid possible down-casting).

When compiling C++ code math.h has the C++ overloads. As you noted,
cmath adds some things to the requirements for math.h from the C
standard. Appendix D says that when compiling C++ code math.h has all
the things that cmath has, and hoists them into the global namespace. So
math.h is usually not just the C header; it has to be modified for C++.
 

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
474,199
Messages
2,571,045
Members
47,643
Latest member
ashutoshjha_1101

Latest Threads

Top