Skip to content

Large-ish numbers not parsed correctly in Elm 0.18, Windows x64 #1648

Open
@ebhasker

Description

@ebhasker

This seems to be a... Parser / code gen problem

SSCCE (with core and html libraries)

import Html exposing (Html, text)
main : Html msg
main = text (toString (2^31) ++ " versus " ++ toString (2147483648))

Compiling using elm-make under Windows 10, x64, gives me the following in the resulting javascript:

var _user$project$Main$main = _elm_lang$virtual_dom$Native_VirtualDom.staticProgram(
	_elm_lang$html$Html$text(
		A2(
			_elm_lang$core$Basics_ops['++'],
			_elm_lang$core$Basics$toString(
				Math.pow(2, 31)),
			A2(
				_elm_lang$core$Basics_ops['++'],
				' versus ',
				_elm_lang$core$Basics$toString(-2147483648)))));

Note the minus sign, specifically. Suspecting a numerical overflow sort of problem.

Embedding this app and opening in any major browser shows the incorrect output:

2147483648 versus -2147483648

Note that this seems specific to the Windows version. Compiling the same example using elm-make under Linux (Ubuntu 16.04, x64 in my case) gives the javascript output:

var _user$project$Main$main = _elm_lang$virtual_dom$Native_VirtualDom.staticProgram(
	_elm_lang$html$Html$text(
		A2(
			_elm_lang$core$Basics_ops['++'],
			_elm_lang$core$Basics$toString(
				Math.pow(2, 31)),
			A2(
				_elm_lang$core$Basics_ops['++'],
				' versus ',
				_elm_lang$core$Basics$toString(2147483648)))));

Which results in the correct output:
2147483648 versus 2147483648

Note: Numbers less than 2^31 seem to not raise the issue. So hopefully this is also a min-SSCCEE (unless you count negative numbers!)

Please let me know if you need more info about my architecture (i.e. if you cannot reproduce this somehow).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions