note description: "Formatter for non-integral numbers" library: "Free implementation of ELKS library" status: "See notice at end of class." legal: "See notice at end of class." names: format_double date: "$Date: 2016-12-05 17:39:47 +0000 (Mon, 05 Dec 2016) $" revision: "$Revision: 99631 $" class FORMAT_DOUBLE create make feature -- Initialization make (w, d: INTEGER_32) require reasonable_field: w >= 1 reasonable_decimals: d <= w do set_defaults (w) decimals := d decimal := '.' trailing_zeros_shown := True ensure blank_fill: fill_character = ' ' show_sign_negative: show_sign_negative no_separator: no_separator width_set: width = w right_justified: right_justified leading_sign: leading_sign decimals_set: decimals = d decimal_point: decimal = '.' trailing_zeros_shown: trailing_zeros_shown end set_defaults (w: INTEGER_32) -- (from FORMAT_INTEGER) require -- from FORMAT_INTEGER reasonable_field: w >= 1 do blank_fill width := w sign_normal sign_negative_only right_justify ensure -- from FORMAT_INTEGER blank_fill: fill_character = ' ' show_sign_negative: show_sign_negative no_separator: no_separator width_set: width = w right_justified: right_justified leading_sign: leading_sign end feature {NONE} -- Initialization default_create -- Process instances of classes with no creation clause. -- (Default: do nothing.) -- (from ANY) do end feature -- Access after_decimal_separate: BOOLEAN -- Use separators after the decimal? arc_cosine (v: REAL_64): REAL_64 -- Trigonometric arccosine of radian v -- in the range [0, pi]. -- (from DOUBLE_MATH) external "C signature (double): double use <math.h>" alias "acos" ensure -- from DOUBLE_MATH instance_free: class end arc_sine (v: REAL_64): REAL_64 -- Trigonometric arcsine of radian v -- in the range [-pi/2, +pi/2]. -- (from DOUBLE_MATH) external "C signature (double): double use <math.h>" alias "asin" ensure -- from DOUBLE_MATH instance_free: class end arc_tangent (v: REAL_64): REAL_64 -- Trigonometric arctangent of radian v -- in the range [-pi/2, +pi/2]. -- (from DOUBLE_MATH) external "C signature (double): double use <math.h>" alias "atan" ensure -- from DOUBLE_MATH instance_free: class end bracketted_negative: BOOLEAN -- Enclose negative numbers in brackets? -- (from FORMAT_INTEGER) ceiling (v: REAL_64): REAL_64 -- Least integral greater than or equal to v. -- (from DOUBLE_MATH) external "C signature (double): double use <math.h>" alias "ceil" ensure -- from DOUBLE_MATH instance_free: class end cosine (v: REAL_64): REAL_64 -- Trigonometric cosine of radian v approximated -- in the range [-pi/4, +pi/4]. -- (from DOUBLE_MATH) external "C signature (double): double use <math.h>" alias "cos" ensure -- from DOUBLE_MATH instance_free: class end dabs (v: REAL_64): REAL_64 -- Absolute of v. -- (from DOUBLE_MATH) external "C signature (double): double use <math.h>" alias "fabs" ensure -- from DOUBLE_MATH instance_free: class end decimal: CHARACTER_8 -- What is used for the decimal decimals: INTEGER_32 -- Number of digits after the decimal point. Euler: REAL_64 = 2.7182818284590452353602874713526625 -- Logarithm base -- (from MATH_CONST) exp (x: REAL_64): REAL_64 -- Exponential of v. -- (from DOUBLE_MATH) external "C signature (double): double use <math.h>" ensure -- from DOUBLE_MATH instance_free: class end fill_character: CHARACTER_8 -- Padding character. -- (from FORMAT_INTEGER) floor (v: REAL_64): REAL_64 -- Greatest integral less than or equal to v. -- (from DOUBLE_MATH) external "C signature (double): double use <math.h>" ensure -- from DOUBLE_MATH instance_free: class end generating_type: TYPE [detachable FORMAT_DOUBLE] -- Type of current object -- (type of which it is a direct instance) -- (from ANY) external "built_in" ensure -- from ANY generating_type_not_void: Result /= Void end generator: STRING_8 -- Name of current object's generating class -- (base class of the type of which it is a direct instance) -- (from ANY) external "built_in" ensure -- from ANY generator_not_void: Result /= Void generator_not_empty: not Result.is_empty end justification: INTEGER_32 -- Where in the field the format goes. -- (from FORMAT_INTEGER) log (v: REAL_64): REAL_64 -- Natural logarithm of v. -- (from DOUBLE_MATH) external "C signature (double): double use <math.h>" ensure -- from DOUBLE_MATH instance_free: class end log10 (v: REAL_64): REAL_64 -- Base 10 logarithm of v. -- (from DOUBLE_MATH) external "C signature (double): double use <math.h>" ensure -- from DOUBLE_MATH instance_free: class end log_2 (v: REAL_64): REAL_64 -- Base 2 logarithm of v. -- (from DOUBLE_MATH) do Result := log (v) / log ({REAL_64} 2.0) ensure -- from DOUBLE_MATH instance_free: class end Pi: REAL_64 = 3.1415926535897932384626433832795029 -- (from MATH_CONST) Pi_2: REAL_64 = 1.5707963267948966192313216916397514 -- (from MATH_CONST) Pi_4: REAL_64 = 0.7853981633974483096156608458198757 -- (from MATH_CONST) separator: CHARACTER_8 -- Separator between 1000's of numbers. -- (from FORMAT_INTEGER) sign_format: INTEGER_32 -- How the sign is formatted. -- (from FORMAT_INTEGER) sign_string: STRING_8 -- Formatting details for the sign. -- (from FORMAT_INTEGER) sine (v: REAL_64): REAL_64 -- Trigonometric sine of radian v approximated -- in range [-pi/4, +pi/4]. -- (from DOUBLE_MATH) external "C signature (double): double use <math.h>" alias "sin" ensure -- from DOUBLE_MATH instance_free: class end sqrt (v: REAL_64): REAL_64 -- Square root of v. -- (from DOUBLE_MATH) external "C signature (double): double use <math.h>" ensure -- from DOUBLE_MATH instance_free: class end Sqrt2: REAL_64 = 1.4142135623730950488016887242096981 -- Square root of 2 -- (from MATH_CONST) tangent (v: REAL_64): REAL_64 -- Trigonometric tangent of radian v approximated -- in range [-pi/4, +pi/4]. -- (from DOUBLE_MATH) external "C signature (double): double use <math.h>" alias "tan" ensure -- from DOUBLE_MATH instance_free: class end trailing_sign: BOOLEAN -- Is the sign at the end? -- (from FORMAT_INTEGER) trailing_zeros_shown: BOOLEAN -- Show 0.5000 as 0.5 or 0.5000? width: INTEGER_32 -- Width of the field. -- (from FORMAT_INTEGER) zero_not_shown: BOOLEAN -- Show 0.5 as .5 or 0.5? feature -- Comparison frozen deep_equal (a: detachable ANY; b: like arg #1): BOOLEAN -- Are a and b either both void -- or attached to isomorphic object structures? -- (from ANY) do if a = Void then Result := b = Void else Result := b /= Void and then a.is_deep_equal (b) end ensure -- from ANY instance_free: class shallow_implies_deep: standard_equal (a, b) implies Result both_or_none_void: (a = Void) implies (Result = (b = Void)) same_type: (Result and (a /= Void)) implies (b /= Void and then a.same_type (b)) symmetric: Result implies deep_equal (b, a) end frozen equal (a: detachable ANY; b: like arg #1): BOOLEAN -- Are a and b either both void or attached -- to objects considered equal? -- (from ANY) do if a = Void then Result := b = Void else Result := b /= Void and then a.is_equal (b) end ensure -- from ANY instance_free: class definition: Result = (a = Void and b = Void) or else ((a /= Void and b /= Void) and then a.is_equal (b)) end frozen is_deep_equal alias "≡≡≡" (other: FORMAT_DOUBLE): BOOLEAN -- Are Current and other attached to isomorphic object structures? -- (from ANY) require -- from ANY other_not_void: other /= Void external "built_in" ensure -- from ANY shallow_implies_deep: standard_is_equal (other) implies Result same_type: Result implies same_type (other) symmetric: Result implies other.is_deep_equal (Current) end is_equal (other: FORMAT_DOUBLE): BOOLEAN -- Is other attached to an object considered -- equal to current object? -- (from ANY) require -- from ANY other_not_void: other /= Void external "built_in" ensure -- from ANY symmetric: Result implies other ~ Current consistent: standard_is_equal (other) implies Result end frozen standard_equal (a: detachable ANY; b: like arg #1): BOOLEAN -- Are a and b either both void or attached to -- field-by-field identical objects of the same type? -- Always uses default object comparison criterion. -- (from ANY) do if a = Void then Result := b = Void else Result := b /= Void and then a.standard_is_equal (b) end ensure -- from ANY instance_free: class definition: Result = (a = Void and b = Void) or else ((a /= Void and b /= Void) and then a.standard_is_equal (b)) end frozen standard_is_equal alias "≜" (other: FORMAT_DOUBLE): BOOLEAN -- Is other attached to an object of the same type -- as current object, and field-by-field identical to it? -- (from ANY) require -- from ANY other_not_void: other /= Void external "built_in" ensure -- from ANY same_type: Result implies same_type (other) symmetric: Result implies other.standard_is_equal (Current) end feature -- Status report centered: BOOLEAN -- Are numbers to be formatted centered? -- (from FORMAT_INTEGER) do Result := justification = Center_justification ensure -- from FORMAT_INTEGER Result = (justification = Center_justification) end conforms_to (other: ANY): BOOLEAN -- Does type of current object conform to type -- of other (as per Eiffel: The Language, chapter 13)? -- (from ANY) require -- from ANY other_not_void: other /= Void external "built_in" end ignore_sign: BOOLEAN -- Ignore the sign of a number? -- (from FORMAT_INTEGER) do Result := sign_format = Ignore_sign_value ensure -- from FORMAT_INTEGER Result = (sign_format = Ignore_sign_value) end leading_sign: BOOLEAN -- Is the sign leading? -- (from FORMAT_INTEGER) do Result := not trailing_sign ensure -- from FORMAT_INTEGER Result = not trailing_sign end left_justified: BOOLEAN -- Are numbers to be formatted with spaces on the right? -- (from FORMAT_INTEGER) do Result := justification = Left_justification ensure -- from FORMAT_INTEGER Result = (justification = Left_justification) end no_separator: BOOLEAN -- Is there a separator? -- (from FORMAT_INTEGER) do Result := separator = '%U' ensure -- from FORMAT_INTEGER Result = (separator = '%U') end not_justified: BOOLEAN -- Are numbers to be formatted in smallest string possible -- (from FORMAT_INTEGER) do Result := justification = No_justification ensure -- from FORMAT_INTEGER Result = (justification = No_justification) end right_justified: BOOLEAN -- Are numbers to be formatted with spaces on the left? -- (from FORMAT_INTEGER) do Result := justification = Right_justification ensure -- from FORMAT_INTEGER Result = (justification = Right_justification) end same_type (other: ANY): BOOLEAN -- Is type of current object identical to type of other? -- (from ANY) require -- from ANY other_not_void: other /= Void external "built_in" ensure -- from ANY definition: Result = (conforms_to (other) and other.conforms_to (Current)) end show_sign: BOOLEAN -- Are numbers to show sign whether positive or negative? -- (from FORMAT_INTEGER) do Result := sign_format = Show_sign_value ensure -- from FORMAT_INTEGER Result = (sign_format = Show_sign_value) end show_sign_negative: BOOLEAN -- Are numbers to show sign only when negative? -- (from FORMAT_INTEGER) do Result := sign_format = Sign_negative_value ensure -- from FORMAT_INTEGER Result = (sign_format = Sign_negative_value) end show_sign_positive: BOOLEAN -- Are numbers to show sign only when positive? -- (from FORMAT_INTEGER) do Result := sign_format = Sign_positive_value ensure -- from FORMAT_INTEGER Result = (sign_format = Sign_positive_value) end feature -- Status setting asterisk_fill -- Fill numbers with asterisks. -- (from FORMAT_INTEGER) do fill_character := '*' ensure -- from FORMAT_INTEGER fill_character = '*' end blank_fill -- Fill numbers with blanks. -- (from FORMAT_INTEGER) do fill_character := ' ' ensure -- from FORMAT_INTEGER fill_character = ' ' end bracket_negative -- Bracket negative numbers. -- (from FORMAT_INTEGER) do bracketted_negative := True ensure -- from FORMAT_INTEGER bracketted_negative end center_justify -- Put padding on right and left -- (from FORMAT_INTEGER) do justification := Center_justification ensure -- from FORMAT_INTEGER centered end comma_decimal -- Use , as the decimal point. do decimal := ',' ensure decimal = ',' end comma_separate -- Set the separator to be comma. require -- from FORMAT_INTEGER True do separator := ',' separate_after_decimal ensure -- from FORMAT_INTEGER separator = ',' ensure then after_decimal_separate end dollar_fill -- Fill numbers with dollars. -- (from FORMAT_INTEGER) do fill_character := '$' ensure -- from FORMAT_INTEGER fill_character = '$' end dot_separate -- Set separator to period. -- (from FORMAT_INTEGER) do separator := '.' ensure -- from FORMAT_INTEGER separator = '.' end hide_trailing_zeros -- Show 0.5000 as 0.5, and 0.0000 as 0.0. do trailing_zeros_shown := False ensure trailing_zeros_shown_set: not trailing_zeros_shown end hide_zero -- Show 0.5 as .5 . do zero_not_shown := True ensure zero_not_shown end left_justify --Put padding on right -- (from FORMAT_INTEGER) do justification := Left_justification ensure -- from FORMAT_INTEGER left_justified end no_justify -- Always return the smallest string possible -- (from FORMAT_INTEGER) do justification := No_justification ensure -- from FORMAT_INTEGER not_justified end no_separate_after_decimal -- Do not use separators after the decimal. do after_decimal_separate := False ensure not after_decimal_separate end point_decimal -- Use . as the decimal point. do decimal := '.' ensure decimal = '.' end remove_separator -- Remove the separator. require -- from FORMAT_INTEGER True do separator := '%U' no_separate_after_decimal ensure -- from FORMAT_INTEGER separator = '%U' ensure then not after_decimal_separate end right_justify -- Put padding on left -- (from FORMAT_INTEGER) do justification := Right_justification ensure -- from FORMAT_INTEGER right_justified end separate_after_decimal -- Use separators after the decimal. do after_decimal_separate := True ensure after_decimal_separate end set_decimals (d: INTEGER_32) -- d decimals to be displayed. require d <= width do decimals := d ensure decimals = d end set_fill (c: CHARACTER_8) -- Fill numbers with c -- (from FORMAT_INTEGER) do fill_character := c ensure -- from FORMAT_INTEGER fill_character = c end set_separator (c: CHARACTER_8) -- Set the separator to c -- (from FORMAT_INTEGER) do separator := c ensure -- from FORMAT_INTEGER separator = c end set_sign (s: STRING_8) -- Set sign values for positive, zero, negative -- All values must be the same length. -- Stored as negative, zero, positive. -- (from FORMAT_INTEGER) require -- from FORMAT_INTEGER s /= Void s.count >= 3 s.count \\ 3 = 0 do sign_string := s.twin ensure -- from FORMAT_INTEGER sign_set: sign_string ~ s end set_width (w: INTEGER_32) -- Set width to w -- (from FORMAT_INTEGER) require -- from FORMAT_INTEGER wide_enough: w >= 1 do width := w ensure -- from FORMAT_INTEGER width = w end show_trailing_zeros -- Show 0.5000 as 0.5000. do trailing_zeros_shown := True ensure trailing_zeros_shown_set: trailing_zeros_shown end show_zero -- Show 0.5 as 0.5 . do zero_not_shown := False ensure not zero_not_shown end sign_cr_dr -- Set sign for CR/DR -- (from FORMAT_INTEGER) do sign_string := "CR DR" ensure -- from FORMAT_INTEGER sign_string ~ "CR DR" end sign_dr_cr -- Set sign for DR/CR -- (from FORMAT_INTEGER) do sign_string := "DR CR" ensure -- from FORMAT_INTEGER sign_string ~ "DR CR" end sign_floating_dollar -- Set sign for floating dollar. -- (from FORMAT_INTEGER) do sign_string := "$$$" sign_leading ensure -- from FORMAT_INTEGER sign_string ~ "$$$" end sign_floating_dollar_signed -- Set sign for floating dollar include sign. -- (from FORMAT_INTEGER) do sign_string := "-$ $+$" sign_leading ensure -- from FORMAT_INTEGER sign_string ~ "-$ $+$" end sign_ignore -- Do not show sign. -- (from FORMAT_INTEGER) do sign_format := Ignore_sign_value ensure -- from FORMAT_INTEGER ignore_sign end sign_leading -- Set the sign to lead -- (from FORMAT_INTEGER) do trailing_sign := False ensure -- from FORMAT_INTEGER leading_sign end sign_negative_only -- Show sign for negative numbers only. -- (from FORMAT_INTEGER) do sign_format := Sign_negative_value ensure -- from FORMAT_INTEGER show_sign_negative end sign_normal -- Set sign for - and +. -- (from FORMAT_INTEGER) do sign_string := "- +" ensure -- from FORMAT_INTEGER sign_string ~ "- +" end sign_positive_only -- Show sign for positive numbers only. -- (from FORMAT_INTEGER) do sign_format := Sign_positive_value ensure -- from FORMAT_INTEGER show_sign_positive end sign_show -- Show sign for all numbers. -- (from FORMAT_INTEGER) do sign_format := Show_sign_value ensure -- from FORMAT_INTEGER show_sign end sign_trailing -- Set the sign to trail -- (from FORMAT_INTEGER) do trailing_sign := True ensure -- from FORMAT_INTEGER trailing_sign end unbracket_negative -- Do not bracket negative numbers. -- (from FORMAT_INTEGER) do bracketted_negative := False ensure -- from FORMAT_INTEGER not bracketted_negative end underscore_separate -- Set the separator to be underscore. require -- from FORMAT_INTEGER True do separator := '_' separate_after_decimal ensure -- from FORMAT_INTEGER separator = '_' ensure then after_decimal_separate end zero_fill -- Fill numbers with zeros. -- (from FORMAT_INTEGER) do fill_character := '0' ensure -- from FORMAT_INTEGER fill_character = '0' end feature -- Conversion formatted (d: REAL_64): STRING_8 -- Format d. local sign: INTEGER_32 integral, fraction: REAL_64 ints, fracs: STRING_8 value: REAL_64 do value := d sign := 1 if d < 0.to_double then sign := -1 value := - value end value := value + 5.to_double * 10 ^ (- decimals - 1).to_double integral := floor (value) fraction := floor ((value - integral) * 10 ^ (decimals + 1).to_double) if not no_separator then ints := split_integral (integral.out) if after_decimal_separate then fracs := separate_fraction (pad_fraction (fraction)) else fracs := pad_fraction (fraction) end else ints := integral.out fracs := pad_fraction (fraction) end create Result.make (width) if integral /= 0.to_double or else not zero_not_shown then Result.append (ints) end if not Result.has ('e') then Result.extend (decimal) if decimals > 0 then Result.append (fracs) end if not ignore_sign then Result := process_sign (Result, sign) end end if justification /= No_justification and then Result.count < width then Result := justify (Result) end ensure exists: Result /= Void correct_length: not_justified or Result.count >= width end fm_formatted (i: INTEGER_32): STRING_8 -- Format the integer. -- (from FORMAT_INTEGER) local sign: INTEGER_32 unsigned: INTEGER_32 do if i < 0 then sign := -1 unsigned := - i elseif i > 0 then sign := 1 unsigned := i end if not no_separator then Result := split_integral (unsigned.out) else Result := unsigned.out end if not ignore_sign or bracketted_negative then Result := process_sign (Result, sign) end if justification /= No_justification and then Result.count < width then Result := justify (Result) end ensure -- from FORMAT_INTEGER exists: Result /= Void correct_length: not_justified or Result.count >= width end feature -- Duplication frozen clone (other: detachable ANY): like other obsolete "Use `twin' instead. [2017-05-31]" -- Void if other is void; otherwise new object -- equal to other -- -- For non-void other, clone calls copy; -- to change copying/cloning semantics, redefine copy. -- (from ANY) do if other /= Void then Result := other.twin end ensure -- from ANY instance_free: class equal: Result ~ other end copy (other: FORMAT_DOUBLE) -- Update current object using fields of object attached -- to other, so as to yield equal objects. -- (from ANY) require -- from ANY other_not_void: other /= Void type_identity: same_type (other) external "built_in" ensure -- from ANY is_equal: Current ~ other end frozen deep_clone (other: detachable ANY): like other obsolete "Use `deep_twin' instead. [2017-05-31]" -- Void if other is void: otherwise, new object structure -- recursively duplicated from the one attached to other -- (from ANY) do if other /= Void then Result := other.deep_twin end ensure -- from ANY instance_free: class deep_equal: deep_equal (other, Result) end frozen deep_copy (other: FORMAT_DOUBLE) -- Effect equivalent to that of: -- copy (other . deep_twin) -- (from ANY) require -- from ANY other_not_void: other /= Void do copy (other.deep_twin) ensure -- from ANY deep_equal: deep_equal (Current, other) end frozen deep_twin: FORMAT_DOUBLE -- New object structure recursively duplicated from Current. -- (from ANY) external "built_in" ensure -- from ANY deep_twin_not_void: Result /= Void deep_equal: deep_equal (Current, Result) end frozen standard_clone (other: detachable ANY): like other obsolete "Use `standard_twin' instead. [2017-05-31]" -- Void if other is void; otherwise new object -- field-by-field identical to other. -- Always uses default copying semantics. -- (from ANY) do if other /= Void then Result := other.standard_twin end ensure -- from ANY instance_free: class equal: standard_equal (Result, other) end frozen standard_copy (other: FORMAT_DOUBLE) -- Copy every field of other onto corresponding field -- of current object. -- (from ANY) require -- from ANY other_not_void: other /= Void type_identity: same_type (other) external "built_in" ensure -- from ANY is_standard_equal: standard_is_equal (other) end frozen standard_twin: FORMAT_DOUBLE -- New object field-by-field identical to other. -- Always uses default copying semantics. -- (from ANY) external "built_in" ensure -- from ANY standard_twin_not_void: Result /= Void equal: standard_equal (Result, Current) end frozen twin: FORMAT_DOUBLE -- New object equal to Current -- twin calls copy; to change copying/twinning semantics, redefine copy. -- (from ANY) external "built_in" ensure -- from ANY twin_not_void: Result /= Void is_equal: Result ~ Current end feature -- Basic operations frozen as_attached: attached FORMAT_DOUBLE obsolete "Remove calls to this feature. [2017-05-31]" -- Attached version of Current. -- (Can be used during transitional period to convert -- non-void-safe classes to void-safe ones.) -- (from ANY) do Result := Current end frozen default: detachable FORMAT_DOUBLE -- Default value of object's type -- (from ANY) do end frozen default_pointer: POINTER -- Default value of type POINTER -- (Avoid the need to write p.default for -- some p of type POINTER.) -- (from ANY) do ensure -- from ANY instance_free: class end default_rescue -- Process exception for routines with no Rescue clause. -- (Default: do nothing.) -- (from ANY) do end frozen do_nothing -- Execute a null action. -- (from ANY) do ensure -- from ANY instance_free: class end feature {NONE} -- Implementation Center_justification: INTEGER_32 = 2 -- (from FORMAT_INTEGER) Ignore_sign_value: INTEGER_32 = 1 -- (from FORMAT_INTEGER) justify (s: STRING_8): STRING_8 -- Justify s. -- (from FORMAT_INTEGER) require -- from FORMAT_INTEGER room: s.count < width justification: justification /= No_justification local l, r: STRING_8 i, t: INTEGER_32 do Result := s if not centered then create l.make (width - s.count) from i := 1 until i > l.capacity loop l.extend (fill_character) i := i + 1 end if left_justified then Result.append (l) else Result.prepend (l) end else t := (width - s.count) // 2 if 2 * t + s.count < width then create l.make (t + 1) else create l.make (t) end create r.make (t) from i := 1 until i > r.capacity loop l.extend (fill_character); r.extend (fill_character) i := i + 1 end if i = l.capacity then l.extend (fill_character) end; Result.prepend (l); Result.append (r) end end Left_justification: INTEGER_32 = 1 -- (from FORMAT_INTEGER) No_justification: INTEGER_32 = 0 -- (from FORMAT_INTEGER) pad_fraction (f: REAL_64): STRING_8 -- Stretch or shrink f to length decimals . local i: INTEGER_32 do Result := f.out; Result.remove_tail (1) if Result.count > decimals then Result := Result.substring (1, decimals) else from until Result.count = decimals loop Result.precede ('0') end end if not trailing_zeros_shown then from i := Result.count until i <= 1 or else Result.item (i) /= '0' loop Result.remove (i) i := i - 1 end end ensure valid_result: trailing_zeros_shown implies Result.count = decimals end process_sign (s: STRING_8; sn: INTEGER_32): STRING_8 -- Process sign related values. -- (from FORMAT_INTEGER) local sstring: detachable STRING_8 do Result := s if bracketted_negative and sn = -1 then Result.precede ('('); Result.extend (')') end if ((show_sign_negative or show_sign) and sn = -1) or else ((show_sign_positive or show_sign) and sn = 1) or else (show_sign and sn = 0) then sstring := sign_value (sn) end if sstring /= Void then if trailing_sign then Result.append (sstring) else Result.prepend (sstring) end end end Right_justification: INTEGER_32 = 3 -- (from FORMAT_INTEGER) separate_fraction (s: STRING_8): STRING_8 -- Apply separators to the fraction. require efficiency: separator /= '%U' local count, sep_length: INTEGER_32 do from count := 1 create Result.make (width) until count > s.count - 3 loop from sep_length := 0 until sep_length = 3 loop Result.extend (s.item (count)) count := count + 1 sep_length := sep_length + 1 end; Result.extend (separator) end from until count > s.count loop Result.extend (s.item (count)) count := count + 1 end end Show_sign_value: INTEGER_32 = 0 -- (from FORMAT_INTEGER) Sign_negative_value: INTEGER_32 = 3 -- (from FORMAT_INTEGER) Sign_positive_value: INTEGER_32 = 2 -- (from FORMAT_INTEGER) sign_size: INTEGER_32 -- Size of the sign. -- (from FORMAT_INTEGER) do Result := sign_string.count // 3 ensure -- from FORMAT_INTEGER Result * 3 = sign_string.count end sign_value (i: INTEGER_32): STRING_8 -- Value of the sign. -- (from FORMAT_INTEGER) require -- from FORMAT_INTEGER correct_sign: -1 <= i and i <= 1 local t: INTEGER_32 do t := sign_size * (i + 1) + 1 Result := sign_string.substring (t, t + sign_size - 1) end split_integral (s: STRING_8): STRING_8 -- Apply separators to an integer -- (from FORMAT_INTEGER) require -- from FORMAT_INTEGER efficiency: separator /= '%U' local count, sep_length: INTEGER_32 do from count := s.count create Result.make (width) until count <= 3 loop from sep_length := 0 until sep_length = 3 loop Result.precede (s.item (count)) count := count - 1 sep_length := sep_length + 1 end; Result.precede (separator) end from until count = 0 loop Result.precede (s.item (count)) count := count - 1 end end feature -- Output Io: STD_FILES -- Handle to standard file setup -- (from ANY) once create Result; Result.set_output_default ensure -- from ANY instance_free: class io_not_void: Result /= Void end out: STRING_8 -- New string containing terse printable representation -- of current object -- (from ANY) do Result := tagged_out ensure -- from ANY out_not_void: Result /= Void end print (o: detachable ANY) -- Write terse external representation of o -- on standard output. -- (from ANY) local s: READABLE_STRING_8 do if attached o then s := o.out if attached {READABLE_STRING_32} s as s32 then Io.put_string_32 (s32) elseif attached {READABLE_STRING_8} s as s8 then Io.put_string (s8) else Io.put_string_32 (s.as_string_32) end end ensure -- from ANY instance_free: class end frozen tagged_out: STRING_8 -- New string containing terse printable representation -- of current object -- (from ANY) external "built_in" ensure -- from ANY tagged_out_not_void: Result /= Void end feature -- Platform Operating_environment: OPERATING_ENVIRONMENT -- Objects available from the operating system -- (from ANY) once create Result ensure -- from ANY instance_free: class operating_environment_not_void: Result /= Void end feature {NONE} -- Retrieval frozen internal_correct_mismatch -- Called from runtime to perform a proper dynamic dispatch on correct_mismatch -- from MISMATCH_CORRECTOR. -- (from ANY) local l_msg: STRING_32 l_exc: EXCEPTIONS do if attached {MISMATCH_CORRECTOR} Current as l_corrector then l_corrector.correct_mismatch else create l_msg.make_from_string ("Mismatch: ".as_string_32) create l_exc; l_msg.append (generating_type.name_32); l_exc.raise_retrieval_exception (l_msg) end end invariant separate_all: no_separator implies not after_decimal_separate -- from FORMAT_INTEGER sign_string_attached: sign_string /= Void sign_string_count: sign_string.count >= 3 sign_string_equal_parts: sign_string.count \\ 3 = 0 wide_enough: width >= 1 No_justification <= justification and justification <= Right_justification -- from ANY reflexive_equality: standard_is_equal (Current) reflexive_conformance: conforms_to (Current) note copyright: "Copyright (c) 1984-2012, Eiffel Software and others" license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)" source: "[ Eiffel Software 5949 Hollister Ave., Goleta, CA 93117 USA Telephone 805-685-1006, Fax 805-685-6869 Website http://www.eiffel.com Customer support http://support.eiffel.com ]" end -- class FORMAT_DOUBLE
Generated by ISE EiffelStudio