/gcc-4.3.4/gcc/vhdl/libraries/ieee/math_real.vhdl

# · VHDL · 267 lines · 81 code · 50 blank · 136 comment · 0 complexity · 0cb80ac3952ead71acae23d1d72ecc9b MD5 · raw file

  1. ------------------------------------------------------------------------
  2. --
  3. -- This source file may be used and distributed without restriction.
  4. -- No declarations or definitions shall be added to this package.
  5. -- This package cannot be sold or distributed for profit.
  6. --
  7. -- ****************************************************************
  8. -- * *
  9. -- * W A R N I N G *
  10. -- * *
  11. -- * This DRAFT version IS NOT endorsed or approved by IEEE *
  12. -- * *
  13. -- ****************************************************************
  14. --
  15. -- Title: PACKAGE MATH_REAL
  16. --
  17. -- Library: This package shall be compiled into a library
  18. -- symbolically named IEEE.
  19. --
  20. -- Purpose: VHDL declarations for mathematical package MATH_REAL
  21. -- which contains common real constants, common real
  22. -- functions, and real trascendental functions.
  23. --
  24. -- Author: IEEE VHDL Math Package Study Group
  25. --
  26. -- Notes:
  27. -- The package body shall be considered the formal definition of
  28. -- the semantics of this package. Tool developers may choose to implement
  29. -- the package body in the most efficient manner available to them.
  30. --
  31. -- History:
  32. -- Version 0.1 (Strawman) Jose A. Torres 6/22/92
  33. -- Version 0.2 Jose A. Torres 1/15/93
  34. -- Version 0.3 Jose A. Torres 4/13/93
  35. -- Version 0.4 Jose A. Torres 4/19/93
  36. -- Version 0.5 Jose A. Torres 4/20/93 Added RANDOM()
  37. -- Version 0.6 Jose A. Torres 4/23/93 Renamed RANDOM as
  38. -- UNIFORM. Modified
  39. -- rights banner.
  40. -- Version 0.7 Jose A. Torres 5/28/93 Rev up for compatibility
  41. -- with package body.
  42. --
  43. -- GHDL history
  44. -- 2005-04-07 Initial version.
  45. -- 2005-09-01 Some PI constants added.
  46. -- 2005-12-20 I. Curtis : significant overhaul to bring closer in line
  47. -- with ieee standard
  48. -------------------------------------------------------------
  49. Library IEEE;
  50. Package MATH_REAL is
  51. -- IAC: should have a string with copyright notice
  52. -- constant CopyRightNotice: STRING
  53. -- := "GPL";
  54. --
  55. -- commonly used constants
  56. --
  57. constant MATH_E : real := 2.71828_18284_59045_23536; -- e
  58. constant MATH_1_OVER_E : real := 0.36787_94411_71442_32160; -- 1/e
  59. constant MATH_PI : real := 3.14159_26535_89793_23846; -- pi
  60. constant MATH_2_PI : real := 2.0 * MATH_PI; -- 2 * pi
  61. constant MATH_1_OVER_PI : real := 0.31830_98861_83790_67154; -- 1/pi
  62. constant MATH_PI_OVER_2 : real := 1.57079_63267_94896_61923; -- pi / 2
  63. constant MATH_PI_OVER_4 : real := 0.78539_81633_97448_30962; -- pi / 4
  64. constant MATH_LOG_OF_2 : real := 0.69314_71805_59945_30942;
  65. -- natural log of 2
  66. constant MATH_LOG_OF_10: real := 2.30258_50929_94045_68402;
  67. -- natural log of10
  68. constant MATH_LOG2_OF_E: real := 1.44269_50408_88963_4074;
  69. -- log base 2 of e
  70. constant MATH_LOG10_OF_E: real := 0.43429_44819_03251_82765;
  71. -- log base 10 of e
  72. constant MATH_SQRT2: real := 1.41421_35623_73095_04880;
  73. -- sqrt of 2
  74. constant MATH_SQRT1_2: real := 0.70710_67811_86547_52440;
  75. -- sqrt of 1/2
  76. constant MATH_SQRT_PI: real := 1.77245_38509_05516_02730;
  77. -- sqrt of pi
  78. constant MATH_DEG_TO_RAD: real := 0.01745_32925_19943_29577;
  79. -- conversion factor from degree to radian
  80. constant MATH_RAD_TO_DEG: real := 57.29577_95130_82320_87685;
  81. -- conversion factor from radian to degree
  82. --
  83. -- function declarations
  84. --
  85. function SIGN (X: real ) return real;
  86. -- returns 1.0 if X > 0.0; 0.0 if X == 0.0; -1.0 if X < 0.0
  87. function CEIL (X : real ) return real;
  88. attribute foreign of ceil : function is "VHPIDIRECT ceil";
  89. -- returns smallest integer value (as real) not less than X
  90. function FLOOR (X : real ) return real;
  91. attribute foreign of floor : function is "VHPIDIRECT floor";
  92. -- returns largest integer value (as real) not greater than X
  93. function ROUND (X : real ) return real;
  94. attribute foreign of round : function is "VHPIDIRECT round";
  95. -- returns integer FLOOR(X + 0.5) if X > 0;
  96. -- return integer CEIL(X - 0.5) if X < 0
  97. function TRUNC (X : real ) return real;
  98. attribute foreign of trunc : function is "VHPIDIRECT trunc";
  99. -- returns integer FLOOR(X) if X > 0;
  100. -- return integer CEIL(X) if X < 0
  101. function "MOD" (X, Y : real ) return real;
  102. attribute foreign of "mod" : function is "VHPIDIRECT fmod";
  103. -- returns the floating point modulus of X/Y
  104. function REALMAX (X, Y : real ) return real;
  105. attribute foreign of realmax : function is "VHPIDIRECT fmax";
  106. -- returns the algebraically larger of X and Y
  107. function REALMIN (X, Y : real ) return real;
  108. attribute foreign of realmin : function is "VHPIDIRECT fmin";
  109. -- returns the algebraically smaller of X and Y
  110. procedure UNIFORM (variable Seed1,Seed2:inout integer; variable X:out real);
  111. -- returns a pseudo-random number with uniform distribution in the
  112. -- interval (0.0, 1.0).
  113. -- Before the first call to UNIFORM, the seed values (Seed1, Seed2) must
  114. -- be initialized to values in the range [1, 2147483562] and
  115. -- [1, 2147483398] respectively. The seed values are modified after
  116. -- each call to UNIFORM.
  117. -- This random number generator is portable for 32-bit computers, and
  118. -- it has period ~2.30584*(10**18) for each set of seed values.
  119. --
  120. -- For VHDL-1992, the seeds will be global variables, functions to
  121. -- initialize their values (INIT_SEED) will be provided, and the UNIFORM
  122. -- procedure call will be modified accordingly.
  123. -- IAC: functions SRAND, RAND and GET_RAND_MAX should not be visible
  124. function SRAND (seed: in integer ) return integer;
  125. attribute foreign of srand : function is "VHPIDIRECT srand";
  126. --
  127. -- sets value of seed for sequence of
  128. -- pseudo-random numbers.
  129. -- It uses the foreign native C function srand().
  130. function RAND return integer;
  131. attribute foreign of rand : function is "VHPIDIRECT rand";
  132. --
  133. -- returns an integer pseudo-random number with uniform distribution.
  134. -- It uses the foreign native C function rand().
  135. -- Seed for the sequence is initialized with the
  136. -- SRAND() function and value of the seed is changed every
  137. -- time SRAND() is called, but it is not visible.
  138. -- The range of generated values is platform dependent.
  139. function GET_RAND_MAX return integer;
  140. --
  141. -- returns the upper bound of the range of the
  142. -- pseudo-random numbers generated by RAND().
  143. -- The support for this function is platform dependent, and
  144. -- it uses foreign native C functions or constants.
  145. -- It may not be available in some platforms.
  146. -- Note: the value of (RAND() / GET_RAND_MAX()) is a
  147. -- pseudo-random number distributed between 0 & 1.
  148. function SQRT (X : real ) return real;
  149. -- returns square root of X; X >= 0
  150. function CBRT (X : real ) return real;
  151. attribute foreign of cbrt : function is "VHPIDIRECT cbrt";
  152. -- returns cube root of X
  153. function "**" (X : integer; Y : real) return real;
  154. -- returns Y power of X ==> X**Y;
  155. -- error if X = 0 and Y <= 0.0
  156. -- error if X < 0 and Y does not have an integer value
  157. function "**" (X : real; Y : real) return real;
  158. -- returns Y power of X ==> X**Y;
  159. -- error if X = 0.0 and Y <= 0.0
  160. -- error if X < 0.0 and Y does not have an integer value
  161. function EXP (X : real ) return real;
  162. attribute foreign of exp : function is "VHPIDIRECT exp";
  163. -- returns e**X; where e = MATH_E
  164. function LOG (X : real ) return real;
  165. -- returns natural logarithm of X; X > 0
  166. function LOG (X: in real; BASE: in real) return real;
  167. -- returns logarithm base BASE of X; X > 0
  168. function LOG2 (X : in real ) return real;
  169. -- returns logarithm base 2 of X; X > 0
  170. function LOG10 (X : in real ) return real;
  171. -- returns logarithm base 10 of X; X > 0
  172. function SIN (X : real ) return real;
  173. attribute foreign of sin : function is "VHPIDIRECT sin";
  174. -- returns sin X; X in radians
  175. function COS ( X : real ) return real;
  176. attribute foreign of cos : function is "VHPIDIRECT cos";
  177. -- returns cos X; X in radians
  178. function TAN (X : real ) return real;
  179. attribute foreign of tan : function is "VHPIDIRECT tan";
  180. -- returns tan X; X in radians
  181. -- X /= ((2k+1) * PI/2), where k is an integer
  182. function ARCSIN (X : real ) return real;
  183. -- returns -PI/2 < asin X < PI/2; | X | <= 1
  184. function ARCCOS (X : real ) return real;
  185. -- returns 0 < acos X < PI; | X | <= 1
  186. function ARCTAN (X : real) return real;
  187. attribute foreign of arctan : function is "VHPIDIRECT atan";
  188. -- returns -PI/2 < atan X < PI/2
  189. function ARCTAN (X : real; Y : real) return real;
  190. -- returns atan (X/Y); -PI < atan2(X,Y) < PI; Y /= 0.0
  191. function SINH (X : real) return real;
  192. attribute foreign of sinh : function is "VHPIDIRECT sinh";
  193. -- hyperbolic sine; returns (e**X - e**(-X))/2
  194. function COSH (X : real) return real;
  195. attribute foreign of cosh : function is "VHPIDIRECT cosh";
  196. -- hyperbolic cosine; returns (e**X + e**(-X))/2
  197. function TANH (X : real) return real;
  198. attribute foreign of tanh : function is "VHPIDIRECT tanh";
  199. -- hyperbolic tangent; -- returns (e**X - e**(-X))/(e**X + e**(-X))
  200. function ARCSINH (X : real) return real;
  201. attribute foreign of arcsinh : function is "VHPIDIRECT asinh";
  202. -- returns ln( X + sqrt( X**2 + 1))
  203. function ARCCOSH (X : real) return real;
  204. -- returns ln( X + sqrt( X**2 - 1)); X >= 1
  205. function ARCTANH (X : real) return real;
  206. -- returns (ln( (1 + X)/(1 - X)))/2 ; | X | < 1
  207. -- Compatibility; will be removed in the future!
  208. impure function FMAX (X, Y : real ) return real;
  209. impure function FMIN (X, Y : real ) return real;
  210. impure function ASIN (X : real ) return real;
  211. impure function ACOS (X : real ) return real;
  212. impure function ATAN (X : real) return real;
  213. impure function ATAN2 (X : real; Y : real) return real;
  214. impure function ASINH (X : real) return real;
  215. impure function ACOSH (X : real) return real;
  216. impure function ATANH (X : real) return real;
  217. end MATH_REAL;