New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: Change the type of (%) to number -> number -> number #4

Closed
imeckler opened this Issue Nov 14, 2014 · 10 comments

Comments

Projects
None yet
7 participants
@imeckler
Contributor

imeckler commented Nov 14, 2014

Is there a compelling reason for (%) to have the current restricted type Int -> Int -> Int? Javascript (%) works as expected for non-integers and I often actually need this operation.

@thSoft

This comment has been minimized.

Show comment
Hide comment
@thSoft

thSoft Dec 5, 2014

Contributor

+1

Contributor

thSoft commented Dec 5, 2014

+1

@imeckler

This comment has been minimized.

Show comment
Hide comment
@imeckler

imeckler Jan 20, 2015

Contributor

In response to evancz's comment, I don't know about Haskell or SML, but in OCaml the function I have in mind is called mod_float. Do you prefer to make it a separate function instead of just changing to type of (%)?

Contributor

imeckler commented Jan 20, 2015

In response to evancz's comment, I don't know about Haskell or SML, but in OCaml the function I have in mind is called mod_float. Do you prefer to make it a separate function instead of just changing to type of (%)?

@imeckler

This comment has been minimized.

Show comment
Hide comment
@imeckler

imeckler Feb 19, 2015

Contributor

If you need such a function, here's an elm implementation in the meantime.

modFloat : Float -> Float -> Float
modFloat x m = x - m * toFloat (floor (x/m))
Contributor

imeckler commented Feb 19, 2015

If you need such a function, here's an elm implementation in the meantime.

modFloat : Float -> Float -> Float
modFloat x m = x - m * toFloat (floor (x/m))
@evancz

This comment has been minimized.

Show comment
Hide comment
@evancz

evancz Feb 19, 2015

Member

I have reservations about using the number type too aggressively, so I'd currently be more comfortable with a separate function. I'm used to seeing it called fmod in places like C++. How this is handled in Java and C# and F#?

Member

evancz commented Feb 19, 2015

I have reservations about using the number type too aggressively, so I'd currently be more comfortable with a separate function. I'm used to seeing it called fmod in places like C++. How this is handled in Java and C# and F#?

@alexiamcdonald

This comment has been minimized.

Show comment
Hide comment
@alexiamcdonald

alexiamcdonald Jun 12, 2015

Contributor

@bjz and I ran into this the other day. What's the status of adding an fmod style function to the core library?

This is what we used:

fmod : Float -> Int -> Float
fmod f n =
  let integer = floor f
  in  toFloat (integer % n) + f - toFloat integer
Contributor

alexiamcdonald commented Jun 12, 2015

@bjz and I ran into this the other day. What's the status of adding an fmod style function to the core library?

This is what we used:

fmod : Float -> Int -> Float
fmod f n =
  let integer = floor f
  in  toFloat (integer % n) + f - toFloat integer
@mus0u

This comment has been minimized.

Show comment
Hide comment
@mus0u

mus0u Nov 10, 2015

I would also love to see an fmod function added.

mus0u commented Nov 10, 2015

I would also love to see an fmod function added.

@alexiamcdonald

This comment has been minimized.

Show comment
Hide comment
@alexiamcdonald

alexiamcdonald May 2, 2016

Contributor

I've made a library for this one function! It uses the native (%) operator though, so it would have to have a module review. Do you think it is worth it for a one-function package, or can we get this in the standard library? 😛

Contributor

alexiamcdonald commented May 2, 2016

I've made a library for this one function! It uses the native (%) operator though, so it would have to have a module review. Do you think it is worth it for a one-function package, or can we get this in the standard library? 😛

@JoshuaOSHickman

This comment has been minimized.

Show comment
Hide comment
@JoshuaOSHickman

JoshuaOSHickman Jul 26, 2016

Found myself needing this function. Not hard to write, but I was mostly just surprised there wasn't something in Basics for it.

JoshuaOSHickman commented Jul 26, 2016

Found myself needing this function. Not hard to write, but I was mostly just surprised there wasn't something in Basics for it.

@evancz

This comment has been minimized.

Show comment
Hide comment
@evancz

evancz Sep 22, 2016

Member

Consolidated all the math related stuff into the #721 meta issue. Follow along there!

Member

evancz commented Sep 22, 2016

Consolidated all the math related stuff into the #721 meta issue. Follow along there!

@evancz evancz closed this Sep 22, 2016

@jvoigtlaender jvoigtlaender referenced this issue Mar 18, 2018

Closed

floatMod #10

@jvoigtlaender

This comment has been minimized.

Show comment
Hide comment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment