Sujet : Re: how cast works?
De : thiago.adams (at) *nospam* gmail.com (Thiago Adams)
Groupes : comp.lang.cDate : 09. Aug 2024, 20:22:30
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v95q9m$2oa92$3@dont-email.me>
References : 1 2 3 4 5 6 7 8
User-Agent : Mozilla Thunderbird
Em 8/9/2024 4:03 PM, Keith Thompson escreveu:
Thiago Adams <thiago.adams@gmail.com> writes:
[...]
This part was always clear to me:
>
"They are not performed 'in-place', any more than writing `a + 1`
changes the value of `a`."
>
Lets take double to int.
>
In this case the bits of double needs to be reinterpreted (copied to) int.
The word "reinterpreted" usually refers to taking a given representation
(sequence of bits) and treating it as a value of a specified type
*without changing the bits*. (<OT>C++ even has "reintrepret_cast" as a
keyword.</OT>)
Converting from int to double does not reinterpret the bits. It creates
a new value that is mathematically equal (or nearly so) to the operand
value.
So the answer "how it works" can be
>
always/generally machine has a instruction to do this
>
or.. this is defined by the IIE ... standard as ...
Do you mean the IEEE standard? As always, the C standard defines the
semantics of conversions. For an implementation that claims to conform
to IEEE floating-point standard (ISO/IEC 60559), the semantics are
specified more precisely.
Yes. maybe the conversion double to int for instance, is related with truncation, and this is specified on IEEE.
The inverse int to double is similar. For instance ULLONGMAX to double.
I guess all computers languages works in the same way today because also hardware works following the floating point standards.
-- We already have many topics in one...but I am adding one more. :D _Decimal32 , _Decimal64 etc..C23 have these new types. I think it has to me emulated because it is not something implemented on hardware.C started as being something more hardware related, but now we have complex types, bool, _Decimal.. I think all these types are "emulated".