precision of Verilog math
Author Message
precision of Verilog math

Please see the module below for the problem/issue.
Any help is MUCH appreciated.

// This module tests the maximum value
// and precision for a Verilog real calculations
// But why is this happening ??
// (using ModelSim 5.3d on Sun Solaris 2.5.1)
// the intended result is: 480827077700001.000000
//   the actual result is: 480827077700001.062500

`timescale 1ns / 100 fs

module tst_real();

real aa, bb, cc;

initial
begin
aa = 1.0e-9;
bb = 4.808270777e23;
end

begin
cc = aa * bb + 1;
\$display("\nresult: %f\n", cc);
end

endmodule

Sent via Deja.com http://www.*-*-*.com/

Sun, 02 Mar 2003 02:22:25 GMT
precision of Verilog math

Quote:

>Please see the module below for the problem/issue.
>Any help is MUCH appreciated.

>// This module tests the maximum value
>// and precision for a Verilog real calculations
>// But why is this happening ??
>// (using ModelSim 5.3d on Sun Solaris 2.5.1)
>// the intended result is: 480827077700001.000000
>//   the actual result is: 480827077700001.062500

>`timescale 1ns / 100 fs

>module tst_real();

>    real aa, bb, cc;

>    initial
>    begin
>            aa = 1.0e-9;
>            bb = 4.808270777e23;
>    end

>    begin
>            cc = aa * bb + 1;
>            \$display("\nresult: %f\n", cc);
>    end

>endmodule

this is not a Verilog problem, it is a Floating point operation
problem. The following C program gives a similar incorrect result
under NT 5. Floating point operations are not infinite precision, so
not all "real" numbers can be represented by floating point numbers.
When you hit a one of those bad ones, you get inaccurate results.

#include <stdio.h>
#include <math.h>

int main()
{
double a = 1.0e-9;
double b = 4.808270777e23;
double c = a * b + 1;
printf("%f", c);
return 0;

Quote:
}

D:\Projects>test
480827077700001.060000

Mon, 03 Mar 2003 03:00:00 GMT

 Page 1 of 1 [ 2 post ]

Relevant Pages