Skip to content
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

Problem with floating-point exponent #690

Closed
ptal opened this issue May 3, 2023 · 1 comment
Closed

Problem with floating-point exponent #690

ptal opened this issue May 3, 2023 · 1 comment
Labels
bug resolved Issue is resolved and the feature or fix will be part of next release

Comments

@ptal
Copy link

ptal commented May 3, 2023

"Exported" from Gecode/gecode#164 with further analysis of the issue.

The .mzn:

float: x;
var float: y;
constraint x > y;

The .dzn:

 x = 2.0e-5;

The error:

  File "/home/ptalbot/.local/lib/python3.10/site-packages/minizinc/instance.py", line 100, in __init__
    self.analyse()
  File "/home/ptalbot/.local/lib/python3.10/site-packages/minizinc/instance.py", line 584, in analyse
    output = self._driver._run(["--model-interface-only"] + files, self._solver)
  File "/home/ptalbot/.local/lib/python3.10/site-packages/minizinc/driver.py", line 232, in _run
    for _ in decode_json_stream(output.stdout):
  File "/home/ptalbot/.local/lib/python3.10/site-packages/minizinc/json.py", line 90, in decode_json_stream
    raise error_from_stream_obj(obj)
minizinc.error.MiniZincError: unexpected token `e'

I checked the definition of the grammar but I didn't find anything wrong, and I don't think it's relevant to the grammar actually.

  • When I try with x = 2.0e-4 it works.
  • When I try with x = 0.000000003125; it doesn't work and gives the same error about the e syntax.

I run the latest version 0.9.0 and MiniZinc 2.7.3

@Dekker1
Copy link
Member

Dekker1 commented May 3, 2023

This problem occurs because the JSON parser in MiniZinc does not correctly parse floating point literals.

A minimal example is to only declare x:

float: x;

and use the following JSON data file:

{ "x": 2e-5 }

Since your data file is already in DZN format the easy workaround is to not have MiniZinc Python parse the data.

I will move this issue to the compiler repository, and solve it.

@Dekker1 Dekker1 transferred this issue from MiniZinc/minizinc-python May 3, 2023
@Dekker1 Dekker1 added the bug label May 4, 2023
guidotack pushed a commit that referenced this issue May 4, 2023
@Dekker1 Dekker1 added the resolved Issue is resolved and the feature or fix will be part of next release label May 4, 2023
@ptal ptal closed this as completed May 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug resolved Issue is resolved and the feature or fix will be part of next release
Projects
None yet
Development

No branches or pull requests

2 participants