# Push real values into queue using parameterized class

**URL:** <https://verificationacademy.com/forums/t/push-real-values-into-queue-using-parameterized-class/31929>\
**Category:** SystemVerilog\
**Tags:** SystemVerilog, Queues, randomization, parameterized-class\
**Created:** [June 10, 2016, 7:51am UTC](https://verificationacademy.com/forums/t/push-real-values-into-queue-using-parameterized-class/31929 "2016-06-10T07:51:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rakesh2learn](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/r/9e8a1a/32.png) [@rakesh2learn](https://verificationacademy.com/forums/u/rakesh2learn)\
**Post date:** [June 10, 2016, 7:51am UTC](https://verificationacademy.com/forums/t/push-real-values-into-queue-using-parameterized-class/31929/1 "2016-06-10T07:51:21Z")

</div>

Problem: output of my queue is zero, instead I am expecting the queue to get filled with 6 random real values.  
Here is the parameterized base class defining my queue:

```auto
class stack #(type T=int,int depth=10);
	rand T data;	
	T Q[$:depth-1]; // defining datatype and depth of queue using pamaeterization 

	task push_Q(T data);
	        
		Q.push_back(data);		

	endtask	

endclass

```

Below is the child class which converts randomized bit type into real value and then push real value into queue. Since I am unaware of a direct way to randomize the real values, so I do it this way.

```auto
class newStack_P #(type T = real,int depth = 6) extends stack; // with parameterization in extended class
rand bit [7:0] bit_val;
T temp;
task put_real (T temp);
		
		
	      temp = $bitstoreal(bit_val); 
	      super.push_Q(temp);
              $display(" bit_val = %b", bit_val);
	      $display(" temp in extended class = %0p", temp);	
	      $display(" queue in extended class = %0p", super.Q);
endtask
endclass

```

Below is my top module:

```auto
module top;
newStack_P #(real,6) ext_stkP_h;
initial begin
ext_stkP_h = new;
		for (int i2=0; i2<6; i2++) begin // push 6 elements in extended class with parameterization case.
			ext_stkP_h.randomize();
			ext_stkP_h.put_real(ext_stkP_h.temp);
		end
end
endmodule

```

So in brief, I want to push in random real values into the queue, but only using my base class method ‘push\_Q’. How can I get this done ? Thank you.

---

<div class="post-metadata">

**Author:** ![sharat](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/s/7ba0ec/32.png) [@sharat](https://verificationacademy.com/forums/u/sharat)\
**Post date:** [June 10, 2016, 9:31am UTC](https://verificationacademy.com/forums/t/push-real-values-into-queue-using-parameterized-class/31929/2 "2016-06-10T09:31:17Z")

</div>

_In reply to [rakesh2learn](https://verificationacademy.com/forums/t/push-real-values-into-queue-using-parameterized-class/31929):_

If you want the child class to be parameterized with _ **real** _ type and queue depth of 6, then you class definition should be

```verilog
 class newStack extends stack #(real, 6); 

```

The child class definition that you have written means that the child class is being extended from the base class with it’s default parameters i.e. (int, 10)

I have re-written the code which should work fine.

```verilog

class stack #(type T = int, int depth = 10);
   T Q[$:depth - 1];
   
   task push_Q(T data);
      Q.push_back(data);
   endtask
endclass

class newStack extends stack #(real, 6);
   
    rand bit [7:0] bit_val;
    real temp;

    task put_real();
        temp = $btistoreal(bit_val);
        push_Q(temp);
        $display("temp in extended class = %0p", temp);	
	$display(" queue in extended class = %0p", Q);
    endtask
endclass

module top;

   newStack ext_stkP_h;
   initial begin
       ext_stkP_h = new;
       for (int i2=0; i2<6; i2++) begin // push 6 elements in extended class with parameterization case.
           ext_stkP_h.randomize();
	   ext_stkP_h.put_real();
	end
   end
endmodule
```

---

<div class="post-metadata">

**Author:** ![rakesh2learn](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/r/9e8a1a/32.png) [@rakesh2learn](https://verificationacademy.com/forums/u/rakesh2learn)\
**Post date:** [June 10, 2016, 3:14pm UTC](https://verificationacademy.com/forums/t/push-real-values-into-queue-using-parameterized-class/31929/3 "2016-06-10T15:14:48Z")

</div>

_In reply to [sharat](https://verificationacademy.com/forums/t/push-real-values-into-queue-using-parameterized-class/31929/2):_

couple of typo in your answer. Though, no big deal about it, I fixed those. Thanks for your time.
