On 10/4/07, Hamptonio <[EMAIL PROTECTED]> wrote:
>
> I am porting some Mathematica code to sage and I ran into a minor
> issue.  I was using the Mod command in mathematica with argument types
> Mod[float,integer] to create a periodic function.  In sage, the mod
> command gives an error on that sort of input.  So I made a simple
> function:
>
> def float_mod(x,divisor):
>     '''An extension of the mod command for floats.'''
>     return x-floor(float(x)/divisor)*divisor
>
> which does what I want.  Is there something like this already in
> sage?

Yes, %, e.g.,

sage: a = float(1.2393); b = int(5)
sage: a % b
1.2393000000000001
sage: a = float(1.2393); b = int(1)
sage: a % b
0.23930000000000007

That this doesn't work on Sage types, i.e., Sage real numbers
and Sage integers is because we didn't think to implement it:

sage: 1.2394 % 1

boom because we didn't think to implement.

Should this be added to Sage?  If somebody thinks so...
implement it and post a trac ticket.

> I know the normal python % operation does something similar but
> that's taken out by the preparser.

The Sage preparser doesn't touch %:

sage: preparse('a % b')
'a % b'


William

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-devel@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/sage-devel
URLs: http://sage.scipy.org/sage/ and http://modular.math.washington.edu/sage/
-~----------~----~----~----~------~----~------~--~---

Reply via email to