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/
Before you buy.



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  
 
 [ 2 post ] 

 Relevant Pages 

1. FREEWARE: RXXMATH -- Arbitrary Precision Math Functions for REXX

2. Math precision on Intel

3. Need Quad Precision Math Library routine

4. Precision math/trig routines

5. precision math source code

6. Arbitrary precision math library

7. mpexpr-0.8 Multiple precision math for Tcl

8. Math. functions in verilog

9. Answer - math functions in Verilog

10. Verilog ***** Verilog ***** Verilog ***** Verilog

11. Convert single precision to double precision

12. Constant precision & type/precision promotion

 

 
Powered by phpBB® Forum Software