So why double to float conversion is implicit ?
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Tue Oct 24 17:54:55 UTC 2017
On 10/24/2017 12:28 PM, Fool wrote:
> On Tuesday, 24 October 2017 at 14:28:20 UTC, Basile B. wrote:
>> float f0 = cos(2 * PI / 1.123548789545545646452154L);
>> float f1 = cos(cast(float)(2 * PI / 1.123548789545545646452154L));
>>
>> [...]
>>
>> but paradoxically the first is more accurate.
>
> There is no paradox. That's comparing apples with oranges. No offense.
>
> @all: It is sad to see how parts of the community are losing their
> distance to the project and even put a gloss on completely absurd design
> decisions.
For the record, I remember the points made:
* When converting across integral types, any failed coercion yields a
value essentially unrelated to the source. So we deemed these unacceptable.
* When converting int to float or long to double, there is a loss of
accuracy - a float can represent all ints, but some of them will be
represented with approximation. But here there _is_ a notion of "I'm
okay with an approximation". So we deemed these acceptable.
* When converting double to float, again there is a loss of accuracy and
also the risk of too large values. But there's never a gross mistake -
too large values are converted to infinity, and otherwise an
approximation occurs. This was also deemed acceptable.
Folks with other design sensibilities might choose differently. Actually
I wasn't on board with this decision, but I accepted it. But deeming it
absurd is a bit of a stretch.
Andrei
More information about the Digitalmars-d
mailing list