V: Operation "int % float" gives bugs

Created on 6 Nov 2019  路  5Comments  路  Source: vlang/v

V version:
V playground

OS:
N/A

What did you do?

fn main() {
    println(3%1.2)
} 

What did you expect to see?
An error
Or a result (eg, in Python)

What did you see instead?
You just found a bug. V can't compile this program, but it should. Please create a GitHub issue.

Bug

Most helpful comment

Fixed.

All 5 comments

@SleepyRoy actually for floating-point remainder you need math.fmod(3, 1.2).

@LorenzoPirro Thanks. So I think "3%1.2" should simply gives an error (actually "1.2%3" is handled correctly). Also it might be better that the compiler gives a suggestion of turning to the math module. @medvednikov

@SleepyRoy you're welcome! Yes could be useful

Yes, that has to be fixed. I noticed the error is not cought by V compiler only when you use the literal on the right-hand side. If you assign it to the variable first then try % it gives you an error as expected. Somebody will fix it. Thanks for the issue.

Fixed.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

clpo13 picture clpo13  路  3Comments

medvednikov picture medvednikov  路  3Comments

oleg-kachan picture oleg-kachan  路  3Comments

markgraydev picture markgraydev  路  3Comments

jtkirkpatrick picture jtkirkpatrick  路  3Comments