J
Joakim Hove
Hello,
I have an array of doubles, allocated with
dbarr = malloc(N * sizeof(double));
I then want to set[1] all the elements of the array to zero, this is
currently done with
for (i=0; i < N; i++)
dbarr = 0.0;
Now, I think using memset would be more 'elegant', and it seems very
tempting to use:
memset(dbarr , 0 , N * sizeof(* dbarr));
This works on Linux, but do I have a guarantee that the representation
of 0.0 in a double will always be the same as the appropriate number
of consecutive char zero representations? (I mean in principle some
hardware/software could use 01010101010101010.... to represent zero
for a 64 bit double, and 11110000 for a byte zero - or am I just
rambling with nonsense here?)
Regards Joakim
[1]: I know calloc() would solve the problem in the first go, but
dbarr will be used several times, and must be cleared between
each usage.
--
Joakim Hove
hove AT ntnu.no /
Tlf: +47 (55 5)8 27 13 / Stabburveien 18
Fax: +47 (55 5)8 94 40 / N-5231 Paradis
http://www.ift.uib.no/~hove/ / 55 91 28 18 / 92 68 57 04
I have an array of doubles, allocated with
dbarr = malloc(N * sizeof(double));
I then want to set[1] all the elements of the array to zero, this is
currently done with
for (i=0; i < N; i++)
dbarr = 0.0;
Now, I think using memset would be more 'elegant', and it seems very
tempting to use:
memset(dbarr , 0 , N * sizeof(* dbarr));
This works on Linux, but do I have a guarantee that the representation
of 0.0 in a double will always be the same as the appropriate number
of consecutive char zero representations? (I mean in principle some
hardware/software could use 01010101010101010.... to represent zero
for a 64 bit double, and 11110000 for a byte zero - or am I just
rambling with nonsense here?)
Regards Joakim
[1]: I know calloc() would solve the problem in the first go, but
dbarr will be used several times, and must be cleared between
each usage.
--
Joakim Hove
hove AT ntnu.no /
Tlf: +47 (55 5)8 27 13 / Stabburveien 18
Fax: +47 (55 5)8 94 40 / N-5231 Paradis
http://www.ift.uib.no/~hove/ / 55 91 28 18 / 92 68 57 04