Optimization: principles and algorithms, by Michel Bierlaire
machineEpsilon.m
Go to the documentation of this file.
1 %> \file
2 %> Algorithm 7.1: calculation of the machine epsilon. Implementation of algorithm 7.2 of \cite Bier15-book
3 %>
4 %> @author <a href="http://people.epfl.ch/michel.bierlaire">Michel Bierlaire</a>
5 %> @date Fri Mar 20 10:27:04 2015
6 %> @ingroup Algorithms
7 %> @ingroup chap07
8 
9 %> @note Tested with \ref runMachineEpsilon.m
10 
11 %> Calculate the machine epsilon in single and double precision
12 %> @return epss: single precision
13 %> @return epsd: double precision
14 function [epss, epsd] = machineEpsilon()
15  epss = single(1.0) ;
16  while (epss + 1.0 != 1.0)
17  epss /= 2.0 ;
18  endwhile
19 
20  epsd = double(1.0) ;
21  while (epsd + 1.0 != 1.0)
22  epsd /= 2.0 ;
23  endwhile
24 endfunction
25 
function machineEpsilon()
Calculate the machine epsilon in single and double precision.
Copyright 2015-2018 Michel Bierlaire