Navigation

Operators and Keywords

Function List:

C++ API

Function File: [macheps, round, machepsb, roundb] = fetestenv ()

Check some properties of floating point arithmetics: the rounding mode and the machine epsilon, as seen by Octave's interpreted code (round and macheps, respectively) and, if requested, as seen by BLAS (roundb and machepsb, respectively).

The function performs a variant of the standard

          1 + macheps ~= 1

test in order to check the actual machine epsilon macheps and the present rounding mode round used in all interpreted expressions in Octave.

As Octave interpreted code cannot achieve more than double precision, and some BLAS implementations may impose their internal precision and rounding modes, the user may request to check the actual rounding and precision used in BLAS calls. To this end, we perform a machine epsilon/rounding mode check of the form

          [1, machepsb, -1]*[1; 1; 1] ~= 0.

This Octave code results in a call to a BLAS routine, which in turn may use different floating point arithmetic settings than available to Octave. Rounding mode and machine epsilon (both as seen by BLAS) are returned in roundb and machepsb, respectively.

See the manual pages of fesetprec for more details and subtleties.

Note that the results of this test may or may not apply to library functions called by Octave. The simplest way to verify if the function you use in Octave is affected by the change of the rounding mode or the precision, is to run your function on the same data with different settings. Small differences between various modes indicate these modes do affect the behaviour of your function. No differences mean they probably do not apply. Big differences most likely indicate either an instability of your function or ill conditioning of your problem.

Demonstration 1

The following code

  fesetround(+Inf); fesetprec(1);
  fetestenv();
  fesetround(0.5); fesetprec(3);

Produces the following output

Interpreter:
	Machine epsilon: 1.19209e-07
	Rounding mode:   Inf
BLAS:
	Machine epsilon: 1.19209e-07
	Rounding mode:   Inf

Demonstration 2

The following code

  fesetround(0); fesetprec(3);
  fetestenv();
  fesetround(0.5); fesetprec(3);

Produces the following output

Interpreter:
	Machine epsilon: 2.22045e-16
	Rounding mode:   0
BLAS:
	Machine epsilon: 1.0842e-19
	Rounding mode:   0