Sage-ST ä

Convertreal

Documentation

EvaluateSciFloat FloatToStr OVRFloatToStr OVRFloatToStr
OVRStrToFloat OVRStrToFloat RoundAndTrimSciFloat StrToFloat




  procedure FloatToStr
             (FloatVal : in     float;
              Str      :    out string;
              width    : in     natural;
              decDigit : in     integer;
              Success  :    out boolean);

  --*
  --  FloatToStr - Convert from floating point to string, can be fixed size.
  --
  --  This procedure converts a floating point number into a string.  The
  --  number may be converted into either a fixed point or a scientific
  --  notation form.  For example:
  --
  --     FloatVal= 123.456
  --
  --     'wide'       'decDigit'           result
  --     ------       ----------      ------------
  --       10             3           "   123.456"
  --       10             0           "       123"
  --       10            -1           "  1.2E+002"
  --       10            -2           " 1.23E+002"
  --
  --     FloatVal= -123.456
  --
  --     'wide'       'decDigit'           result
  --     ------       ----------      ------------
  --       10             3           "  -123.456"
  --       10             0           "      -123"
  --       10            -1           " -1.2E+002"
  --       10            -2           "-1.23E+002"
  --
  --     FloatVal= 123.456
  --
  --     'wide'       'decDigit'           result
  --     ------       ----------      ------------
  --       0              3           "123.456   "
  --       0              0           "123       "
  --       0             -1           "1.2E+002  "
  --       0             -2           "1.23E+002 "
  --
  --     FloatVal= -123.456
  --
  --     'wide'       'decDigit'           result
  --     ------       ----------      ------------
  --       0              3           "-123.456  "
  --       0              0           "-123      "
  --       0             -1           "-1.2E+002 "
  --       0             -2           "-1.23E+002"
  --
  --  There are two modes of using this routine.  If the value of width is equal
  --  to 0 then the value is converted to string in a free format.  If the value
  --  of width is greater than 0 the string is converted in a fixed format.
  --
  --  Free format - If the value of width is 0 then this format is used.  This
  --  This results in a string that is always left justified and only shows the
  --  sign position if the number is negative.  In this mode the only constraint
  --  to converting is the size of the string that was passed in.
  --
  --  Fixed format - If the value of width is greater than 0 then this format is
  --  used.  In this mode the value is converted to a total length that equals
  --  the size of width.  NOTE - The value of width INCLUDES the sign character
  --  if the number is negative (i.e. the value of -100.0 requires a width of 6).
  --  If the value is positive it can completely fill the string (i.e. a width
  --  of 6 can handle a positive value up to 9999.9).
  --
  --  If the string passed is shorter than width or if the converted value will
  --  not fit within the length of the string then SageError #16
  --  (SageErrs.ArrayTooSmall) is generated.
  --
  --  CALLING SEQUENCE -
  --
  --    FloatToStr (flt, str, wide, decDigit, Success)
  --
  --  ENTRY -
  --
  --    FloatVal: Float
  --      Floating point number to convert to a string.
  --
  --    Width : Natural
  --      Requested width of the resultant string.  If requesting scientific
  --      notation (decDigit is negative), this width must be long enough to
  --      hold the required decimal digit precision plus the signs and exponent
  --      information (see previous example).
  --
  --    decDigit : Natural
  --      The number of digits required to the right of the decimal.  If this
  --      number is negative, the string will be returned in scientific notation
  --      and there will be only 1 digit to the left of the decimal.
  --
  --  EXIT -
  --
  --    str : string
  --      String containing the number in alpha form.
  --
  --    Success : boolean
  --      Operation was successful (TRUE).
  --
  --  EXAMPLE -
  --
  --    with ConvertReal;
  --
  --    procedure NumTest is
  --      str  : string (1..20) := (others => ' ');
  --      done : boolean := false;
  --    begin
  --      ConvertReal.FloatToStr (-123.456, str, 10,  3, done);
  --      ConvertReal.FloatToStr (-123.456, str, 10,  0, done);
  --      ConvertReal.FloatToStr (-123.456, str, 10, -1, done);
  --      ConvertReal.FloatToStr (-123.456, str, 10, -2, done);
  --      ConvertReal.FloatToStr (-123.456, str, 10, -3, done);
  --      ConvertReal.FloatToStr (-123.456, str, 10, -4, done);
  --    end NumTest;
  --




  procedure FloatToStr
             (FloatVal : in     ModSys.S_Float;
              Str      :    out string;
              width    : in     natural;
              decDigit : in     integer;
              Success  :    out boolean);

  --*
  --  FloatToStr - Base FloatToStr overloaded to handle Modsys.S_Float.
  --
  --  See FloatToStr declaration above for details.
  --




  procedure FloatToStr
             (FloatVal : in     ModSys.S_Float64;
              Str      :    out string;
              width    : in     natural;
              decDigit : in     integer;
              Success  :    out boolean);

  --*
  --  FloatToStr - Base FloatToStr overloaded to handle Modsys.S_Float64.
  --
  --  See FloatToStr declaration above for details.
  --




  procedure StrToFloat
             (Str      : in     string;
              FloatVal :    out float;
              Success  :    out boolean);

  --*
  --  StrToFloat - Convert from a string to a floating point value.
  --
  --  This procedure converts a string which contains the alpha representation
  --  of a real number into a floating point number.  The format of the number
  --  within the string ('str') is flexible and may be a number represented in
  --  integer, fixed floating point, or scientific notation form.  For example:
  --
  --     Acceptable           Not Acceptable
  --     ----------           --------------
  --       123.0E+2             123.E+2
  --       123.0E2              123.E2
  --       123
  --      -123
  --       123.
  --       123.456
  --       123E+2
  --
  --  CALLING SEQUENCE -
  --
  --    StrToFloat (str, flt, Success)
  --
  --  ENTRY -
  --
  --    str : string
  --      String containing the number representation.  This may contain
  --      leading blanks, an integer representation, a fixed floating point
  --      representation, or a number represented in scientific notation.
  --
  --  EXIT -
  --
  --    FloatVal: Float
  --      The resultant floating point number.
  --
  --    Success : boolean
  --      Conversion was successful (TRUE).
  --
  --  EXAMPLE -
  --
  --    with ConvertReal;
  --    with ModSys;
  --
  --    procedure NumTest is
  --      f    : Float := 0.0;
  --      done : boolean := false;
  --      str  : string (1..4);
  --    begin
  --      str := " 123";
  --      ConvertReal.StrToFloat (str,         f,done);
  --      ConvertReal.StrToFloat (" 123.",     f,done);
  --      ConvertReal.StrToFloat ("-123.456",  f,done);
  --      ConvertReal.StrToFloat ("123E+2",    f,done);
  --      ConvertReal.StrToFloat (" 123.0E+2", f,done);
  --      ConvertReal.StrToFloat ("123.0E2",   f,done);
  --    end NumTest;
  --




  procedure StrToFloat
             (Str      : in     string;
              FloatVal :    out ModSys.S_Float;
              Success  :    out boolean);

  --*
  --  StrToFloat - Base StrToFloat overloaded to handle Modsys.S_Float.
  --
  --  See StrToFloat declaration above for details.
  --




  procedure StrToFloat
             (Str      : in     string;
              FloatVal :    out ModSys.S_Float64;
              Success  :    out boolean);

  --*
  --  StrToFloat - Base StrToFloat overloaded to handle Modsys.S_Float64.
  --
  --  See StrToFloat declaration above for details.
  --




  procedure EvaluateSciFloat
             (Value              : in     string;
              NumPreDecimal      :    out ModSys.S_Natural;
              NumPostDecimal     :    out ModSys.S_Natural;
              NumInExponent      :    out ModSys.S_Natural;
              PreSignIsPositive  :    out boolean;
              PostSignIsPositive :    out boolean;
              ePosition          :    out ModSys.S_Natural;
              InvalidChars       :    out boolean);

  --*
  --  EvaluateSciFloat - Parse the SciFloat to count sizes.
  --
  --  This procedure parses a supposedly SciFloat format alpha string
  --  and returns the information about how it is composed.  If
  --  invalid characaters are encounted it reports that alos.
  --
  --  CALLING SEQUENCE -
  --
  --    EvaluateSciFloat (Value, NumPreDecimal, NumPostDecimal,
  --                      NumInExponent, PreSignIsPositive,
  --                      PostSignIsPositive, EPosition, InvalidChars)
  --
  --  ENTRY -
  --
  --    Value : string
  --      The string containing the SciFloat format value.
  --
  --  EXIT -
  --
  --    NumPreDecimal : Modsys.S_Natural
  --      The number of digits found before the decimal place.  This does
  --      NOT include the sign character.
  --
  --    NumPostDecimal : Modsys.S_Natural
  --      The number of digits found after the decimal place and before the
  --      'E' character.  This does NOT include that character.
  --
  --    NumInExponent : Modsys.S_Natural
  --      The number of digits found in the exponent position NOT including
  --      the sign position.
  --
  --    PreSignIsPositive : boolean
  --      True - The pre-decimal sign is positive.
  --      False - The pre-decimal sign is negative.
  --
  --    PostSignIsPositive : boolean
  --      True - The post-decimal sign is positive.
  --      False - The post-decimal sign is negative.
  --
  --    EPosition : ModSys.S_Natural
  --      The position in the string where the E character is found.
  --
  --    InvalidChars : boolean
  --      TRUE - Invalid charaters for this format encounted.
  --      FALSE - All characters valid in their respecitve positions.
  --




  procedure RoundAndTrimSciFloat
             (NumDecimalDigits : in     ModSys.S_Natural;
              SciAlphaVal      :    out string);

  --*
  --  RoundAndTrimSciFloat - Round and trim SciFloat value in the post decimal chars.
  --
  --  This procedure checks and rounds the post decimal positions of a SciFloat
  --  format string.  After trimming the string should be correctly rounded and
  --  trimmed to only allow NumDecimalDigits of characters following the
  --  decimal point and preceeding the 'E' character.
  --
  --  CALLING SEQUENCE -
  --
  --    RoundAndTrimSciFloat (NumDecimalDigits, SciAlphaVal)
  --
  --  ENTRY -
  --
  --    NumDecimalDigites : Modsys.S_Natural
  --      The final allowable number of post decimal digits to retain.
  --
  --  EXIT -
  --
  --    SciAlphaVal : string
  --      The string representing the correct rounded and trimmed value of the
  --      floating point number.
  --




Send mail to   warren.merrill@inl.gov with questions or comments about this web site.
Copyright © 1989-2006 Battelle Energy Alliance