Bug 533 - Multiplication of Scalar variables does not give expected result
Multiplication of Scalar variables does not give expected result
Status: RESOLVED FIXED
Product: ns-3
Classification: Unclassified
Component: core
ns-3-dev
PC Linux
: P5 normal
Assigned To: Faker Moatamri
: bug
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2009-03-27 06:40 EDT by Nicola Baldo
Modified: 2009-04-23 03:36 EDT (History)
2 users (show)

See Also:


Attachments
This is a patch to implement a general purpose 128 bits multiply operation (4.44 KB, patch)
2009-04-22 12:05 EDT, Faker Moatamri
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Nicola Baldo 2009-03-27 06:40:58 EDT
I built and ran the following simple program:

#include <iostream>
#include <ns3/nstime.h>

using namespace ns3;

int main (int argc, char** argv)
{
  Scalar omega = 5.0;
  Scalar tdivT = 0.5;
  Scalar result = omega * tdivT ; 
  std::cout << " expected " << omega.GetDouble() * tdivT.GetDouble()
	    << " actual " << result.GetDouble()  
	    << std::endl;
}
  

And the result I got is:

 expected 2.5 actual 0

I would expect result.GetDouble() to return the value 2.5, too.
Comment 1 Rajib Bhattacharjea 2009-03-27 11:38:21 EDT
Sounds a lot like bug 455...
Comment 2 Faker Moatamri 2009-04-22 12:05:12 EDT
Created attachment 425 [details]
This is a patch to implement a general purpose 128 bits multiply operation

It has the effect of correcting the bug and also it does take into account the sign of the inputs to have the sign of the outputs. I also added tests to verify that it actually works. The function fails if there is an overflow.
Comment 3 Mathieu Lacage 2009-04-23 03:36:06 EDT
changeset: 7d096e399d77