Re: Strange double to uint conversion

2019-11-19 Thread Luiz Silveira via Digitalmars-d-learn
On Monday, 18 November 2019 at 21:54:53 UTC, Steven Schveighoffer wrote: You are expecting floating point to behave as if it is stored as a decimal number. It's not. I was actually asking why 'c' and 'c2' functions behave differently. After mipri's answer I learned that the default floating

Re: Strange double to uint conversion

2019-11-18 Thread Steven Schveighoffer via Digitalmars-d-learn
On 11/18/19 4:54 PM, Steven Schveighoffer wrote: What you may want to do is use std.math.ceil. Sorry, what you want is std.math.round. -Steve

Re: Strange double to uint conversion

2019-11-18 Thread Steven Schveighoffer via Digitalmars-d-learn
On 11/18/19 4:08 PM, Luiz Silveira wrote: Hello, everyone!   I'm a new D fan, still learning the language and this is my first post.   I came up with a strange behavior, using D 2.089 for windows.   Considering the program "error.d": import std.stdio; import std.conv; void main() {  

Re: Strange double to uint conversion

2019-11-18 Thread Luiz Silveira via Digitalmars-d-learn
On Monday, 18 November 2019 at 21:14:37 UTC, mipri wrote: double f; If this is changed to `real f;`, you get the desired result. real is also the type used for the comparison code: https://dlang.org/spec/float.html#fp_const_folding Yes, it worked as expected. Thank you, Luiz.

Re: Strange double to uint conversion

2019-11-18 Thread mipri via Digitalmars-d-learn
On Monday, 18 November 2019 at 21:08:39 UTC, Luiz Silveira wrote: double f; If this is changed to `real f;`, you get the desired result. real is also the type used for the comparison code: https://dlang.org/spec/float.html#fp_const_folding

Strange double to uint conversion

2019-11-18 Thread Luiz Silveira via Digitalmars-d-learn
Hello, everyone! I'm a new D fan, still learning the language and this is my first post. I came up with a strange behavior, using D 2.089 for windows. Considering the program "error.d": import std.stdio; import std.conv; void main() { uint c(double v) { return