Finding index of the negative value in Queue

I have got a problem while finding the index of the element in a queue

int queue[$]='{2,-1,127};

I am trying to find the index value of the negative no in the queue using

queue.find_first_index(x) with (x<0)

it should give index value as 1 but i am not getting the index value as 1.
Can anyone tell me whats wrong?

In reply to Manoj J:

Works for me. How about showing us a complete example? Mine was 5 lines (and 2 of them were module top; endmodule).

In reply to dave_59:

I was trying to do the exercises in the chris spear’s book


``` verilog
module queue_prblm8;
  int queue[3]='{2,-1,127};
  initial begin
    $display("Sum of the queue is %0d",queue.sum());
    queue.sort;
    $display("Min value in the queue is %0d",queue[0]);
    $display("Max value in the queue is %0d",queue[3]);
    $display("Queue after sorting is %p",queue);
    $display("Index of the negative value %d",queue.find_first_index(x) with (x < 0));
    $display("Positive  values in the queue is %p",(queue.find() with (item > 0)));
    queue.reverse;
    $display("queue after reversing %p",queue);
  end
endmodule

This is the code and i am using synopsys simulator

> Sum of the queue is 128
... 
Index of the negative value   166757000


and this is the output i am getting

In reply to Manoj J:

queue.find_first_index()

doesn’t return an index. It returns a queue that will either contain the desired index or be empty if no such index exists. What you’re printing is the “memory location” of the array. Change your format specifier to

%p

Also note that you’re printing queue[3] after doing max(), but the array only has 3 elements.

In reply to Tudor Timi:

Thanks Tudor!!!

Also note that you’re printing queue[3] after doing max(), but the array only has 3 elements.

Yeah, i will correct it.