Quantcast
Channel: SystemC Language Forum RSS Feed
Viewing all articles
Browse latest Browse all 595

Writing / reading unsigned long long using double channel

$
0
0

I tried to write and read an unsigned long long value over a double channel, using a double value as starting point.

Code snippet:

 

    double d = 3.1415926535897931;

    unsigned long long * ullp = (unsigned long long *) &d;

    out_port.write(*ullp); // sc_out<double> out_port; connected via sc_signal<double> to in_port

    unsigned long long ull = in_port.read(); // sc_in<double> in_port; connected via sc_signal<double> to out_port

    double * dp = (double *) &ull;

 

When I print the values of d, *ullp, ull and *dp, I notice the following:

 

    d:     3.1415926535897931;

    *ullp: 4614256656552045848;

    ull:   4614256656552045568;

    *dp:   3.1415926535896688;

 

However, plain casting without SystemC (double d -> ull* ullp = (ull*) &d -> ull u = *ullp -> double* dp = (double*) &u -> double d2 = *dp) returns d2 with exactly the same value as d.

 

Any idea what is happening and why the channel of type double seems to loose a bit of its precision when using it in this way?

 

-- 

greetz,

Bas


Viewing all articles
Browse latest Browse all 595

Trending Articles