Mod function that returns quotient remainder?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Mod function that returns quotient remainder?

kurtosis
Hello, is there a 'mod' that returns the remainder of a quotient?  eg,

    mod(5/2) = 1?  

I know you can find out if there is a remainder by

    if trunc(Y / 2) * 2 == Y

but is there a way to return the actual remainder?  Thanks,

Byron
Reply | Threaded
Open this post in threaded view
|

Re: [erlang-questions] Mod function that returns quotient remainder?

Rick Pettit
On Wed, Sep 06, 2006 at 09:08:35PM -0700, fbg111 wrote:
>
> Hello, is there a 'mod' that returns the remainder of a quotient?  eg,
>
>     mod(5/2) = 1?  

5 rem 2.

> I know you can find out if there is a remainder by
>
>     if trunc(Y / 2) * 2 == Y
>
> but is there a way to return the actual remainder?  Thanks,

Out of curiousity, how did you find out about trunc/1? FYI, a 5 minute google
search could have gotten you an answer (re: rem) much faster than posting to
the list (don't get me wrong, I don't mind helping when I can :-).

-Rick
_______________________________________________
erlang-questions mailing list
[hidden email]
http://www.erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Mod function that returns quotient remainder?

fbg111

I came across it in the getting started guide, and saw that trunc was used in
a way I've used mod before in other languages, so I wanted to try replacing
it with mod.  I tried searching the Erlang documentation (I always do b/f
posting such questions), but it's not clear what to search for.  It's not in
the math module, and you have to know the spelling to find it in the
glossary and index.  But you're right, next time I'll Google it first.
Thanks,

Byron


Rick Pettit wrote:

>
> On Wed, Sep 06, 2006 at 09:08:35PM -0700, fbg111 wrote:
>>
>> Hello, is there a 'mod' that returns the remainder of a quotient?  eg,
>>
>>     mod(5/2) = 1?  
>
> 5 rem 2.
>
>> I know you can find out if there is a remainder by
>>
>>     if trunc(Y / 2) * 2 == Y
>>
>> but is there a way to return the actual remainder?  Thanks,
>
> Out of curiousity, how did you find out about trunc/1? FYI, a 5 minute
> google
> search could have gotten you an answer (re: rem) much faster than posting
> to
> the list (don't get me wrong, I don't mind helping when I can :-).
>
> -Rick
> _______________________________________________
> erlang-questions mailing list
> erlang-questions
> http://www.erlang.org/mailman/listinfo/erlang-questions
>
>

--
View this message in context: http://www.nabble.com/Mod-function-that-returns-quotient-remainder--tf2231023.html#a6184239
Sent from the Erlang Questions forum at Nabble.com.



Reply | Threaded
Open this post in threaded view
|

Re: [erlang-questions] Mod function that returns quotient remainder?

kurtosis
In reply to this post by Rick Pettit
I came across it in the getting started guide, and saw that trunc was used in a way I've used mod before in other languages, so I wanted to try replacing it with mod.  I tried searching the Erlang documentation (I always do b/f posting such questions), but it's not clear what to search for.  It's not in the math module, and you have to know the spelling to find it in the glossary and index.  But you're right, next time I'll Google it first.  Thanks,

Byron

Rick Pettit wrote
On Wed, Sep 06, 2006 at 09:08:35PM -0700, fbg111 wrote:
>
> Hello, is there a 'mod' that returns the remainder of a quotient?  eg,
>
>     mod(5/2) = 1?  

5 rem 2.

> I know you can find out if there is a remainder by
>
>     if trunc(Y / 2) * 2 == Y
>
> but is there a way to return the actual remainder?  Thanks,

Out of curiousity, how did you find out about trunc/1? FYI, a 5 minute google
search could have gotten you an answer (re: rem) much faster than posting to
the list (don't get me wrong, I don't mind helping when I can :-).

-Rick
_______________________________________________
erlang-questions mailing list
erlang-questions@erlang.org
http://www.erlang.org/mailman/listinfo/erlang-questions