1function C = eps (G)
2%EPS spacing of numbers in a GraphBLAS matrix.
3% C = eps (G) returns the spacing of numbers in a floating-point GraphBLAS
4% matrix.
5%
6% See also GrB/isfloat, realmax, realmin.
7
8% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved.
9% SPDX-License-Identifier: GPL-3.0-or-later
10
11% FUTURE: GraphBLAS should have a built-in unary operator to
12% compute eps.
13
14% convert to a MATLAB full matrix and use the MATLAB eps:
15
16% FUTURE: there should be a sparse version of 'eps'.  C is full because
17% eps (0) is 2^(-1024).
18
19switch (GrB.type (G))
20
21    case { 'single' }
22        C = GrB (eps (single (full (G)))) ;
23
24    case { 'double' }
25        C = GrB (eps (double (full (G)))) ;
26
27    case { 'single complex' }
28        C = max (eps (single (real (G))), eps (single (imag (G)))) ;
29
30    case { 'double complex' }
31        C = max (eps (double (real (G))), eps (double (imag (G)))) ;
32
33    otherwise
34        error ('input must be floating-point') ;
35
36end
37
38