Calculation using IEEE 754 single precision format

J

JF

Hi,

Is there a way to force calculation included in an Excel sheet to use
IEEE 754 single precision format?

What is the simpler solution to do this?

Thank you by advance for your answers.
 
J

joeu2004

JF said:
Is there a way to force calculation included in an
Excel sheet to use IEEE 754 single precision format?

I have experimented extensively over the years, and AFAIK, the answer is
"no".


JF said:
What is the simpler solution to do this?

Do your calculations in VBA, where you declare variables Single instead of
Double.

But caveat: VBA tries to keep intermediate calculations in the 80-bit
floating-point registers of the FPU. In that context, your requirement is
unclear.

For example:

Dim x as Single, y as Single, z as Single
x = 1.1
y = 2.2
z = 3.3
x = x + y + z

The expression x+y+z will be computed with 80-bit precision, then rounded to
single precision.

If that is acceptable, fine. Otherwise you would need to code complex
expressions carefully. For example:

x = x + y
x = x + z

Of course, even then, x+y is computed with 80-bit precision. But there is
nothing you can do about that.

(Note: My constants and arithmetic operations might not be a good example
because it might not make any difference in that case. But hopefully it is
sufficient to understand what I mean conceptually.)

As an alternative, it is possible to call a C++ DLL routine that causes the
FPU to round pairwise operations to single precision. However, VBA resets
to its default each time we exit VBA back to Excel. So you have to call the
DLL routine from each VBA procedure that might be called from Excel.

Moreover, it appears that some other computer languages set the FPU rounding
state to conform to their own requirements; for example, Fortran DLL
routines. So it is ill-advised to rely on what you set in a C++ DLL
routine.
 
J

joeu2004

PS.... I said:
I have experimented extensively over the years, and AFAIK, the answer is
"no".




Do your calculations in VBA, where you declare variables Single instead of
Double.

Why do you care? That is, what are you really trying to achieve, for which
you __think__ it is advantageous to use single-precision arithmetic?

If we can step back and understand your "big picture" problem, perhaps there
is a better alternative.
 
J

JF

In fact, the need I have is to simulate the behaviour of an equipment
which performs some calculations (that could be reproduced through an
Excel sheet) and uses IEEE 754 single precision floating point.

My idea was to use Excel for this. The use of Excel to reproduce
calculations is convenient but for the simulation to be realistic, all
calculations must be done with IEEE 754 single precision format. If
some intermediate calculations are done with 80-bit precision, the
result in Excel should not be represntative of the calculations made by
the real equipment.

If I can't find a solution with Excel I will write a specific
application in another language.

Thank you for your help and for the details on VBA.
 
J

joeu2004

JF said:
If some intermediate calculations are done with 80-bit
precision, the result in Excel should not be represntative
of the calculations made by the real equipment.

If I can't find a solution with Excel I will write a
specific application in another language.

My assertion that all pairwise operations are calculated with 80-bit
precision, even when using VBA type Single, is based on an assumption that
you are using the native computer arithmetic instructions of an
Intel-compatible CPU.

This would be true of any computer language that uses the native computer
arithmetic instructions of an Intel-compatible CPU, e.g. Fortran and C++.

Unless you are talking about implementing the standard 32-bit binary
floating-point operations in software yourself (or finding an existing
software implementation).

Good luck with that!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top