fabien van mook

all packages "fvm-*"

package "fvm-real2text"

function file "real2text_sprintf.m"

Function rt = real2text_sprintf(rt)

returns the struct after the insertion of 
text representations of finite reals, which 
are obtained by function sprintf().

The input struct rt must have the following fields:
  rt.data     (vectorised input as a one-dimensional 
               cell-array)
  rt.realtype (vector of integers classifying each 
               element in rt.data with 
               value 0 for a non-real,
               value 1 for a finite real, and
               values 2...5 for non-finite reals 
               -Inf, +Inf, NaN and NA, respectively)

The input struct rt may have the following optional 
fields:
  rt.precision (integer >= 0)
  rt.template  (string with the sprintf-template)

The output struc rt contains new or renewed fields:
  rt.precision (integer >= 0)
  rt.data      (vectorised input as a one-dimensional 
                cell-array, in which each finite real
                has been replaced by a string)

If the field rt.precision is not input, it is 
automatically defined and set to 3.

If rt.template contains a non-empty string, this
string will be used as an sprintf-template to 
produce text representations of the finite reals
in rt.data. In this case, one may input rt.precision
too, just to indicate an "undefined precision" by
rt.precision == 0, or a "defined precision" by 
rt.precision > 0.

If the field rt.template is not input or is empty,
an sprintf-template is automatically generated 
based on the information in rt.precision: 
-- If rt.precision == 0, the reals will be
   represented by 12 (significant) digits.
-- If rt.precision > 0, the reals will be 
   represented by the indicated number of 
   significant digits.

with the output, the "definedness of the precision"
is determined just by the logical operation
rt.precision != 0, and has implications in 
the functions real2text_decompose() and 
real2text_simplify().

Alternatively, the sprintf-template may be
input by rt.precision. In that case, 1
"defined precision" will be assumed by
functions real2text_decompose() and 
real2text_simplify().

The possible maximal precision depends on the 
internal data type. See e.g.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray
-- Float32Array: 
     1.2*10^-38 to 3.4*10^38
     4 bytes
     32-bit IEEE floating point number
     7 significant digits e.g., 1.234567
-- Float64Array: 
     5.0*10^-324 to 1.8*10^308
     8 bytes
     64-bit IEEE floating point number 
     16 significant digits e.g., 1.23456789012345

Note that the first significant digit is counted
for the functions real2text_xxx(); e.g. 1.2 as well 
as 0.12 have a number of 2 significant digits!


(c) 2026 fabien van mook

2026.08.20 release of this file within package "fvm-real2text" under GNU GPLv3+