Jump to content

  • Log In with Google      Sign In   
  • Create Account

#Actualfastcall22

Posted 13 March 2013 - 01:56 PM

Still,the exercise asks: Why was not each element set to 1? I have no ideea how to explain it

Because you aren't setting each double to 1.0 -- you are setting each individual byte for the first double to 0x01. The layout for your double will be 0x0101010101010101, which is around 7.784e-304, according to IEEE-754.

You probably want to use std::fill instead:
double arr[4] = {};std::fill( arr, arr+4, 1. );

(Also, 1.0 looks like 0x3FF0000000000000 in memory.)

#1fastcall22

Posted 13 March 2013 - 01:47 PM

Still,the exercise asks: Why was not each element set to 1? I have no ideea how to explain it


Because you aren't setting each double to 1.0; you're setting each individual byte for the first double to 0x01. In memory, the layout for your double will be 0x0101010101010101.

You probably want to use std::fill instead:
double arr[4] = {};
std::fill( arr, arr+4, 1. );

PARTNERS