sgherbst / svreal

Synthesizable real number library in SystemVerilog, supporting both fixed- and floating-point formats
MIT License
43 stars 8 forks source link

[Question] Ranges in fixed point representation. #15

Open cgyurgyik opened 3 years ago

cgyurgyik commented 3 years ago

Hey! Awesome library. Can you explain what you mean by the range of a in this section:

In svreal, fixed-point formats are generally determined automatically from the range of the signals they represent. In this case, the range of a is set to +/- 5.0, and the range of b is set to +/- 10.0.

I'm far from a fixed point expert, and am only aware of the Q format to establish bits for integer and fractional widths.

sgherbst commented 3 years ago

Glad that you're finding it useful. svreal has three properties associated with each fixed-point signal:

  1. Width: total number of bits for signal. For example, if the width is "8", then signal, when interpreted as a twos-complement integer, goes from -128 (10000000) to +127 (01111111).
  2. Exponent: implicit scale factor multiplied by the signal's integer interpretation to produce its real number interpretation. For example, if the exponent is "-5", and the integer interpretation of the signal is "123", then the real number represented is 123*(2^(-5))=3.84375.
  3. Range: real-number range of the signal. For example, if it is "3", then the real-number interpretation can range from -3 to +3. The upper bound of the range is set by the width and exponent, but it is worth keeping track of the range separately to prevent ranges from growing faster than necessary in computations.

In general, the ranges of inputs to a computation must be specified by the user (or passed in from a higher level of the design hierarchy; see "Passing real-number signals"). So in this case, since "a" and "b" are inputs to the computation, the user has to provide their ranges ("5", meaning +/- 5, and "10", meaning +/-10)