How to find a closest entry in an array using system verilog

In reply to dave_59:

Will it work correctly for negative values ?