BigMan wrote:

How can I check if assignment of a float to a double (or vice versa)

will result in loss of precision?

You probably mean accuracy.

In the typical implementation,

double precision is more precise that single [float] precision

so conversion from double to float *always* reduces precision

and conversion from float to double *always* increases precision.

Accuracy depends upon the number of significant digits [bits].

If all of the significant digits can be represented accurately

by type float, then accuracy will be maintained in the conversion

from double to float. If conversion from double to float

causes significant digits to be discarded,

the resulting inaccuracy may cause trouble.

You may be concerned about whether the conversion is *exact* or not.

IEEE floating-point specifies signals for inexact arithmetic

and you may be able trap an inexact conversion.

Consult you man pages for signal

SIGNAL(2) Linux Programmer’s Manual SIGNAL(2)

NAME

signal - ANSI C signal handling

SYNOPSIS

#include <signal.h>

typedef void (*sighandler_t)(int);

sighandler_t signal(int signum, sighandler_t handler);

and look for

SIGFPE

Some C++ compilers have options

for trapping inexact floating-point operations

but they probably won't help you much

because most floating-point operations are inexact.