Re: floating point conversion

2014-06-01 Thread Famous via Digitalmars-d-learn
On Sunday, 1 June 2014 at 12:45:26 UTC, bearophile wrote: It's a bad question. Actually, Martin's question is a good one. Initializing a variable of type float via a literal or as conversion from string should be the same, exacly, always. Casting a float to double should be deterministic as

Re: floating point conversion

2014-06-01 Thread Famous via Digitalmars-d-learn
float a = 1.234f; float b = to!float("1.234"); assert (a == b); assert (a == to!float("1.234")); // is allowed to fail due to constant folding

Re: floating point conversion

2014-06-01 Thread Famous via Digitalmars-d-learn
On Sunday, 1 June 2014 at 15:31:53 UTC, Martin Krejcirik wrote: On 1.6.2014 16:42, Famous wrote: from string should be the same, exacly, always. Casting a float to double should be deterministic as well. void main() { float a = 1.234f; double b = 1.234; assert (a == cast(float) b)

Re: floating point conversion

2014-06-01 Thread Famous via Digitalmars-d-learn
I have compiled some cases at http://dpaste.dzfl.pl/5611b8bce8e3 This implies that floating-point constants do not have fixed but minimum precision. Particularly, the literal 1.23 describes a floating-point value with either double or real precision depending on what it is compared to. Thi