cartesionToPolar - why declaring float/passing double


//Kindle position: 1454
Before main we declare

[code]#include <stdio.h>
#include <math.h> //for modf()

void cartesianToPolar (float x, float y, double *rPtr, double *thetaPtr) {
where x and y are both floats.

in main - later in the code example x and y are variables of type double //Kindle position: 1470

double x = 3.0;
double y = 4.0;
double radius;
double angle;

Why is that? Error in the book?

greetings Matthias


It is a good question – Unless I’m working with really big numbers, I don’t usually worry too much about the difference between a float and double. Maybe I should have been more careful. I probably should have declared it like this:

I’ll fix it in the next printing.


Merci for your answer. Matthias


I wondered that too but realized that it shouldn’t make much of a difference as we are giving these variables a type and its to let the computer to know how much memory to put aside for the task. (I think) It would be good to clear that up in the next printing.


The reason that readers will raise this question about this exercise is that, when using default settings in Xcode, Xcode flags the discrepancy with a warning.


In strongly typed languages like Java or C#, this type of call will not compile: two float parameters in a function when called with two double arguments. Is important to note that in C# is possible to pass a value by reference, but in Java all values are passed by value. But, C# normally does not permit to work directly with pointers like in C or C++, unless you mark the code as unsafe.