Cas de test:Comment imprimer un double en toute précision sur iOS?
NSLog(@"%f", M_PI);
NSLog(@"%@", [NSString stringWithFormat:@"%f", M_PI]);
NSLog(@"%@", [NSNumber numberWithDouble:M_PI]);
Résultats:
3,141593
3,141593
3,141592653589793
Conclusions:
1) Impression via NSLog() ou [NSString stringWithFormat ] fournir une précision très faible ...
2) Impression via [NSNumber numberWithDouble] offre une meilleure précision ...
Je me serais attendu à obtenir un résultat beaucoup plus proche de la valeur d'origine: 3.14159265358979323846264338327950288 (tel que défini en math.h)
Des indices?
Brillant, merci! –