I'm looking for an efficient way of converting an array of integers to an array of doubles.

Currently I'm doing this:

int *a = new int[1000]; //And then assign values to the indexes
double *b = new double[1000];
for(int i = 0; i < 1000; i++)
   b[i] = (double) a[i];

But this seems extremely inefficient to me, especially if you do this with large arrays over and over again. Isn't there some other way to do the conversion, such as cast or so?

7 Years
Discussion Span
Last Post by firstPerson

Is there any reason why you can't use double instead of int in the first place? That way the conversion would be unnecessary.


Yes, there is an external function that takes a double array (and I can't change that function), and I'm using this function.


What I mean is, why not use an array of double from the start instead of an array of int, then pass that into the external function? Are you also using an external function that can't be changed which gives you an array of int, or something?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.