CGFloat fmax/fmaxf?

  • I'm looking for something like the following:

    #if CGFLOAT_IS_DOUBLE
    #define CGFloatMax(x,y) fmax(x,y)
    #else
    #define CGFloatMax(x,y) fmaxf(x,y)
    #endif

    Do I really have to define this myself, or is it somewhere I'm missing?

    Thanks,
    Hamish
  • On Jun 26, 2009, at 8:38 PM, Hamish Allan wrote:

    > I'm looking for something like the following:
    >
    > #if CGFLOAT_IS_DOUBLE
    > #define CGFloatMax(x,y) fmax(x,y)
    > #else
    > #define CGFloatMax(x,y) fmaxf(x,y)
    > #endif
    >
    > Do I really have to define this myself, or is it somewhere I'm
    > missing?
    >
    > Thanks,
    > Hamish
    > _______________________________________________

    You can use Objective C++ or C++.  It overloads the standard math
    functions,
    to use a canonical name for all precisions.
    ----------------------------------
    Skinheads are so tired of immigration, that they are going to move to
    a country that don't accept immigrants!
    Tommy Nordgren
    <tommy.nordgren...>
  • On Fri, Jun 26, 2009 at 8:02 PM, Tommy Nordgren<tommy.nordgren...> wrote:

    >        You can use Objective C++ or C++.  It overloads the standard math
    > functions,
    > to use a canonical name for all precisions.

    Thanks, but I think I'd rather just use the definition I gave than use
    a different language altogether!

    I just thought Apple might have implemented common functions like
    maximum and minimum when they invented the CGFloat stuff, given that
    its entire purpose is to insulate you from having to think about
    whether you're working with floats or doubles.

    Hamish
  • On Jun 26, 2009, at 9:19 PM, Hamish Allan wrote:

    > On Fri, Jun 26, 2009 at 8:02 PM, Tommy Nordgren<tommy.nordgren...>
    >> wrote:
    >
    >> You can use Objective C++ or C++.  It overloads the standard
    >> math
    >> functions,
    >> to use a canonical name for all precisions.
    >
    > Thanks, but I think I'd rather just use the definition I gave than use
    > a different language altogether!
    >
    > I just thought Apple might have implemented common functions like
    > maximum and minimum when they invented the CGFloat stuff, given that
    > its entire purpose is to insulate you from having to think about
    > whether you're working with floats or doubles.
    >
    > Hamish

    Then you can use the following:
    inline CGFloat cgFloatMax(CGFloat x, CGFloat y)
    {
    return x > y ? x : y;
    }

    inline is a part of the current C standard;
    ---------------------------------
    How many National Democrats does it take to change a light bulb?
    108: 8 who smashes the rest of the light bulbs, and 100 to blame a
    zionist world conspiracy for the darkness
    --------------------------
    Tommy Nordgren
    <tommy.nordgren...>
  • On Jun 26, 2009, at 8:38 PM, Hamish Allan wrote:

    > I'm looking for something like the following:
    >
    > #if CGFLOAT_IS_DOUBLE
    > #define CGFloatMax(x,y) fmax(x,y)
    > #else
    > #define CGFloatMax(x,y) fmaxf(x,y)
    > #endif
    >
    > Do I really have to define this myself, or is it somewhere I'm
    > missing?
    >
    > Thanks,
    > Hamish

    The transition guide at <http://developer.apple.com/documentation/Cocoa/Conceptual/Cocoa64BitGuide/C
    onvertingExistingApp/ConvertingExistingApp.html
    > suggests that you're doing this basically as it's supposed to be
    done, apart from an underscore.

    Christiaan
  • On Fri, Jun 26, 2009 at 11:38 AM, Hamish Allan<hamish...> wrote:
    > I'm looking for something like the following:
    >
    > #if CGFLOAT_IS_DOUBLE
    > #define CGFloatMax(x,y) fmax(x,y)
    > #else
    > #define CGFloatMax(x,y) fmaxf(x,y)
    > #endif
    >
    > Do I really have to define this myself, or is it somewhere I'm missing?

    C99 already takes care of this for you; just include/import
    <tgmath.h>, and use fmax() directly.

    --
    Clark S. Cox III
    <clarkcox3...>
  • On Jun 26, 2009, at 4:39 PM, Clark Cox wrote:

    > C99 already takes care of this for you; just include/import
    > <tgmath.h>, and use fmax() directly.

    As the "inventor" of CGFloat, I recommend this approach to our clients
    for C/ObjC code.  It's a little cleaner, in my opinion, than the
    #ifdef block.

    Thanks,
    Derek

    --
    Derek Clegg
    <dclegg...>
  • On Jun 29, 2009, at 7:14 PM, Derek Clegg wrote:

    > On Jun 26, 2009, at 4:39 PM, Clark Cox wrote:
    >
    >> C99 already takes care of this for you; just include/import
    >> <tgmath.h>, and use fmax() directly.
    >
    > As the "inventor" of CGFloat, I recommend this approach to our
    > clients for C/ObjC code.  It's a little cleaner, in my opinion, than
    > the #ifdef block.
    >
    > Thanks,
    > Derek
    >
    > --
    > Derek Clegg
    > <dclegg...>
    >

    So perhaps this could then be mentioned in the documentation?

    I must say that I find this a bit confusing to have inconsistent
    definitions of symbols in different headers (tgmath.h vs. math.h).
    It's certainly not clear to me which definition generally wins out...
    really, I think Apple should not have to make us reinvent the wheel,
    it should just work without doing anything (i.e. the Cocoa frameworks
    should import the correct header).

    Bug filed (rdar://problem/7016130).

    Christiaan
previous month june 2009 next month
MTWTFSS
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30          
Go to today