tags:

views:

62

answers:

1

I am working on block compressed sparse row format of sparse matrix. I need to convert a nonzero element into 64 bit floating point. I need a syntax in c OR C++ for that?

+1  A: 

Do you have your number saved as a string? If yes do (this will work in both C and C++):

const char *number = "11.111"; // This the variable holding your number
double num = atof(number); // This is your number saved as a double, that is usually 64 bit

If you have it saved as an int, double, float you can simply do:

double num = other_variable;

Again, it will work in both C and C++.

Andreas Bonini
avoid atof - prefer strtod
anon
Neil, why? [15 chars]
Andreas Bonini
Because strtod() (and strtol() for that matter) is required not to produce unexpected results on overflow during conversion.atof() returns 0.0 both for the string "0.0" and for some invalid input. Whereas for "double strtod(const char *str, char **ptr)", if the value of ptr is not (char **)NULL, the variable to which it points is set to point at the character after the last number, if any, that was recognized. If no number can be formed, *ptr is set to str, and zero is returned. http://www.docs.hp.com/en/B2355-60127/strtod.3C.html
6pack kid