Re: How to implement float min(float x, ...) ?
Re: How to implement float min(float x, ...) ?
- Subject: Re: How to implement float min(float x, ...) ?
- From: Peter Ammon <email@hidden>
- Date: Mon, 17 Nov 2008 10:36:59 -0800
On Nov 16, 2008, at 11:38 PM, Oleg Krupnov wrote:
I apologize, this is plain old C, not Cocoa-specific question, but the
fastest way to get the answer.
I want to create a function that finds the minimum out of a
variable-length list of simple float arguments. In other words, I want
this function:
float min(float x, ...);
Can anyone suggest the implementation?
I have read this: http://developer.apple.com/qa/qa2005/qa1405.html
but it seems to address arguments of type "id", not sure it will work
for simple integral types like float.
Thanks!
In addition to what others have said, it is not possible to pass a
float to such a function (except as one of the named arguments)
without it being promoted to double. So if you depend on working with
floats, you do not want to use a vararg function.
This is why printf() doesn't have separate format specifiers for float
and double. Only %f, which means double.
-Peter
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden