REALSTR.DEF 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. (* !LIBRARY! *) DEFINITION MODULE RealStr;
  2. (* Proposed BSI/ISO Standard Modula-2 I/O Library
  3. * Copyright Roger Henry, University of Nottingham
  4. * Version WG/4.01, February 1989
  5. * Permission is given to copy this Definition Module, with the
  6. * copyright notice intact, for the purposes of evaluation and test.
  7. * At the stage of a formal draft standard, Copyright will be transferred
  8. * to BSI (and through BSI to other recognised standards bodies).
  9. * Status: for review by BSI/IST/5/13;
  10. for review by ISO/IEC JTC1/SC22/WG13
  11. --* this version editted to comform to D105 kjg September 1989 *--
  12. *)
  13. IMPORT ConvTypes;
  14. FROM ConvTypes IMPORT ScanProgress, ScanProc;
  15. (* the text form of an real number is *)
  16. (* where w ~ whitespace, and d ~ decimal digit *)
  17. (* [w] ["+"|"-"] d{d} ["." {d}] ["E" ["+"|"-"] d{d}] *)
  18. PROCEDURE Scan(
  19. this: CHAR; VAR progress: ScanProgress; VAR nextScanner: ScanProc
  20. );
  21. TYPE
  22. ConvResults = ConvTypes.ConvResults;
  23. PROCEDURE Format(str: ARRAY OF CHAR): ConvResults;
  24. (* pre: "str" has a string value *)
  25. (* post: returned value corresponds to format of string *)
  26. (* value with respect to the type CARDINAL *)
  27. PROCEDURE Value(str: ARRAY OF CHAR): REAL;
  28. (* pre: "str" has a string value *)
  29. (* and format is "allRight" with respect to CARDINAL *)
  30. (* post: returned value is the corresponding CARDINAL *)
  31. PROCEDURE Take(
  32. str: ARRAY OF CHAR; VAR real: REAL; VAR format: ConvResults
  33. );
  34. (* pre: "str" has a string value *)
  35. (* post: either value of "format" is "allRight", *)
  36. (* value of "real" is the corresponding REAL *)
  37. (* or value of "format" is "outOfRange", *)
  38. (* value of "real" is the NaNS "HUGE" *)
  39. (* or value of "format" is "wrongFormat" *)
  40. (* value of "real" is undefined *)
  41. (* or value of format is "noData" *)
  42. (* value of "real" is unchanged *)
  43. TYPE
  44. Alignment = ConvTypes.Alignment;
  45. PROCEDURE LengthFloat(real: REAL; sigFigs: CARDINAL): CARDINAL;
  46. (* Returns the number of characters in the floating point *)
  47. (* string of real using the given number of significant places *)
  48. PROCEDURE GiveFloat(
  49. VAR str : ARRAY OF CHAR;
  50. real : REAL;
  51. sigFigs: CARDINAL;
  52. width : CARDINAL;
  53. where : Alignment
  54. );
  55. (* post: as far as capacity of "str" allows, *)
  56. (* the character representation of "real" is contained in "str" *)
  57. (* in a field of at least "width" characters *)
  58. (* using sigFigs significant places *)
  59. PROCEDURE LengthEng(real: REAL; sigFigs: CARDINAL): CARDINAL;
  60. (* Returns the number of characters in the engineering format *)
  61. (* string of real using the given number of significant places *)
  62. PROCEDURE GiveEng(
  63. VAR str : ARRAY OF CHAR;
  64. real : REAL;
  65. sigFigs: CARDINAL;
  66. width : CARDINAL;
  67. where : Alignment
  68. );
  69. (* post: as far as capacity of "str" allows, *)
  70. (* the engineering representation of "real" is contained in "str" *)
  71. (* in a field of at least "width" characters *)
  72. (* using sigFigs significant places *)
  73. PROCEDURE LengthFixed(real: REAL; place: INTEGER): CARDINAL;
  74. (* Returns the number of characters in the fixed point *)
  75. (* string of real rounded at position "place". Positive values *)
  76. (* of "place" correspond to positions in the fraction part. *)
  77. PROCEDURE GiveFixed(
  78. VAR str : ARRAY OF CHAR;
  79. real : REAL;
  80. place : INTEGER;
  81. width : CARDINAL;
  82. where : Alignment
  83. );
  84. (* post: as far as capacity of "str" allows, *)
  85. (* the fixed point representation of "real" is contained *)
  86. (* in "str", rounded at position place. Positive values *)
  87. (* of "place" correspond to the fraction part. *)
  88. END RealStr.