Use floats or doubles when writing mobile gamesWhat's the largest “relative” level I can make using float?video card architectureIs “pure” OpenGL productive enough?How can I use allocators for different systems?When to use GameComponents?What are some gameplay cases where knowing the Z as a result of the raycasting is useful in a 2D setting?Can Mobile Games use Fragments instead of SurfaceViews?

Conveying the idea of "down the road" (i.e. in the future)

Can I voluntarily exit from the US after a 20 year overstay, or could I be detained at the airport?

Using 4K Skyrim Textures when running 1920 x 1080 display resolution?

How much Money Should I save in Order to Generate $1000/Month for the rest of my life?

Quote to show students don't have to fear making mistakes

How to catch creatures that can predict the next few minutes?

How to assemble a contract’s code?

Injection from two strings to one string

Would Great Old Ones care about the Blood War?

What is /dev/null and why can't I use hx on it?

How come the Russian cognate for the Czech word "čerstvý" (fresh) means entirely the opposite thing (stale)?

Maintaining distance

What benefits are there to blocking most search engines?

When can this condition on linear codes be satisfied?

Can an animal produce milk all the time?

Has Boris Johnson ever referred to any of his opponents as "traitors"?

Is Zhent just the term for any member of the Zhentarim?

As an interviewer, how to conduct interviews with candidates you already know will be rejected?

Redirect output on-the-fly - looks not possible in Linux, why?

Why is my vegetable stock bitter, but the chicken stock not?

How do I know how many sub-shells deep I am?

Advices to added homemade symbols

Dotted footnote rule

Use floats or doubles when writing mobile games



Use floats or doubles when writing mobile games


What's the largest “relative” level I can make using float?video card architectureIs “pure” OpenGL productive enough?How can I use allocators for different systems?When to use GameComponents?What are some gameplay cases where knowing the Z as a result of the raycasting is useful in a 2D setting?Can Mobile Games use Fragments instead of SurfaceViews?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty
margin-bottom:0;









2












$begingroup$


I know for shaders, floats should be used because they are the optimal choice for performance. Doubles are slow and use more memory which isn't ideal for shaders. While floats are less accurate and are prone to float overlflows, the tradeoff for speed is ideal on mobile hardware.



But what about everywhere else in the code base not related to the shader pipeline? I'm writing an engine and use doubles for the delta update tick and try to keep all units relative to that data type so there's lots of places using doubles. Should I be using floats on mobile in the engine as well?



The engine is written in C++ language










share|improve this question











$endgroup$













  • $begingroup$
    I'd imagine it largely depends on which language you're using.
    $endgroup$
    – DJ Spicy Deluxe
    7 hours ago










  • $begingroup$
    Added C++ in the description
    $endgroup$
    – Dan
    4 hours ago

















2












$begingroup$


I know for shaders, floats should be used because they are the optimal choice for performance. Doubles are slow and use more memory which isn't ideal for shaders. While floats are less accurate and are prone to float overlflows, the tradeoff for speed is ideal on mobile hardware.



But what about everywhere else in the code base not related to the shader pipeline? I'm writing an engine and use doubles for the delta update tick and try to keep all units relative to that data type so there's lots of places using doubles. Should I be using floats on mobile in the engine as well?



The engine is written in C++ language










share|improve this question











$endgroup$













  • $begingroup$
    I'd imagine it largely depends on which language you're using.
    $endgroup$
    – DJ Spicy Deluxe
    7 hours ago










  • $begingroup$
    Added C++ in the description
    $endgroup$
    – Dan
    4 hours ago













2












2








2


1



$begingroup$


I know for shaders, floats should be used because they are the optimal choice for performance. Doubles are slow and use more memory which isn't ideal for shaders. While floats are less accurate and are prone to float overlflows, the tradeoff for speed is ideal on mobile hardware.



But what about everywhere else in the code base not related to the shader pipeline? I'm writing an engine and use doubles for the delta update tick and try to keep all units relative to that data type so there's lots of places using doubles. Should I be using floats on mobile in the engine as well?



The engine is written in C++ language










share|improve this question











$endgroup$




I know for shaders, floats should be used because they are the optimal choice for performance. Doubles are slow and use more memory which isn't ideal for shaders. While floats are less accurate and are prone to float overlflows, the tradeoff for speed is ideal on mobile hardware.



But what about everywhere else in the code base not related to the shader pipeline? I'm writing an engine and use doubles for the delta update tick and try to keep all units relative to that data type so there's lots of places using doubles. Should I be using floats on mobile in the engine as well?



The engine is written in C++ language







architecture memory-efficiency






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 4 hours ago







Dan

















asked 10 hours ago









DanDan

11911 bronze badges




11911 bronze badges














  • $begingroup$
    I'd imagine it largely depends on which language you're using.
    $endgroup$
    – DJ Spicy Deluxe
    7 hours ago










  • $begingroup$
    Added C++ in the description
    $endgroup$
    – Dan
    4 hours ago
















  • $begingroup$
    I'd imagine it largely depends on which language you're using.
    $endgroup$
    – DJ Spicy Deluxe
    7 hours ago










  • $begingroup$
    Added C++ in the description
    $endgroup$
    – Dan
    4 hours ago















$begingroup$
I'd imagine it largely depends on which language you're using.
$endgroup$
– DJ Spicy Deluxe
7 hours ago




$begingroup$
I'd imagine it largely depends on which language you're using.
$endgroup$
– DJ Spicy Deluxe
7 hours ago












$begingroup$
Added C++ in the description
$endgroup$
– Dan
4 hours ago




$begingroup$
Added C++ in the description
$endgroup$
– Dan
4 hours ago










1 Answer
1






active

oldest

votes


















6














$begingroup$

You'd be hard pressed to find a mobile GPU that could use doubles even if you wanted to, so that choice is pretty much made for you.



There are only a few places where you might benefit from switching from single-precision floats in your game. Storing total elapsed time, or an absolute position several kilometers from the origin, are two examples of things you shouldn't try to store in a single-precision float, but that doesn't mean you need to use doubles necessarily. Integer types can handle these values just fine.



A delta time value will usually be on the order of 16 milliseconds, so storing it in a single precision float gives you precision to about $2^-29$, which is down to the level of nanoseconds — ie. probably higher precision than you can signal your threads or graphics refresh anyway. Adding more precision here with a double is unlikely to improve your game in any measurable way. So you can store your total elapsed at high precision or using an integer type, compute your delta and convert to single-precision float once per frame, then use floats happily form there on.



Similarly for positions. Even with a huge world, if you break it up into chunks less than 32 km across, then single precision floats can locate a position within a chunk to a precision of less than a millimetre. Relative offsets between objects (for computing headings and the like) are generally just fine to store in a float even out to immense distances. Your relative error stays in a controlled range.



So, there's not much reason to turn to doubles as a default. I'd consider that only if you have a very particular need, where you've computed the precision of floats won't cut it, and keep it contained to only the part of your game that actively needs it.






share|improve this answer









$endgroup$
















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "53"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );














    draft saved

    draft discarded
















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgamedev.stackexchange.com%2fquestions%2f175861%2fuse-floats-or-doubles-when-writing-mobile-games%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    6














    $begingroup$

    You'd be hard pressed to find a mobile GPU that could use doubles even if you wanted to, so that choice is pretty much made for you.



    There are only a few places where you might benefit from switching from single-precision floats in your game. Storing total elapsed time, or an absolute position several kilometers from the origin, are two examples of things you shouldn't try to store in a single-precision float, but that doesn't mean you need to use doubles necessarily. Integer types can handle these values just fine.



    A delta time value will usually be on the order of 16 milliseconds, so storing it in a single precision float gives you precision to about $2^-29$, which is down to the level of nanoseconds — ie. probably higher precision than you can signal your threads or graphics refresh anyway. Adding more precision here with a double is unlikely to improve your game in any measurable way. So you can store your total elapsed at high precision or using an integer type, compute your delta and convert to single-precision float once per frame, then use floats happily form there on.



    Similarly for positions. Even with a huge world, if you break it up into chunks less than 32 km across, then single precision floats can locate a position within a chunk to a precision of less than a millimetre. Relative offsets between objects (for computing headings and the like) are generally just fine to store in a float even out to immense distances. Your relative error stays in a controlled range.



    So, there's not much reason to turn to doubles as a default. I'd consider that only if you have a very particular need, where you've computed the precision of floats won't cut it, and keep it contained to only the part of your game that actively needs it.






    share|improve this answer









    $endgroup$



















      6














      $begingroup$

      You'd be hard pressed to find a mobile GPU that could use doubles even if you wanted to, so that choice is pretty much made for you.



      There are only a few places where you might benefit from switching from single-precision floats in your game. Storing total elapsed time, or an absolute position several kilometers from the origin, are two examples of things you shouldn't try to store in a single-precision float, but that doesn't mean you need to use doubles necessarily. Integer types can handle these values just fine.



      A delta time value will usually be on the order of 16 milliseconds, so storing it in a single precision float gives you precision to about $2^-29$, which is down to the level of nanoseconds — ie. probably higher precision than you can signal your threads or graphics refresh anyway. Adding more precision here with a double is unlikely to improve your game in any measurable way. So you can store your total elapsed at high precision or using an integer type, compute your delta and convert to single-precision float once per frame, then use floats happily form there on.



      Similarly for positions. Even with a huge world, if you break it up into chunks less than 32 km across, then single precision floats can locate a position within a chunk to a precision of less than a millimetre. Relative offsets between objects (for computing headings and the like) are generally just fine to store in a float even out to immense distances. Your relative error stays in a controlled range.



      So, there's not much reason to turn to doubles as a default. I'd consider that only if you have a very particular need, where you've computed the precision of floats won't cut it, and keep it contained to only the part of your game that actively needs it.






      share|improve this answer









      $endgroup$

















        6














        6










        6







        $begingroup$

        You'd be hard pressed to find a mobile GPU that could use doubles even if you wanted to, so that choice is pretty much made for you.



        There are only a few places where you might benefit from switching from single-precision floats in your game. Storing total elapsed time, or an absolute position several kilometers from the origin, are two examples of things you shouldn't try to store in a single-precision float, but that doesn't mean you need to use doubles necessarily. Integer types can handle these values just fine.



        A delta time value will usually be on the order of 16 milliseconds, so storing it in a single precision float gives you precision to about $2^-29$, which is down to the level of nanoseconds — ie. probably higher precision than you can signal your threads or graphics refresh anyway. Adding more precision here with a double is unlikely to improve your game in any measurable way. So you can store your total elapsed at high precision or using an integer type, compute your delta and convert to single-precision float once per frame, then use floats happily form there on.



        Similarly for positions. Even with a huge world, if you break it up into chunks less than 32 km across, then single precision floats can locate a position within a chunk to a precision of less than a millimetre. Relative offsets between objects (for computing headings and the like) are generally just fine to store in a float even out to immense distances. Your relative error stays in a controlled range.



        So, there's not much reason to turn to doubles as a default. I'd consider that only if you have a very particular need, where you've computed the precision of floats won't cut it, and keep it contained to only the part of your game that actively needs it.






        share|improve this answer









        $endgroup$



        You'd be hard pressed to find a mobile GPU that could use doubles even if you wanted to, so that choice is pretty much made for you.



        There are only a few places where you might benefit from switching from single-precision floats in your game. Storing total elapsed time, or an absolute position several kilometers from the origin, are two examples of things you shouldn't try to store in a single-precision float, but that doesn't mean you need to use doubles necessarily. Integer types can handle these values just fine.



        A delta time value will usually be on the order of 16 milliseconds, so storing it in a single precision float gives you precision to about $2^-29$, which is down to the level of nanoseconds — ie. probably higher precision than you can signal your threads or graphics refresh anyway. Adding more precision here with a double is unlikely to improve your game in any measurable way. So you can store your total elapsed at high precision or using an integer type, compute your delta and convert to single-precision float once per frame, then use floats happily form there on.



        Similarly for positions. Even with a huge world, if you break it up into chunks less than 32 km across, then single precision floats can locate a position within a chunk to a precision of less than a millimetre. Relative offsets between objects (for computing headings and the like) are generally just fine to store in a float even out to immense distances. Your relative error stays in a controlled range.



        So, there's not much reason to turn to doubles as a default. I'd consider that only if you have a very particular need, where you've computed the precision of floats won't cut it, and keep it contained to only the part of your game that actively needs it.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 7 hours ago









        DMGregoryDMGregory

        72.8k16 gold badges128 silver badges204 bronze badges




        72.8k16 gold badges128 silver badges204 bronze badges































            draft saved

            draft discarded















































            Thanks for contributing an answer to Game Development Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            Use MathJax to format equations. MathJax reference.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgamedev.stackexchange.com%2fquestions%2f175861%2fuse-floats-or-doubles-when-writing-mobile-games%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Invision Community Contents History See also References External links Navigation menuProprietaryinvisioncommunity.comIPS Community ForumsIPS Community Forumsthis blog entry"License Changes, IP.Board 3.4, and the Future""Interview -- Matt Mecham of Ibforums""CEO Invision Power Board, Matt Mecham Is a Liar, Thief!"IPB License Explanation 1.3, 1.3.1, 2.0, and 2.1ArchivedSecurity Fixes, Updates And Enhancements For IPB 1.3.1Archived"New Demo Accounts - Invision Power Services"the original"New Default Skin"the original"Invision Power Board 3.0.0 and Applications Released"the original"Archived copy"the original"Perpetual licenses being done away with""Release Notes - Invision Power Services""Introducing: IPS Community Suite 4!"Invision Community Release Notes

            Canceling a color specificationRandomly assigning color to Graphics3D objects?Default color for Filling in Mathematica 9Coloring specific elements of sets with a prime modified order in an array plotHow to pick a color differing significantly from the colors already in a given color list?Detection of the text colorColor numbers based on their valueCan color schemes for use with ColorData include opacity specification?My dynamic color schemes

            Ласкавець круглолистий Зміст Опис | Поширення | Галерея | Примітки | Посилання | Навігаційне меню58171138361-22960890446Bupleurum rotundifoliumEuro+Med PlantbasePlants of the World Online — Kew ScienceGermplasm Resources Information Network (GRIN)Ласкавецькн. VI : Літери Ком — Левиправивши або дописавши її