# Unexpected result using float variables #159

Closed
opened this Issue Apr 10, 2017 · 5 comments

Projects
None yet
4 participants

### feserafim commented Apr 10, 2017

 Hello, I'm getting an unexpected result for the following example: ``````var 0.0..100.0: a; var 0.0..100.0: b; constraint (a > 94.0 /\ b > 94.0) /\ (a > b); solve minimize b; `````` Result: ``````a = 95.0; b = 95.0; ---------- ========== `````` Why am I getting that result since `(a > b)` is set in the constraint? By the way, I'm using the MiniZinc IDE for the execution and the solver is set on "Gecode (bundled)". Thanks in advance.

### a1880 commented Apr 10, 2017

 I tried to uncover some rounding problems and modified the example: ``````float: k = 1e300; var 0.0..100.0: a; var 0.0..100.0: b; constraint (a > 94.0 /\ b > 94.0) /\ (a > b); solve minimize b; output ["\na = " ++ show(k * a) ++ "\nb = " ++ show(k * b) ++ "\na - b = " ++ show(k * (a-b))]; `````` The output is: ``````a = 9.500000000000001e+301 b = 9.500000000000001e+301 a - b = 0.0 ---------- ========== ``````
Member

### Dekker1 commented Oct 4, 2017

 This bug seems to be caused by a faulty internal transformation. The resulting FlatZinc for this model is: ``````array [1..2] of float: X_INTRODUCED_0_ = [-1.0,1.0]; var 95.0..100.0: a:: output_var; var 95.0..100.0: b:: output_var; constraint float_lin_lt(X_INTRODUCED_0_,[a,b],0.0); solve minimize b; ``````

### guidotack added a commit that referenced this issue Oct 6, 2017

``` Fix incorrect simplification of float domain constraints. Fixes #159. ```
``` a7b4034 ```
Member

### guidotack commented Oct 6, 2017

 The incorrect simplification (changing the bound to 95.0) is now fixed in the compiler. The fact that a>b is violated is a bug in Gecode, not in MiniZinc (I will close this bug here and report it for Gecode).

### feserafim commented Oct 20, 2017

 I have just updated MiniZinc IDE (bundled) newest version (2.1.6) and executed ``````\$ path/to/mzn2fzn.exe my-example.mzn `````` but I am still getting the same result as @Dekker1. Am I doing anything wrong?
Member

### Dekker1 commented Oct 20, 2017 • edited

 Hello @feserafim, Although Guido managed to fix the flattening bug, the fix has only been implemented on the development branch. (We haven't released any new versions since the bug was fixed). This is also the reason that the issue is still open. If you are still experiencing problems and you can't wait until the next release, then you might want to try to compile the `develop` branch and use that `mzn2fzn` binary. The problem should be fully fixed on that branch. (Although the problem in Gecode is a different issue as Guido mentioned)