• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How to implement float min(float x, ...) ?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to implement float min(float x, ...) ?


  • Subject: Re: How to implement float min(float x, ...) ?
  • From: Peter N Lewis <email@hidden>
  • Date: Mon, 17 Nov 2008 19:20:12 +0900

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?

Do you really need an arbitrary length argument array? Or would three or four or five be sufficient? Are you overgeneralizing what would be a relatively easy problem?


inline float min( float a1, float a2, float a3 )
   { return fminf( a1, fminf( a2, a3 ) ); }

inline float min( float a1, float a2, float a3, float a4 )
  { return fminf( a1, min( a2, a3, a4 ) ); }

inline float min( float a1, float a2, float a3, float a4, float a5 )
  { return fminf( a1, min( a2, a3, a4, a5 ) ); }

etc

Enjoy,
   Peter.

--
              Keyboard Maestro 3 Now Available!
                Now With Status Menu triggers!

Keyboard Maestro <http://www.keyboardmaestro.com/> Macros for your Mac
<http://www.stairways.com/>           <http://download.stairways.com/>
_______________________________________________

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


References: 
 >How to implement float min(float x, ...) ? (From: "Oleg Krupnov" <email@hidden>)

  • Prev by Date: Re: Set user agent for NSURL
  • Next by Date: Re: newbie NSMutable dictionary subclass question
  • Previous by thread: Re: How to implement float min(float x, ...) ?
  • Next by thread: Re: How to implement float min(float x, ...) ?
  • Index(es):
    • Date
    • Thread