Hi all,
→ data.txt file :
-0.1234
1.3456
-1267
345
0.24567
→ In my case i want to read this type of values in my module
=> how can i read this type of values in systemverilog?
=> how can i check whether receiving values is integer or floting point?
In reply to Prashant Soni:
How is the module receiving the values? Is it reading the file directly? If so, you can read it as a string, and then search for the period “.”.
If all you are concerned about is whether the value has a fractional component, you can read it as a real number, cast it to an int, and then subtract the real variable from the int variable. If the result is non-zero, you have fractional number.
thank you dave for your quick response…
yes , i want to receive the values from data.txt
dave can you tell me by example (how can i read floating point and integer type of values)?
In reply to Prashant Soni:
int file, code;
real value_real;
int value_int;
file = $fopen("data.txt","r");
if (file==0) $error("fopen failed");
...
code = $fscanf("%g",value_real);
if (code == 1) // then we read one value
begin
value_int = value_real; // convert to integral
if (value_real - value_int == 0)
$display("read integer");
else
$display("read real");
end