-1

I have floating point number in verilog , I wanna shift it to right to make IEEE standard, but I don't know where the point is, to understand if it is standard or not(to stop shifting) .

what can I do?

second question: if i shift floating point like this: 10001.11 to right what does happen in verilog? 0100.111 or 0100.11 ?

IEEE standard

user76767
  • 45
  • 2
  • 2
  • 8
  • Why do you need to shift to make it IEEE standard it is a IEEE standard 754 – Morgan Mar 25 '15 at 20:09
  • What happened when you tried the `>>` shift I get : ` Illegal operator for real expressions: >>.` why not just multiply by 0.5. – Morgan Mar 25 '15 at 20:13
  • I wanna make it to 1.000111 to be normalized (its my fault to say make it standard), tnx i will multiply by 0.5 but what does happen? 0100.111 ? @morgan – user76767 Mar 26 '15 at 18:45
  • You can not use the `>>` operator on reals, so nothing happens. Also just to make sure you are aware reals are not synthesisable. – Morgan Mar 26 '15 at 18:54
  • ok i will use *0.5 ,but what will happen ? 0100.11 or 0100.111?@morgan – user76767 Mar 26 '15 at 18:57
  • What will happen when? multiplying 010001.11 (base2) * 0.5 (base10). Floating point numbers are integers multiplied by a scaling factor so you actually have `01000111 * 2^-2` *0.5. 0.5 is 2^-1 so the result is `01000111 * 2^-3`. which holds the value `01000.111` but that is not the underlying bit pattern that represents the floating point number. – Morgan Mar 26 '15 at 19:06
  • can I write k=m*(2^l) in verilog? what kind of data l,m and k should be?@morgan – user76767 Mar 26 '15 at 19:40
  • use `2**l` in verilog `^` is XOR. Other wise you can write that, but about now you might be realising that synthesisable verilog is integer only, there is no builtin fractional format. if you want fractional fixed point is the easiest way to go. Floating point is not trivial to implement. These two answers might be useful [one](http://stackoverflow.com/a/27765266/97073) and [two](http://stackoverflow.com/a/28170918/97073) – Morgan Mar 26 '15 at 20:00
  • I understood that my problem solved with this(" 01000111 * 2^-3) representation, i don't want to solved it with floating point numbers. but as you said the only thing that I must do in when I want to use power is using ** instead of ^ ? (thank for your link, i'll read them) @morgan – user76767 Mar 26 '15 at 20:18

4 Answers4

0

IEEE 1800-2012 the latest SystemVerilog specification states:

5.7.2 Real literal constants

The real literal constant numbers shall be represented as described by IEEE Std 754, an IEEE standard for double-precision floating-point numbers.

...

6.12 Real, shortreal, and realtime data types
The real* data type is the same as a C double. The shortreal data type is the same as a C float. The realtime declarations shall be treated synonymously with real declarations and can be used interchangeably. Variables of these three types are collectively referred to as real variables

* The real and shortreal types are represented as described by IEEE Std 754.

Wikipedia IEEE 754

Morgan
  • 19,934
  • 8
  • 58
  • 84
0

One thing to make sure is whether you're dealing with a floating point number, or a fixed-point number. They are stored very differently in practice, with fixed-point numbers being much easier to process.

  • Fixed point numbers are stored the same as any other integer. The difference is when they are interpreted a decimal point is added at a bit position. For example, you could store a 16-but number, but say the last 4 bits are after the decimal point. This is sometimes referred to as 12.4, make sure you comment your code to make this clear. You also need to track whether the number is a positive-only value, or a 2's complement value.

    • Floating points are stored using a mantissa and exponent. They can represent a much wider range of values, but are more complicated to manipulate.

For your second question I'm going to assume you're using fixed-point arithmetic. The decimal point is fixed and doesn't move. So for your example:

10001.11 >> 1 = 11000.11

Note that if your number is signed 2's complement, then MSBs will be copied from the MSB of the number before the shift (this maintains the sign before and after the shift).

0

You tell about fix point operation. Shift operation don't work with float numbers.

Verilog has float type - real, but this type is not for synthesis and don't support oparation >> (shift)

For float numbers shift is undefined in all languages.

But if you want to multiply number, you must work with exponent and mantissa parts

Papayaved
  • 103
  • 1
  • 1
  • 11
0

To make it IEEE standard. you need to follow IEEE-754 format for representing floating point numbers. There are different types of floating point representations in the standard.

  1. half precision(or FP16), where you can have 1 bit for sign, 5-bits for exponent and 10 bits for mantissa.

  2. full precision(or FP32), where you can have 1 bit for sign, 8-bits for exponent and 23-bits for mantissa and so on.

You can perform any kind of operations with FP16 and FP32 representations, like addition, subtraction, multiplication etc.

Yaseen Ahmad
  • 1,807
  • 5
  • 25
  • 43
sathyarokz
  • 13
  • 6