Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8623321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:15:13+00:00 2026-06-12T07:15:13+00:00

I have considered posting this question on GameDev since my case relates to a

  • 0

I have considered posting this question on GameDev since my case relates to a game project, but I figured this would be more suited for a broader programming SE. Please let me know if this question would be better posted there after all.

From my understanding – and please correct me if I’m wrong -, game development for mobile (which is my case) can benefit considerably from employing fixed point calculations, since that would assure more consistency betweens platforms and would be an increase in performance in cases where the device isn’t well-equiped to deal with floating point appropriately.

But fixed-point does have limitations, most notably with overflows. So my question is, assuming we have determined that fixed-point is the best alternative given the target platforms, how to determine if a given project’s requirements allow for their use.

To make things clearer, I’d like to share a bit of code I’m having trouble with:

CIwVec2 calculateBezier(float t, CIwVec2 p0, CIwVec2 p1, CIwVec2 p2) {
    float u = 1 - t;

    CIwVec2 p = IW_FIXED(u * u) * p0;   // (1 - t)²P0
    p += IW_FIXED(2 * u * t) * p1;      // 2(1 - t)tP1
    p += IW_FIXED(t * t) * p2;          // t²P2

    return p;
}

In this project I’m using Marmalade SDK, which uses C++ and comes with their own implementation of fixed-point numbers (they have both 16 and 32-bit, I’m using 32-bit as of now), and a Vector class (CIwVec2) which uses that implementation for position and calculations (including scalar multiplication, which is shown in the code above). Oh, and IW_FIXED is just a macro to convert floats to fixed-point.

When I try to run the above code, I get a Multiply overflow error. Debug values as follows:

t = 0
u = 1 (which converts to 4096 in int32 fixed-point with IW_FIXED)
p0.x = 1638400 (400.0f with IW_FIXED_TO_FLOAT)
p0.y = 409600 (100.0f with IW_FIXED_TO_FLOAT)

To be perfectly honest, I don’t have a complete understanding on fixed-point numbers. I understand the idea, but fixed point operations aren’t entirely clear to me (I must have ditched most math classes relating to base 2, shame on me). But I’m completely boggled by the fact that something as simple as 1.0f * 400.0f would cause an overflow in fixed-point.

So, while I thought I wouldn’t have a problem supporting fixed-point in my project, it appears it might not be the case. The game is a top-down car game, which won’t have huge tracks or anything, but they’ll have to be at least as big as the device’s screen (or better yet, its resolution), and since we’re aiming for tablets as well, having trouble with something like 1.0f * 400.0f means fixed-point is out of the question.

Am I correct with this assumption? And, for future projects and for other people with similar problems, how can we assess the viability of fixed-point numbers in a project? Also how to decide between 16-bit and 32-bit would be a great bonus 🙂

(Sorry for the long post and thanks for your time!)

Update:

So, so sum up a bit of the responses so far. The ideal scenario would be to implement your fixed-point numbers in such a way as to have the necessary range for your needs (Mooing Duck’s anwer). Also, for operations with 32bit numbers, the safest thing to do is to calculate using 64bit (timday’s answer and Max’s comment). By the way, Marmalade does have some “safe fixed multiplication” functions, but it’s not the case with the scalar multiplication operator overload for CIwVec2 (which uses IW_FIXED_MUL underneath, which does not mupliply safely).

And lastly, more in regards to my particular scenario, it appears that as of Marmalade 6.1, just using floats would probably be the best solution.

Edit:
Although Max’s answer really solved my problem, it was mostly because it was something specific to Marmalade. Because of that, I have selected Mooing Duck’s answer as the selected answer since I feel is the one which would help out more people in general.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T07:15:14+00:00Added an answer on June 12, 2026 at 7:15 am

    Fixed point can be viewed as storing the top half of a fraction, and the bottom half in your case is 4096. So 1.0f is equal to 4096/4096, and it’s stored in memory as 4096. I won’t go into the details of fractional multiplication because I don’t remember them, but the important part is when multiplying A/D * B/D to get a result C/D, then C is A*B/D.

    So: where you have 1.0f * 400.0f, the computer sees this as 4096 * 1638400 / 4096. A little algebra shows this should result in 1638400 (400.0f), but if the fractional point library isn’t smart enough for that, it ends up with a temporary value of 6710886400 before it does the division, which is too big for an int.

    Since your floating points have a denominator of 4096, your "floats" are accurate to the closest 0.00024, and have a range of -524288.999f to 524287.999f (ish). Is there a way in your compiler to decrease the accuracy of the "floats" to get more range? Otherwise you’re hosed.

    EDIT

    Max confirms that the 4096 is part of Marmalade and cannot be changed. In that case, I see few options:
    (1) Don’t use fixed point.
    (2) Try to keep all floating point numbers between -128 and 128.
    (3) Use a special function for multiplying a scalar and a CIwVec2 that uses IW_FIXED_MUL underneath. Preferably, wrap the float in a special class and overload the operator* to call IW_FIXED_MUL. Don’t provide an implicit conversion to float, otherwise you’ll never find all the errors.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I guess no one will have a definative answer to this but considered predictions
This is a really stupid question, but I need a little reassurance/assistance. I have
I have only started learning python recently. I would still be considered a beginner.
This will be a bit abstract but I have a method like this: private
I'm about to do this in C++ but I have had to do it
I know this type of question has been asked a lot, but I really
Hey, sorry for posting this here, I know that this question better suites into
Due to a problem posting, my last question (duplicate of this) was closed. Background
I posted this question on MWS forum but, didn't get an answer. So, I'm
Whenever I have an application using ActiveRecord I get this ConnectionTimeoutError - but always

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.