2 (*
3 * Purpose:
4 * Provides REAL/string conversions
5 *
6 * Log:
7 * April 96 jl initial version
8 *
9 * Notes:
10 * Complies with ISO/IEC 10514-1:1996 (as RealStr)
11 *
12 * Modified for Component Pascal by kjg, February 2004
13 *
14 *)
18 (***************************************************************)
19 (* *)
20 (* PRIVATE - NOT EXPORTED *)
21 (* *)
22 (***************************************************************)
24 CONST
27 TYPE
31 (*===============================================================*)
35 BEGIN
43 (*===============================================================*)
46 BEGIN
54 (*===============================================================*)
59 BEGIN
63 (*===============================================================*)
69 BEGIN
75 ELSE
90 (*===============================================================*)
103 BEGIN
104 (*
105 * We want to assert that digit[0] # "0",
106 * unless real = zero. So to avoid a sack o'woe
107 *)
118 (* get optional sign *)
127 (* get integer part *)
137 (* count any leading zeros *)
151 (* get fractional part *)
156 ELSE
168 (* At this point, if we are not ended, we have a NaN *)
171 ELSE
172 (* Index of virtual decimal point is eVal + iLen *)
178 (***************************************************************)
186 BEGIN
194 ELSE
201 LOOP
204 ELSE
218 (***************************************************************)
219 (* *)
220 (* PUBLIC - EXPORTED *)
221 (* *)
222 (***************************************************************)
224 (*===============================================================*
225 *
226 * Ignores any leading spaces in str. If the subsequent characters in str
227 * are in the format of a signed real number, assigns a corresponding value
228 * to real. Assigns a value indicating the format of str to res.
229 *)
235 BEGIN
240 (*===============================================================*
241 *
242 * Converts the value of real to floating-point string form, with sigFigs
243 * significant digits, and copies the possibly truncated result to str.
244 *)
253 BEGIN
264 ELSE
274 (*
275 * IF dExp # 0 THEN CopyExp(dExp,index,str) END;
276 *)
281 (*===============================================================*
282 *
283 * Converts the value of real to floating-point string form, with sigFigs
284 * significant digits, and copies the possibly truncated result to str.
285 * The number is scaled with one to three digits in the whole number part and
286 * with an exponent that is a multiple of three.
287 *)
296 BEGIN
310 ELSE
320 ELSE
325 (*
326 * IF dExp # 0 THEN CopyExp(dExp,index,str) END;
327 *)
332 (*===============================================================*
333 *
334 * Converts the value of real to fixed-point string form, rounded to the
335 * given place relative to the decimal point, and copies the result to str.
336 *)
353 BEGIN
354 (* the decimal point and fraction part *)
355 (* ["-"] "0" "." d^(fWid) -- if dExp < 0 *)
356 (* ["-"] d^(lWid) "." d^(fWid) -- if fWid > 0 *)
357 (* ["-"] d^(lWid) -- if fWid = 0 *)
369 (* Semantics of dExp value *)
370 (* 012345 ... digit index *)
371 (* dddddd ... digit content *)
372 (* ^-------- dExp value *)
373 (* "ddd.ddd..." result str. *)
387 (*
388 * Now copy the optional signe
389 *)
391 (*
392 * Now copy the integer part
393 *)
396 ELSE
399 ELSE
406 (*
407 * Now copy the fractional part
408 *)
412 (* 012345 ... digit idx *)
413 (* dddddd ... digit str. *)
414 (* ^-------- dExp = -1 *)
426 (*===============================================================*
427 *
428 * Converts the value of real as RealToFixed if the sign and magnitude can be
429 * shown within the capacity of str, or otherwise as RealToFloat, and copies
430 * the possibly truncated result to str.
431 * The number of places or significant digits are implementation-defined.
432 *)
434 BEGIN
440 (* ---------------------------------------- *)