Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Crayz · Mar 28, 2015 at 05:44 AM · floating point

Floating point determinism..

Hello folks, quick question about floating points. I know floating point numbers can be calculated differently on varying machines and operating systems though does this only apply to multiplication, division, etc? If a player clicks in a Vector3 location on the world, or I assign a unit to move to a Vector3 position in the world, are the XYZ float values potentially going to vary between machines as well? Or does it only apply to arithmetic?

edit: It seems like majority of the time Vector3 values are applied rounded to the nearest 10ths (20.3 etc), if my code remains that way should I even worry about determinism? Physics and collisions I'm sure will have some issues

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Huacanacha · Mar 28, 2015 at 06:23 AM 2
Share

Vector3 values are NOT rounded to a single decimal place. Vector.ToString() rounds to a single decimal place by default when formatting the string. Try `myVector.ToString("0.000000").

The precision of floating point arithmetic is predo$$anonymous$$antly dependent on the difference in magnitude between the two floating point numbers. The exponent part of the float indicates it's magnitude, and for a given exponent a floating point number will have a certain resolution, or the $$anonymous$$imum amount the float can change. As an example if you add 0.0001f to 1000000f the result is still 1000000f, because 0.0001 is less than the precision that can be represented by a float (32-bit IEEE) of that scale.

The $$anonymous$$imum precise significant digits that are guaranteed by a float is 6. Therefore if you know you are dealing with a score out of 20, for example, you are guaranteed precise arithmetic with up to 4 decimal places (2 significant digits left of the decimal, 4 after).

avatar image Glurth · Mar 28, 2015 at 01:19 PM 0
Share

Good comment by Huacanacha, but I'd like to add that if you compare two vectors in unity, it will declare them equal even if they are only "really close" to being equal. http://docs.unity3d.com/ScriptReference/Vector3-operator_eq.html

You can do the same where checking float numbers for equality by using the mathf.Approximately(float, float) method. (http://docs.unity3d.com/ScriptReference/$$anonymous$$athf.Approximately.html)

are the XYZ float values potentially going to vary between machines as well

Probably. In fact, I've seen values vary slightly from one session to the next on the SA$$anonymous$$E machine: Zero the first run, and some really small number like 6.745E-9 the next run.

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

22 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Hexadecimal String to Float 1 Answer

VR flight sim floating point fun 1 Answer

Floating Point Inaccuracies in Editor 0 Answers

Atmospheric Scattering Shader Glitch on Floating Origin Late Update 0 Answers

My character vibrates. 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges