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 8521443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:49:35+00:00 2026-06-11T06:49:35+00:00

Android uses the RectF structure for drawing bitmaps. I am working on my game

  • 0

Android uses the RectF structure for drawing bitmaps. I am working on my game structure, so for example, a Sprite will have and x/y coordinate, width, height, speed, and so on. This means every time in my render loop I have to cast those integers to floats when figuring out the source/target RectF’s to use… alternatively, I can be far more universal and use floats everywhere so that when it comes time to simulate the physics and render, all of the types are already of the same type… even if it is unnecessary for what the property is (I don’t need a float for “x position”, but will have to cast it when rendering if not).

if floats generally are 2-10x’s more ineffient (per http://developer.android.com/guide/practices/performance.html), what is the proper course to take?

TLDL: Should I cast int’s to float on render, or just have all of the contributing variables be floats to begin with, even if floats are inefficient? How inefficient is a typecast?

  • 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-11T06:49:36+00:00Added an answer on June 11, 2026 at 6:49 am

    The best way to do this is to do your calculations with the highest degree of precision required to produce the expected results within the specified tolerance. That means if you need to use doubles to do calculations and get the expected results with consistency, then use them. Figure out where less precision is acceptable, and only do the operations that require it with floats. Remember, your world doesn’t have to approximate earth gravity for falling objects, you could simplify things and make the gravity 10 instead of 9.81, make pixels correspond to even units, etc. It’ll also help if you define your constants in the same units and avoid doing unit conversion to do math (as this results in extra ops), it’s better to add more final constants that have something like gravity in cm/s, m/s and km/h than it is to only have one and to convert it a thousand times. Oh and the cost of casting int to float isn’t very high compared multiplying 2 floats, so think about that.

    I’ll also note that FPUs are becoming more and more common in modern android phones, and so the issue of using floating point math is becoming a little less important (although not entirely).

    The other thing I want to note is Double/Float/Integer vs. double/float/int. The former require new objects to be created to use and shouldn’t be used for math (whenever possible), whereas the latter are primitives and do not result in new object creation to use, they’re less costly to create.

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

Sidebar

Related Questions

My android project uses many images, and I have images for different DPIs as
I have a client and a server app on Android (that uses ZeroC -
I am building an android application that uses several third party libraries. I have
I have learned that when using android:entries with a ListView , it uses android.R.layout.simple_list_item_1
We're creating a game that will run on iOS, Android and in the web
I have a drawing application in Android that allows the user to draw with
In Java for some reason the Ellipse2D.Double uses the parameters (height, width, x, y)
I have an Android application that uses the well known Strategies for Legacy Applications
I have got my android app that uses HttpClient to reach my servlet deployed
I have an Android Activity that uses a class that I developed that extends

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.