• 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 /
This question was closed Feb 15, 2015 at 02:24 PM by meat5000 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by gameplay4all · Feb 15, 2015 at 01:49 PM · floatingpoint

Quick question: is 0.032342 * 2.04554356 more expensive than 0.03 * 2.046 ?

Well the title says it all actually.

But I need this for my GUI functionality, I want to make everything resolution independent. Don't worry I won't calculate it every OnGUI frame, I got that covered ;)

It goes against my feeling to think that the more number multiplication will be as cheap as the simple one. But then again, they are both based on 32 bit floats right?

Thank you for your time!

Comment
Add comment
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

1 Reply

  • Sort: 
avatar image
1
Best Answer

Answer by DaDonik · Feb 15, 2015 at 02:02 PM

They are both the same speed.

As you say yourself, both are 32bits, no matter what number you specify.

Even if you spefify a much to large number like 0.4234783217483174907381275178231, it will still be the same speed. The reason is that those numbers are constants and therefore the compiler will truncate them to fit the 32bits.

This will take place at compile time and therefore doesn't affect the execution speed of you game at all.

Comment
Add comment · Show 5 · Share
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 gameplay4all · Feb 15, 2015 at 02:12 PM 0
Share

Okay great! Thank you! :)

avatar image gameplay4all · Feb 15, 2015 at 02:14 PM 0
Share

Oh and btw, you said constants: Will it be different if it was Screen.height * 0.3243535 ? (Edit: made it "code text")

avatar image meat5000 ♦ · Feb 15, 2015 at 02:18 PM 0
Share

It's a question of precision, not speed.

avatar image DaDonik · Feb 15, 2015 at 02:22 PM 0
Share

It's still just a multiplication between two 32bit floats.

To put it into perspective, your PC won't need more than a few nanosecons to do such a multiplication. A single call to GameObject.Find() can take milliseconds...

You should not worry about multiplying values. It's kind of a very micro micro-optimization. =)

What could be worth mentioning is that a division takes much more time than a multiplication. So a 'valid' micro optimization would be to replace (Screen.Height / 2.0f) with (Screen.Height * 0.5f), which is indeed a couple of times faster.

To put it in a nutshell. Don't worry about basic math when program$$anonymous$$g =)

avatar image gameplay4all · Feb 15, 2015 at 02:49 PM 0
Share

Okay thanks, yeah I already came by that tip! Thanks anyway!

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

20 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

Related Questions

How do I initialize a float texture by script? 1 Answer

Why this prints (0, 0, 0): Debug.Log("" + ((new Vector3(1, 0, 0)) * 0.016f)); 1 Answer

Infinite runner world creation 2 Answers

Floating point correction 4 Answers

Float check not returning the right value. 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