Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
math:start [2022/07/30 15:38] – [Namespace math] rajit | math:start [2025/09/23 11:02] (current) – [Fixed point data type] rajit | ||
---|---|---|---|
Line 4: | Line 4: | ||
===== Functions ===== | ===== Functions ===== | ||
+ | |||
+ | <code act> | ||
+ | template< | ||
+ | </ | ||
+ | |||
+ | This function takes an integer '' | ||
+ | |||
+ | |||
+ | <code act> | ||
+ | template< | ||
+ | </ | ||
+ | |||
+ | This function takes an integer '' | ||
+ | |||
+ | ===== Fixed point data type ===== | ||
+ | |||
+ | The standard math library has a fixed point data type. | ||
+ | |||
+ | <code act> | ||
+ | export template <pint A, B> deftype fixpoint(int< | ||
+ | </ | ||
+ | |||
+ | This datatype uses the standard Q(A,B) fixed point format, where A bits are used for the integer part and B bits are used for the fractional part. This datatype defines operators for addition, subtraction, | ||
+ | |||
+ | The following code fragment initializes the fixed point value '' | ||
+ | <code act> | ||
+ | math:: | ||
+ | ... | ||
+ | chp { | ||
+ | x.set(x.const(5.25)); | ||
+ | ... | ||
+ | } | ||
+ | </ | ||
+ | Other ways to initialize '' | ||
+ | <code act> | ||
+ | ... | ||
+ | chp { | ||
+ | x.x := 0x0f; | ||
+ | ... | ||
+ | | ||
+ | ... | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | For debugging purposes, two macros are also provided for displaying the value of a fixed point number. The '' | ||
+ | <code act> | ||
+ | chp { | ||
+ | ... | ||
+ | | ||
+ | ... | ||
+ | } | ||
+ | </ | ||
+ | |||
Line 48: | Line 101: | ||
This returns the negated value of a signed Q(A,B) number '' | This returns the negated value of a signed Q(A,B) number '' | ||
+ | <code act> | ||
+ | template< | ||
+ | </ | ||
+ | This is true if the fixed point number is positive (greater than zero), and false otherwise. | ||
+ | |||
+ | <code act> | ||
+ | template< | ||
+ | </ | ||
+ | This is true if the fixed point number is negative, and false otherwise | ||
+ | |||
+ | <code act> | ||
+ | template< | ||
+ | </ | ||
+ | This tests if the value in '' | ||
+ | |||
+ | <code act> | ||
+ | function conv_to_fxp(pint A, B; preal v) : pint; | ||
+ | </ | ||
+ | This can be used to convert a real constant value into its fixed point representation. Note that since '' | ||
+ | These functions are used by the fixed point data type. | ||