80.TXT 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. Starting from Rigal V.2.34
  2. Operations with real values in Rigal
  3. =======================================
  4. Limitations of Turbo Pascal
  5. ===========================
  6. Rigal is implemented via Pascal real run time library. The
  7. following sequence of characters is accepted by Pascal VAL
  8. procedure as a real number:
  9. (* space *) [ (+!-) ] (* digits1 *) [ '.' (* digit2 *) ]
  10. [ (e!E) [ (+!-) ] (* digit3 *) ]
  11. The context constraints are that:
  12. digit1+digit2<37 ( limited number of digits )
  13. The absolute value of digits1.digits2E[-]digits3 must be
  14. in 2.9e-39 ... 1.7e38
  15. Input real number from lexical analyzer
  16. =======================================
  17. We call real numbers stored in Rigal memory as #FATOMs. Use
  18. built-in Rigal predicate #FATOM to recognize them. They
  19. can be read by the lexical analyzer from its input as
  20. sequences of characters that must match following grammar
  21. rule
  22. (+ digits1 +)
  23. ( '.' (* digit2 *) [ (e!E) [ (+!-) ] (* digit3 *) ]
  24. ! (e!E) [ (+!-) ] (* digit3 *) )
  25. and it must be acceptable by procedure VAL (see above). If
  26. #FATOM is read then it is stored in 8-byte-length atom, 6
  27. bytes are occupied by standard representation of REAL type
  28. in Pascal. In other two bytes number of digits before dot
  29. and number of digits after the dot are stored. If the input
  30. number was in exponential form then these bytes contain
  31. zeros.
  32. Since standard 6-byte representation is stored, only 10 or
  33. 11 digits are valid.
  34. If the input value matches grammar and does not match "VAL
  35. rules" then atom with type #KEYWORD is produced (it is
  36. used for diagnostic purposes). Normally #FATOM is produced.
  37. Output of real numbers
  38. ======================
  39. Statements PRINT, <<, ,<], built-in rules #IMPLODE and
  40. #EXPLODE output real numbers in form
  41. Sd.ddddddddddEZdd
  42. S is space or '-'
  43. d are digits (exactly 10 digits after dot)
  44. E is character 'E'
  45. Z is '+' or '-'
  46. Real numbers in traditional operators
  47. =====================================
  48. If you use real numbers in traditional arithmetical
  49. operators and comparisons, all #FATOMs are accepted the
  50. same way as NULL. It corresponds to 0 value. If you compare
  51. #FATOMs with '=', their internal representation (with 6
  52. or 8 bytes long code) will be compared.
  53. Ways to create #FATOM
  54. =====================
  55. #CALL_PAS(80 S any_string)
  56. returns #FATOM if string value matches "VAL rule".
  57. Otherwise NULL is returned.
  58. #CALL_PAS(80 I integer)
  59. returns #FATOM. Integer value can be arbitrary.
  60. Ways to get information from #FATOM
  61. ===================================
  62. #CALL_PAS(80 D #FATOM) returns pair
  63. (. digits_before digits_after .)
  64. for FATOM values that were entered through the
  65. lexical analyzer. If the number was entered in exponential
  66. style (with character, 'E'), value (. 0 0 .) is returned.
  67. If the value was obtained by #CALL_PAS(80..), NULL is
  68. returned. There is no other ways to create #FATOM.
  69. NOTE:
  70. If you have entered #FATOM to variable $X via lexical
  71. analyzer, you can output it with the same number of digits
  72. before and after the point (if it was not exponential
  73. style) as it was read by lexical analyser:
  74. $D:=#CALL_PAS(80 D $X);
  75. IF $D AND ($D[1]+$D[2]>0) ->
  76. $REZ:=#CALL_PAS(80 Z $X ($D[1]+$D[2]+1)*100+$D[2])
  77. ELSIF T->
  78. $REZ:=#CALL_PAS(80 V $X)
  79. FI;
  80. Conversions
  81. ===========
  82. #CALL_PAS(80 T #FATOM)
  83. returns #NUMBER - whole part of real value. If the
  84. number is not in -2147483648..2147483647 then NULL is
  85. returned.
  86. #CALL_PAS(80 Z #FATOM D*100+A)
  87. returns formatted string with the value of the real
  88. number. "A" can be positive or negative.
  89. If "A" is arbitrary NEGATIVE number then exponential form
  90. is produced in following form:
  91. Sd.dEZdd (e.g. -7.7E01)
  92. S is space or '-' Z is '-' or '+'
  93. If D>=9 then additional digits are added after the point,
  94. but not more than 10 digits.
  95. If "A" is 0 then integer value is produced, possible with
  96. '-'.
  97. If "A" is positive, it specifies number of digits after
  98. the point. Non-exponential form is produced.
  99. Zeros are appended after point if necessary. The
  100. number of digits after the point cannot be larger than 11.
  101. After all cases discussed above, if "D" is larger than the
  102. new string, RIGAL adds spaces from the left side of the
  103. string. The result string length is not less than "D".
  104. #CALL_PAS(80 R #FATOM p)
  105. - returns rounded value of real number. The number is
  106. rounded such way that digits after p-th position after the
  107. dot must be set to zeros. E.g. 23.1415 rounded at 2 nd
  108. position must be 23.140000.
  109. If p is not positive, it is accepted as 0. If absolute
  110. value of real*(10 in p-th degree) is larger than 1e37 then
  111. NULL is returned.
  112. #CALL_PAS(80 V #FATOM)
  113. - creates string from real number in form
  114. [-]d.ddddddddddESdd
  115. S is '+' or '-'
  116. #CALL_PAS(80 Q #FATOM) returns square root if argument is
  117. not negative, NULL otherwise.
  118. #CALL_PAS(80 X #FATOM) returns exponential ( e in r-th
  119. degree) of the argument.
  120. #CALL_PAS(80 L #FATOM) returns natural logarithm if the
  121. argument is positive, otherwise NULL.
  122. #CALL_PAS(80 op #FATOM #FATOM)
  123. Operations "op" can be '+','-', '*','/', '<','>',
  124. '<=','>=', '<>','='
  125. If '+' or '-' applied, absolute value of the arguments
  126. must be less than 6.2e37 otherwise NULL is returned.
  127. If '*' or '-' applied, absolute value of the result must
  128. be between 1.6e-38..6.2e37 and the second argument of '/' is
  129. not 0, otherwise NULL is returned.
  130. If '<','>','<=','>=','<>','=' are applied, one of the
  131. arguments is returned to indicate 'true', NULL is returned
  132. to indicate 'false' Note that it is IMPOSSIBLE to check the
  133. results of real arithmetic using '=' or '<>' operations,
  134. because the computer never calculates precise results. You
  135. can compare two real numbers only after some conversion,
  136. e.g. using #CALL_PAS(80 V ...).
  137. Common note about #CALL_PAS(80..).
  138. =================================
  139. It has no run time diagnostic.
  140. If wrong types of arguments of wrong number of arguments
  141. or wrong operation name is given, NULL is returned.
  142. If #CALL_PAS(80...) produces a #FATOM, it is 6 bytes long
  143. and it has no information about the digits before and after
  144. the dot.
  145. You can learn more details about #CALL_PAS(80) from
  146. source files USE80.PAS and SERVICES.PAS.
  147.