Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
math:start [2022/07/30 11:38]
rajit [Namespace math::fxp]
math:start [2023/04/25 10:23] (current)
rajit [Functions]
Line 2: Line 2:
  
 This namespace is used to provide support functions for math operations. This namespace is used to provide support functions for math operations.
 +
 +===== Functions =====
 +
 +<code act>
 +template<pint Worig, Wnew> function sign_extend (int<Worig> x) : int<Wnew>;
 +</code>
 +
 +This function takes an integer ''x'' of width ''Worig'', and sign extends its most significant bit to return a result that has width ''Wnew''. It assumes that ''Wnew'' is at least ''Worig.''
 +
 +
 +<code act>
 +template<pint Worig, Wnew> function zero_extend (int<Worig> x) : int<Wnew>;
 +</code>
 +
 +This function takes an integer ''x'' of width ''Worig'', and zero extends it to return a result that has width ''Wnew''. It assumes that ''Wnew'' is at least ''Worig.''
 +
 +
 +
  
 ===== Namespace math::fxp ===== ===== Namespace math::fxp =====
Line 45: Line 63:
 This returns the negated value of a signed Q(A,B) number ''x''. This returns the negated value of a signed Q(A,B) number ''x''.
  
 +<code act>
 +template<pint A,B> function positive (int<A+B> x) : bool;
 +</code>
 +This is true if the fixed point number is positive (greater than zero), and false otherwise.
 +
 +<code act>
 +template<pint A,B> function negative (int<A+B> x) : bool;
 +</code>
 +This is true if the fixed point number is negative, and false otherwise
 +
 +<code act>
 +template<pint A,B> function le(int<A+B> x, y) : bool;
 +</code>
 +This tests if the value in ''x'' is less than or equal to ''y''.
 +
 +<code act>
 +function conv_to_fxp(pint A, B; preal v) : pint;
 +</code>
 +This can be used to convert a real constant value into its fixed point representation. Note that since ''pint'' values are 64-bit wide (max), this only works when ''A+B'' is at most 64.