Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for double precision floats #288

Closed
m4nu3lf opened this issue Apr 14, 2014 · 79 comments
Closed

Add support for double precision floats #288

m4nu3lf opened this issue Apr 14, 2014 · 79 comments

Comments

@m4nu3lf
Copy link
Contributor

m4nu3lf commented Apr 14, 2014

Since I need more number precision for my game, I tried to recompile the engine with REAL_T_IS_DOUBLE, however it doesn't work.

It seems like float have been used here and there in place of the abstract real_t type.
In the other hand b2ConvexDecomp::float32 is defined as real_t... and real_t can be a double precision float (float64). So it is quite confusing.

@reduz
Copy link
Member

reduz commented Apr 14, 2014

support for doubles was never completed, maybe one day..

On Mon, Apr 14, 2014 at 7:23 AM, m4nu3lf notifications@github.com wrote:

Since I need more number precision for my game, I tried to recompile the
engine with REAL_T_IS_DOUBLE, however it doesn't work.

It seems like float have been used here and there in place of the abstract
real_t type.
In the other hand b2ConvexDecomp::float32 is defined as real_t... and
real_t can be a double precision float (float64). So it is quite confusing.


Reply to this email directly or view it on GitHubhttps://github.com//issues/288
.

@akien-mga akien-mga changed the title Cannot compile with double precision Add support for double precision floats Oct 29, 2015
@akien-mga akien-mga added this to the Later milestone Oct 29, 2015
@akien-mga
Copy link
Member

akien-mga commented Nov 2, 2015

See also the proposed implementation in #334.

@akien-mga
Copy link
Member

That's planned for 3.0 AFAIK.

@akien-mga akien-mga added this to the 3.0 milestone Jul 19, 2016
@Marqin
Copy link
Contributor

Marqin commented Aug 19, 2016

real_t seems to be just typedef for float so it can be 64-bit, depending on your platform/compiler.

C++ standard:

There are three floating point types: float, double, and long double. The type double provides at least
as much precision as float, and the type long double provides at least as much precision as double. The
set of values of the type float is a subset of the set of values of the type double; the set of values of the type
double is a subset of the set of values of the type long double. The value representation of floating-point
types is implementation-defined. [ Note: This International Standard imposes no requirements on the accuracy
of floating-point operations; see also 18.3.2. — end note ] Integral and floating types are collectively called
arithmetic types. Specializations of the standard library template std::numeric_limits (18.3) shall specify
the maximum and minimum values of each arithmetic type for an implementation.

So if you want to be sure, you have to check:

std::assert( sizeof(float) == 4 && std::numeric_limits<float>::is_iec559 );

( this will work with C++98 ).

@bojidar-bg
Copy link
Contributor

Wasn't this fixed in 3.0 already?

@reduz
Copy link
Member

reduz commented Mar 11, 2017 via email

@reduz reduz modified the milestones: 3.1, 3.0 Aug 4, 2017
@reduz
Copy link
Member

reduz commented Aug 4, 2017

Not gonna be done for 3.0

@fire
Copy link
Member

fire commented Sep 2, 2017

What is the current status? What is working? What is missing? How much work is required to get this in?

@reduz
Copy link
Member

reduz commented Sep 2, 2017

I'm not completely sure what needs to be done for this feature (and adding a proper compilation flag for this) happens, but comes to mind:

  1. There is some support for using doubles in binary serialization, but it's probably not complete. files such as resouce_format_binary.cpp and marshalls.cpp would need to be checked and made sure that doubles are written (and read) in a binary compatible way.
  2. Variant needs to be tested for double support, as this would mean Vector2, Vector3, etc. are doubles so Variant is bigger
  3. Some third party libraries might need to be modified (I think probably not, but i'm not sure, If Bullet is added, i think it can also use btScalar as double)
  4. Need to check that everything works in VisualServer when using doubles
  5. As it is not possible to use doubles in GLSL, world coordinates in matrices will need to be somehow wrapped or clamped to avoid numerical precision errors. This is most likely the last step that needs to be done once everything works

If you or anyone else would like to do this, feel welcome :) It's quite some work but it would be awesome to get it to work

@Marqin
Copy link
Contributor

Marqin commented Sep 13, 2017

As it is not possible to use doubles in GLSL

Bzzzzt wrong @reduz. I've used them in my project few years ago.

You can check on OpenGL wiki. But I remember I had to use some extension for it on my card:

#extension GL_ARB_gpu_shader_fp64 : require

@fire
Copy link
Member

fire commented Sep 14, 2017

https://github.com/Hopetech/libSoftFloat

Emulated support for fp64 library.

@fire
Copy link
Member

fire commented Oct 20, 2017

I'll add a compilation flag called float and it'll have float=32 and float=64 as arguments. Hopefully we won't have to implement float=128 ;)

@Hopetech
Copy link

Hello godot dev,

I replayed to question about using libSoftFloat in your game engine: Hopetech/libSoftFloat#1
TL;DR: Yes, you can use it. But the amount of work is huge and the result will be slow.

Let me know if you have any questions.

@aaronfranke
Copy link
Member

I am also interested in double-precision floats in Godot. Please implement this if you can.

@NathanWarden
Copy link
Contributor

NathanWarden commented Oct 30, 2017

If this doesn't get completed, as a workaround you'll be able to keep track of double precision floats in C# (and I believe in C++ also) for scripting. For instance, if it's for something like avoiding jittery movement for large scale (planetary sized) games then keeping track of x,y,z as doubles then converting them to floats when setting the position usually does a good job. It's not ideal, but it's an option.

@aaronfranke
Copy link
Member

aaronfranke commented Nov 15, 2017

@fire 128-bit? Well, that depends on what kind of games you expect Godot to power.

  • 32-bit floats have 6-7 decimal digits of accuracy, so if you aim for millimeter-precision, the play area is limited to just a few kilometers. This is incredibly restrictive, and means any large scale game is forced to use relative positioning, which is a pain especially for multiplayer games.

  • 64-bit floats have 15-16 decimal digits of accuracy, so if you aim for millimeter-precision, the play area is limited to a few billion kilometers, or a few terameters. This is accurate enough to have non-relative positioning on planets, but not beyond solar systems (Neptune is about 5 Tm orbital radius). For universe scale games, it could be useful to have 128-bit floats.

  • 128-bit floats have 33 decimal digits of accuracy, so if you aim for micrometer-precision, the play area is limited to a few septillion kilometers, or thousands of yottameters. This is almost exactly the estimated diameter of the observable universe. In other words, 256-bit floats are never needed :) But also, very few pieces of harwdare and programming languages support 128-bit floats.

@realkotob
Copy link
Contributor

Since the float in GDScript is now 64bit on the master branch, is this resolved?

@aaronfranke
Copy link
Member

aaronfranke commented Feb 27, 2020

@asheraryam No, it is not resolved. float in GDScript has been 64-bit double-precision for years, the issue is with having core types (like Vector3) and other CPU-side math done with doubles.

I have a PR here: #21922

@blaeberry
Copy link

@aaronfranke You mention CPU-side, but what about GPU-side? I'm working on shaders for my game and I'm noticing some issues with very small floating point values being rounded down to zero...

@Calinou
Copy link
Member

Calinou commented Mar 6, 2020

@blaeberry As far as I know, using FP64 (= double precision) in shaders is ill-advised in a game engine. This is because FP64 can be very slow on consumer-grade GPUs. 64-bit floating point performance is intentionally crippled on such GPUs, to incite professionals to buy much more expensive professional-grade GPUs.

How do other engines typically handle this? I'm curious to see how they do it 🙂

@0x0177b11f
Copy link

@blaeberry As far as I know, using FP64 (= double precision) in shaders is ill-advised in a game engine. This is because FP64 can be very slow on consumer-grade GPUs. 64-bit floating point performance is intentionally crippled on such GPUs, to incite professionals to buy much more expensive professional-grade GPUs.

How do other engines typically handle this? I'm curious to see how they do it 🙂

There is a trick to bypass this problem.Although we use FP64, we can convert the coordinate system from world space to the camera-relative coordinate system when calculating animation and final rendering, so that we will not use expensive FP64 in shaders

@nxrighthere
Copy link

I've started a similar discussion on Unity forums. You might find some valuable information there.

@aaronfranke
Copy link
Member

As part of an effort to move all feature proposals to the godot-proposals repo, I wrote this proposal which directly supersedes this issue. It significantly summarizes and elaborates on the discussion about double support in Godot. As such, this issue will now be closed.

@3top1a
Copy link

3top1a commented Aug 29, 2020

Will 4.0 support 128-bit floats/doubles?

@Calinou
Copy link
Member

Calinou commented Aug 29, 2020

@3top1a There are no plans to add 128-bit (or arbitrary precision) integers or floats to GDScript, but this could be done by a third-party module.

@fire
Copy link
Member

fire commented Aug 29, 2020

Godot does have a fixed point 128bit doubles implementation, but no plans to add to gdscript.

Edited:
https://github.com/godotengine/godot/blob/988dd09047aab9f33b172cfb140d4081885c7083/thirdparty/misc/r128.h

@3top1a
Copy link

3top1a commented Oct 12, 2020

@fire well yes, but that's a 128-bit integer.
What about a 128-bit float?

(in the core since I'm coding in c++ modules now)

@fire
Copy link
Member

fire commented Oct 12, 2020

I was imprecise, its 64.64 float. It is not a 128 bit integer.

@akien-mga
Copy link
Member

For the record (as this is referenced in various issues), this has been implemented in 4.0 (see godotengine/godot-proposals#892 for details).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests