Re: [AD] float math function inconsistencies

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


Chipmunk: on iOS it uses CGPoint, which is 2D float. It is double by default on other platforms, but can be switched easily to float. And notice how all of the math functions pair with the number type.

If you were to make it optional on Allegro you could do this. However, is it really necessary?


#if (TARGET_OS_IPHONE == 1) && (!defined CP_USE_CGPOINTS)

#define CP_USE_CGPOINTS 1

#endif


#ifdef CP_USE_CGPOINTS

#if TARGET_OS_IPHONE

#import <CoreGraphics/CGGeometry.h>

#elif TARGET_OS_MAC

#import <ApplicationServices/ApplicationServices.h>

#endif

#if defined(__LP64__) && __LP64__

#define CP_USE_DOUBLES 1

#else

#define CP_USE_DOUBLES 0

#endif

#endif


#ifndef CP_USE_DOUBLES

// use doubles by default for higher precision

#define CP_USE_DOUBLES 1

#endif


/// @defgroup basicTypes Basic Types

/// Most of these types can be configured at compile time.

/// @{


#if CP_USE_DOUBLES

/// Chipmunk's floating point type.

/// Can be reconfigured at compile time.

typedef double cpFloat;

#define cpfsqrt sqrt

#define cpfsin sin

#define cpfcos cos

#define cpfacos acos

#define cpfatan2 atan2

#define cpfmod fmod

#define cpfexp exp

#define cpfpow pow

#define cpffloor floor

#define cpfceil ceil

#else

typedef float cpFloat;

#define cpfsqrt sqrtf

#define cpfsin sinf

#define cpfcos cosf

#define cpfacos acosf

#define cpfatan2 atan2f

#define cpfmod fmodf

#define cpfexp expf

#define cpfpow powf

#define cpffloor floorf

#define cpfceil ceilf

#endif




On 30 January 2013 00:10, Nick Trout <chinbillybilbo@xxxxxxxxxx> wrote:
Well a lot of the ones I changed are double functions which are passed floats which then set a float value. So surely the precision would be lost in most cases?

It would be good to comment where double is necessary. Often it is important the order of float operations to try and maintain precision.



On 29 January 2013 20:46, Trent Gamblin <nooskewl@xxxxxxxxxx> wrote:
It definitely shouldn't be all double. In spots where it makes sense, sure, but not everywhere.

Trent

On 2013-01-29, at 1:36 PM, Elias Pschernig <elias.pschernig@xxxxxxxxxx> wrote:
> Nah, I meant double. I remember we had to switch some internal parts of the primitives add-on to double to avoid glitches... so I just dislike float. I also think my version of chipmunk is all double... but may be wrong about that.
>
> On Jan 29, 2013 9:01 PM, "Evert Glebbeek" <eglebbk@xxxxxxxxxx> wrote:
> On 29 Jan 2013, at 20:24 , Nick Trout <chinbillybilbo@xxxxxxxxxx> wrote:
> > Really?! In favour of double?
>
> Elias should confirm, but in favour of integer arithmetic is what I think he meant.
>
> Evert

------------------------------------------------------------------------------
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, _javascript_ and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. ON SALE this month only -- learn more at:
http://p.sf.net/sfu/learnnow-d2d
--
https://lists.sourceforge.net/lists/listinfo/alleg-developers




Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/