# [racket-dev] Racket Questions?

 From: Neil Toronto (neil.toronto at gmail.com) Date: Mon Sep 17 11:25:08 EDT 2012 Previous message: [racket-dev] Racket Questions? Next message: [racket-dev] syntax parsing: must be a nice pattern-y way to do this Messages sorted by: [date] [thread] [subject] [author]

```I'll implement `flmodulo' in the math library, which already has
`flodd?' and `fleven?'. These things can be tricky to get right; for
example, most people wouldn't notice that their implementation is wrong
on negative inputs. I'll probably also do `flremainder'.

Neil ⊥

On 09/15/2012 12:45 PM, Michael Wilber wrote:
> For the record, I've always just defined my own modulo when I need it
> for floats:
>
> ; A modulo operator for floats!
> (define (float-modulo p q)
>    (- p (* q (truncate (/ p q)))))
>
> It doesn't properly handle negative numbers though.
>
> David Van Horn <dvanhorn at ccs.neu.edu> writes:
>> On 9/14/12 3:36 PM, Becca MacKenzie wrote:
>>> Hello!
>>> So a friend of mine just started learning Racket and was wondering if
>>> there's a particular reason why the modulo function in racket only takes
>>> in integers? He wrote his own mod function to take in other things but
>>> he was just wondering what the reasoning is behind this.
>>
>> Hi Becca,
>>
>> Excellent question -- I hope you don't mind that I've forwarded it to
>> the Racket developers list for a more authoritative answer (and
>> potentially a change to Racket).
>>
>> I don't believe there's any principled reason not to extend `modulo' to
>> other kinds of numbers such as rationals and (exact) complex numbers.  I
>> worry that the idea of modulo may not be well defined for inexact
>> numbers, but I could be wrong (inexact numbers don't obey a lot of the
>> usual mathematical properties we're used to).  I see that in
>> Mathematica, "the arguments of Mod can be any numeric quantities, not
>> necessarily integers".  Here are some examples:
>>
>>      http://reference.wolfram.com/mathematica/ref/Mod.html#6881
>>
>> Recently, Racket's GCD and LCM were extended to work on non-integer
>> arguments, and I believe this is a similar case where the function could
>> (and should?) be extended to work for more kinds of numbers.  But I'm
>> interested to hear what the dev list has to say on the matter.
>>
>> David
>>
>> _________________________
>>    Racket Developers list:
>>    http://lists.racket-lang.org/dev
> _________________________
>    Racket Developers list:
>    http://lists.racket-lang.org/dev
>

```

 Posted on the dev mailing list. Previous message: [racket-dev] Racket Questions? Next message: [racket-dev] syntax parsing: must be a nice pattern-y way to do this Messages sorted by: [date] [thread] [subject] [author]