Equality / case-equality of multiplied real values

I need to check real values on equality.
I use case-equality (“===”) since I have to check for 'X and 'Z values.

I observed that divided real values can be checed for equality, but multiplied values cannot.
Here some examples:

real myval;
logic mytest;

initial begin

	//simple euality check - multiplied 
	myval = 5.0*1.0e-6;
	mytest = (myval == 5.0e-6);	
	if(mytest) $display("is case-equal");
	else $display("is not case-equal");

	//case equality check - multiplied
	myval = 5.0*1.0e-6;
	mytest = (myval === 5.0e-6); 
	if(mytest) $display("is case-equal");
	else $display("is not case-equal");

	//case equality check - divided
	myval = 20e-6/4.0;
	mytest = (myval === 5.0e-6); 
	if(mytest) $display("is case-equal");
	else $display("is not case-equal");
end

The result is:

is not case-equal
is not case-equal
is case-equal
  1. Why do the multiplied values not result in logic “1” when checked for equality, but the divided value does ?
  2. How can I check the multiplied real values for equality with a real number ?

In reply to HoWei:

This has nothing to do with case equality.

Try executing this statement

  initial $display("%30.30g",1.0e-6);

Then read why 0.1 + 0.2 ≠ 0.3

In reply to dave_59:

Yes, of course, you are right.
Stupid me is comparing real/floating-point numbers without the usual precautions.

For completeness, here an example which is working, when I multiply by 1e9 and floor to an integer. This will limit the accuracy of the values of course:


myval = 5.0*1.0e-6/1.0;
mytest = ($floor(myval*1e9) == $floor(5.0e-6*1e9));	//simple euality check
$display("myval %e",$floor(myval*1e9));
$display("mytest %d",mytest);
if(mytest)
	$display("is equal");
else
	$display("is not equal");

The result is

is equal

Do you see any issue with such a comparison ?
Are there better ways to compare the real numbers ?