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

floating point bounds not as expected #1310

Closed
danschan opened this issue Oct 19, 2021 · 7 comments
Closed

floating point bounds not as expected #1310

danschan opened this issue Oct 19, 2021 · 7 comments

Comments

@danschan
Copy link

What version of CUE are you using (cue version)?

$ cue version 0.4.0 windows/amd64

Does this issue reproduce with the latest release?

yes

What did you do?

evaluated

foo: {
	"value": >=2.1 & <=1.0
}

What did you expect to see?

foo.value: incompatible bounds >=2.1 and <=1.0

What did you see instead?

foo: {
    value: >=2.1 & <=1.0
}
@danschan danschan added NeedsInvestigation Triage Requires triage/attention labels Oct 19, 2021
@verdverm
Copy link

verdverm commented Oct 19, 2021

Are you trying to say it must be outside of (1.0,2.1)?

What you have wrote is that it must be both >=2.1 and <=1.0 at the same time.

You may be looking for value: >=2.1 | <= 1.0 (a disjunction, of which only one should be valid)

@danschan
Copy link
Author

This is only an example for the issue.

If I evaluate ">=2.1 & <=1.1" or ">=2 & <=1" at the same time, cue correctly reports an error. For ">=2.1 & <=1.0" not.

Originally my values were derrived from multiple schemes, but this example reproduces the behaviour in the most simple way.

@verdverm
Copy link

verdverm commented Oct 19, 2021

Ah, this same unreported error happens for >=number & <= int (>=2.1 & <=1)

I have a hunch this has to do with mixed type comparison (number vs int) and that 1.0 is probably converted to 1 as an int rather than a decimal

@verdverm
Copy link

Also, just as an FYI, cue uses an arbitrary precision decimal and not floating point.

https://pkg.go.dev/cuelang.org/[email protected]/internal/core/adt#Num

(the comment there looks to confirm 1.0 is really seen as 1 the int)

@mpvl mpvl added NeedsFix and removed NeedsInvestigation Triage Requires triage/attention labels Oct 21, 2021
@mpvl
Copy link
Member

mpvl commented Oct 21, 2021

Interesting. Should be easy to fix.

@mpvl mpvl added this to the v0.4.x milestone Oct 26, 2021
@antong
Copy link
Contributor

antong commented Oct 27, 2021

I think the bug is around:

switch diff, err := d.Int64(); {

Decimal d.Int64() returns an error if d is not an integer, and SimplifyBounds returns nil. So if the difference between the high and low bound is not integral, then simplification is not done for floats.

>=22.1 & <2.0 // >=22.1 & <2.0
>=22.1 & <2.1 // _|_ incompatible bounds >=22.1 and <2.1
>=22   & <2.0 // _|_ incompatible bounds >=22 and <2.0

@mpvl
Copy link
Member

mpvl commented Nov 14, 2021

@antong: the bug was indeed in that switch statement.

@mpvl mpvl modified the milestones: v0.4.x, v0.4.1: bug fixes Nov 14, 2021
cueckoo pushed a commit that referenced this issue Nov 15, 2021
Equal case was not checked for floats.

Fixes #1310

Signed-off-by: Marcel van Lohuizen <[email protected]>

Change-Id: Icd5d2aba5080fae3b42a4abd5544ca4c579f29c6
Signed-off-by: Marcel van Lohuizen <[email protected]>
cueckoo pushed a commit that referenced this issue Nov 17, 2021
Equal case was not checked for floats.

Fixes #1310

Signed-off-by: Marcel van Lohuizen <[email protected]>

Change-Id: Icd5d2aba5080fae3b42a4abd5544ca4c579f29c6
Signed-off-by: Marcel van Lohuizen <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants