A
A
Anton Fedoryan2015-09-17 08:23:56
Algorithms
Anton Fedoryan, 2015-09-17 08:23:56

Algorithm for converting a real number to single precision?

Please tell me the algorithm for converting a real number (floating point) from double precision (64 bits) to single precision (32 bits).

Answer the question

In order to leave comments, you need to log in

2 answer(s)
J
jcmvbkbc, 2015-09-17
@AnnTHony

Something like this can be done:
Links:
[1] https://en.wikipedia.org/wiki/Single-precision_flo...
[2] https://en.wikipedia.org/wiki/Double-precision_flo...
[3] https:/ /en.wikipedia.org/wiki/IEEE_floating_point#...

A
Armenian Radio, 2015-09-17
@gbg

But simply. Take a C++ compiler, send something like

volatile double a;
cin >> a;
volatile float b=a;

Then compile it into an assembler listing (gcc has the -S switch) and see what happens.
On modern processors, this is done by the CVTSD2SS instruction.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question