Re: Methods with the same name but different return types
Re: Methods with the same name but different return types
- Subject: Re: Methods with the same name but different return types
- From: Eyal Redler <email@hidden>
- Date: Sat, 04 Jun 2011 17:10:50 +0300
>> I think my original post wasn't clear enough. I saw the side effects (like round() retuning NaN) when I _wasn't_ casting.
>
> round is declared in fp.h as follows:
>
> double round(double x);
>
> So, if you directly provide the argument with the result of position - without type casting ...
Again, sorry for the blurry explanation. I'm not feeding round() with the value retuned from or calculated from "position". The only relation these problems have, AFAIK is that fact that once I've fixed the first, the second was gone.
> So, sizeof(double) > sizeof(short).
> Suppose, the compiler will select the short return type, can we be sure the caller's stack is still valid when the receiver returns a double? That is, x and y are not touched in some accidentally way? I hope so. But z would contain junk.
That was my thought, that some other value is getting corrupted on the stack, the only problem is that int and float are the same size (at least under 32bit which is my case). Maybe I'm way off here but if the size is the same, it should not cause any stack issues beyond the bad result of the calculation.
> round() is not a method, it is a function. What happens there is precisely defined. Given your description, there should be no problem - assuming the argument is a proper float and not NaN. But note, there are a couple of flavors of the round() function - which may in certain cases throw a floating-point exception (please see man pages).
>
> Tip: When you use round with a float as argument, you should use roundf() which returns a float.
It is true that I was using round by feeding it a float and extracting a float and that I should have used roundf, but still, AFAIK, the compiler will convert the input output values to the right types (given there is no ambiguity about round())
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden