How to disable implicit convert float to int.

2022-05-31 Thread slangmgh
Your are right! The assembler code generate by c compiler with simple object wrapper is almost same with the plain int.

How to disable implicit convert float to int.

2022-05-31 Thread slangmgh
It is `distinct int` and `float`, not with `int`.

How to disable implicit convert float to int.

2022-05-31 Thread Yardanico
`distinct` would perform the same as an object/tuple with a single element if you compile with optimizations. Convertsions between `distinct T` and `T` are fundamental, I don't see why would you want to disallow them.

How to disable implicit convert float to int.

2022-05-31 Thread slangmgh
Use `distinct` for performance, disable `Price(3.6)` for safety.

How to disable implicit convert float to int.

2022-05-31 Thread Yardanico
I'm not sure if what you want is achievable with `distinct`, but as a workaround you can just make it a normal `object`, which would be better since you don't want to allow your user to directly convert from/to Price and int.

How to disable implicit convert float to int.

2022-05-31 Thread slangmgh
I hope I can find way to prevent the code like this: proc Price(x: float) {.error.} Run But this doesn't compile.

How to disable implicit convert float to int.

2022-05-31 Thread slangmgh
But this code compiles fine. type Price = distinct int var f = 3.6 var p = Price(f) echo p # 3, rather than 4 Run This is what I want to avoid.

How to disable implicit convert float to int.

2022-05-31 Thread Araq
There is no need to disable the conversion as it's only done for _literals_ anyway. This means that this does **not** compile: proc takesFloat(x: float) = discard var i = 44 takesFloat(i) Run

How to disable implicit convert float to int.

2022-05-31 Thread slangmgh
Look at the following code. type Price = distinct int converter float_to_price(x: float): Price = x.toInt.Price let x = 3.6 let y = Price(x) # y = 3, I want to disable it let z: Price = x # z = 4, correct Run