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

String.toInt returns a Float in certain circumstances #831

Closed
ChrisWellsWood opened this Issue Feb 2, 2017 · 5 comments

Comments

Projects
None yet
5 participants
@ChrisWellsWood
Contributor

ChrisWellsWood commented Feb 2, 2017

I was doing some validation on input, and noticed an odd situation when parsing strings:

> String.toInt "1"
Ok 1 : Result.Result String Int
> String.toInt "dfsf"
Err "could not convert string 'dfsf' to an Int" : Result.Result String Int
> String.toInt "-"
Ok NaN : Result.Result String Int
> String.toInt "+"
Ok NaN : Result.Result String Int

But the type of NaN is Float, not Int. I've not found any other circumstances where this occurs yet. I have a work around where I catch it manually, but I have to use toFloat on it first in order to use isNaN.

I'm using Elm 0.18, on FireFox and Elm repl. Thanks!

@process-bot

This comment has been minimized.

Show comment
Hide comment
@process-bot

process-bot Feb 2, 2017

Thanks for the issue! Make sure it satisfies this checklist. My human colleagues will appreciate it!

Here is what to expect next, and if anyone wants to comment, keep these things in mind.

process-bot commented Feb 2, 2017

Thanks for the issue! Make sure it satisfies this checklist. My human colleagues will appreciate it!

Here is what to expect next, and if anyone wants to comment, keep these things in mind.

@jvoigtlaender

This comment has been minimized.

Show comment
Hide comment
@jvoigtlaender

jvoigtlaender Feb 2, 2017

Contributor

There do exist other operations in current Elm that produce NaN despite being typed Int. See https://github.com/elm-lang/core/issues/590, covered in https://github.com/elm-lang/core/issues/721.

Also, it would be pretty important that you not only specify which version of Elm you use, but also which version of the core library you use. Because the implementation of String.toInt was recently changed, see https://github.com/elm-lang/core/releases/tag/5.1.0.

Contributor

jvoigtlaender commented Feb 2, 2017

There do exist other operations in current Elm that produce NaN despite being typed Int. See https://github.com/elm-lang/core/issues/590, covered in https://github.com/elm-lang/core/issues/721.

Also, it would be pretty important that you not only specify which version of Elm you use, but also which version of the core library you use. Because the implementation of String.toInt was recently changed, see https://github.com/elm-lang/core/releases/tag/5.1.0.

@mgold

This comment has been minimized.

Show comment
Hide comment
@mgold

mgold Feb 3, 2017

Contributor

This issue reproduces in 0.18.0/5.1.1.

Contributor

mgold commented Feb 3, 2017

This issue reproduces in 0.18.0/5.1.1.

@ChrisWellsWood

This comment has been minimized.

Show comment
Hide comment
@ChrisWellsWood

ChrisWellsWood Feb 3, 2017

Contributor

Yeah, I'm using Elm 0.18 and elm-core 5.1.1.

Contributor

ChrisWellsWood commented Feb 3, 2017

Yeah, I'm using Elm 0.18 and elm-core 5.1.1.

@evancz

This comment has been minimized.

Show comment
Hide comment
@evancz

evancz Mar 26, 2017

Member

Fixed by OP in #834

Member

evancz commented Mar 26, 2017

Fixed by OP in #834

@evancz evancz closed this Mar 26, 2017

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