Using real data types in VHDL
1 library IEEE; 2 use IEEE.STD_LOGIC_1164.ALL; 3 use IEEE.MATH_REAL.ALL; 4 5 entity real_demo is 6 end real_demo; 7 8 architecture Behavioral of real_demo is 9 10 --signals declared with the REAL data type. 11 --MATH_PI is a constant defined in the math_real package. 12 signal X : real := -MATH_PI/3.0; --A real variable X, initialized to pi/3(60 degreee). 13 signal sign_result,ceil_result,floor_result,round_result,trunc_result : real := 0.0; 14 signal max,min,root,cube,power1,power2,exp_result : real := 0.0; 15 signal log_result,log2_result,log10_result,log_result2,sine,cosine,tangent : real := 0.0; 16 signal sin_inv,cos_inv,tan_inv,sin_hyp,cos_hyp,tan_hyp : real := 0.0; 17 signal inv_sin_hyp,inv_cos_hyp,inv_tan_hyp : real := 0.0; 18 19 begin 20 21 process 22 begin 23 24 sign_result <= SIGN(X); --sign of X 25 ceil_result <= CEIL(X); --smallest integer value not less than X 26 floor_result <= FLOOR(X); --largest integer value not greater than X 27 round_result <= ROUND(X); --round to the nearest integer. 28 trunc_result <= TRUNC(X); --truncation. 29 max <= REALMAX(4.5,4.6); --return the maximum 30 min <= REALMIN(2.3,3.2); --return the minimum 31 root <= SQRT(4.0); --square root 32 cube <= CBRT(64.0); --cube root 33 power1 <= 2**3.0; --power of an integer 34 power2 <= 3.0**3.0; --power of a real 35 exp_result <= EXP(1.0); --returns e**X. 36 log_result <= LOG(2.73); --natural logarithm 37 log2_result <= LOG2(16.0); --log to the base 2. 38 log10_result <= LOG10(100.0); --log to the base 10. 39 log_result2 <= LOG(27.0,3.0); --log to the given base. 40 sine <= SIN(X); --sine of the given angle(in rad) 41 cosine <= COS(X);--cosine of the given angle(in rad) 42 tangent <= TAN(X);--tangent of the given angle(in rad) 43 sin_inv <= ARCSIN(SIN(X)); --sine inverse. 44 cos_inv <= ARCCOS(COS(X)); --cosine inverse. 45 tan_inv <= ARCTAN(TAN(X)); --tangent inverse. 46 sin_hyp <= SINH(X); --Hyperbolic sine 47 cos_hyp <= COSH(X); --Hyperbolic cosine. 48 tan_hyp <= TANH(X); --Hyperbolic tangent. 49 inv_sin_hyp <= ARCSINH(SINH(X)); --Inverse hyperbolic sine. 50 inv_cos_hyp <= ARCCOSH(COSH(X)); --Inverse hyperbolic cosine. 51 inv_tan_hyp <= ARCTANH(TANH(X)); --Inverse hyperbolic tangent. 52 wait; 53 54 end process; 55 56 end Behavioral;