Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ memcpy from double array to float array

Tags:

c++

memcpy

Is is possible to memcpy from a double array to a float array safely?

like image 929
dmessf Avatar asked Jun 02 '10 15:06

dmessf


1 Answers

Depends on what you want. The values certainly won't be preserved. If you need that, use std::copy.

#include <algorithm>

int main()
{
    double a[] = {1.618, 3.1416, 2.7, 0.707, 1.0};
    float b[5];
    std::copy(a, a + 5, b);
}
like image 97
fredoverflow Avatar answered Oct 10 '22 02:10

fredoverflow