0

Possible Duplicate:
Precision of multiplication by 1.0 and int <=> float conversion

I am using the armadillo c++ linear library and am having difficulty with acquiring consistent results. When I print the vector, freq, those are the correct values, but when I multiply it with a scalar value, it is wrong. Even with freq * 1.0! Any suggestions would be great.

mat::fixed<621,1>freq; 
2.0 * arma::datum::pi * freq
Community
  • 1
  • 1
Carnez Davis
  • 863
  • 2
  • 8
  • 12

1 Answers1

1

I can't replicate your problem.

You need to post the exact stand-alone code that demonstrates the problem. In other words, all functions which you're using. This means the program you post can be compiled without any other functions and using only Armadillo dependencies (ie. no Matlab).

When using the following code, I don't get any problems:

#include <iostream>
#include "armadillo"

using namespace arma;
using namespace std;

int main(int argc, char** argv)
  {
  mat::fixed<621,1> freq;
  freq.ones();

  cout << 2.0 * arma::datum::pi * freq << endl;

  return 0;
  }

Btw, googling for the matlab2arma() function (mentioned in the comments to the question) shows a hack done by 3rd party. Mixing fixed size matrices with any kind of hacks involving manual memory management is likely to lead to problems. Do not modify internal Armadillo pointers unless you know what you're doing.

mtall
  • 3,574
  • 15
  • 23