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 random module regression #11198

Closed
mratsim opened this issue May 8, 2019 · 2 comments · Fixed by #11199
Closed

Floating point random module regression #11198

mratsim opened this issue May 8, 2019 · 2 comments · Fixed by #11199

Comments

@mratsim
Copy link
Collaborator

mratsim commented May 8, 2019

This works on 0.19.4 but doesn't on devel

import random
echo rand(-0.1..0.1)

Error is:

Error: type mismatch: got <HSlice[system.float, system.float64]>
but expected one of: 
proc rand(max: int): int
proc rand[T: Ordinal](x: HSlice[T, T]): T
proc rand(r: var Rand; max: Natural): int
proc rand[T](r: var Rand; a: openArray[T]): T
proc rand(max: float): float
proc rand[T: SomeInteger](t: typedesc[T]): T
proc rand(r: var Rand; max: range[0.0 .. high(float)]): float
proc rand[T](a: openArray[T]): T
proc rand[T: Ordinal](r: var Rand; x: HSlice[T, T]): T

expression: rand(-0.1 .. 0.1)
@GULPF
Copy link
Member

GULPF commented May 8, 2019

Caused by 9f94199 I think, not a semcheck issue. Ping @narimiran

@mratsim
Copy link
Collaborator Author

mratsim commented May 8, 2019

Looking again it's not the slice, I thought for 1 moment that float and float64 were not aliases anymore.

The issue is the new Ordinal requirement: #10998 which was introduced to fix #7698 (allow rand on enums).

We probably need an overload just for floats.

This reminds of Rust that has a Ord trait for ordinal types with equality cleanly defined and PartialOrd trait for types like floats that are usually ordinal except for specific values (NaN is not equal to itself).

@mratsim mratsim changed the title Floating point slice regression Floating point random module regression May 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants