Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by RKSlither · Feb 17, 2016 at 11:17 AM · c#mathfloatinfinity

Unity Infinity Math Result

 float stunResist = 0;
 
 void Start(){
 GetHit(0.80f);
 }
 
 void GetHit(float stunChance){
 stunChance = stunChance / stunResist;
 }


now i am no math genius but isn't the result supposed to be 0.80 and unity is giving me infinity result. All i want to know is why?

Edit also i should note yes you can not divide by 0 but what if the default is 0 how do you pass this then?

i should not have to write extra logic for this to be accepted this should already be in the basics of the game engine to notice the 0 result and to just pass the division in that case so that no matter what the result comes out 0,80 even if the divide number is 0.

Edit #2: Well obviously nobody cares enough about this to answer or comment so a mod can close this, I just don't know why something as basic as making a division be forgotten if it is 0 is not in the unity engine already i mean the game engine know what a division is already so its seems easy to do something like.

 if(dividing number is 0){
 keep result and forget the division
 }

so in my case unity would know the dividing number is 0 and just keep the 0.80 as the result with out touching it until the divided number was changed in the future by future code.

Comment
Add comment · Show 5
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 Glurth · Feb 17, 2016 at 03:10 PM 0
Share

The problem with doing the check every single time is that takes processing power. Consider you in the midst of some nested loops that runs very often: in this case even a single comparison operation can add significantly to the total processing time. This is the same reason you need to check that your objects are not equal to null, before you use them. Personally, I'm surprised that didn't generate a run time error: Division by zero is a very low level CPU exception/interrupt.

Edit: you asked about default values- If a number is used as a deno$$anonymous$$ator, I usually set the default value to 1.0f (aka, do nothing). It is also possible to store the number x as 1/x, and do a multiplication rather than division at operation-time. (this second option makes those divide by zero's more obvious.)

avatar image Nerevar · Feb 17, 2016 at 04:00 PM 1
Share

Stun resist should be 1 by default then. And above 1 when you want to add resistance. And yeah X/0 = infinity in math...

avatar image Glurth Nerevar · Feb 17, 2016 at 04:20 PM 0
Share

Not really of practical program$$anonymous$$g importance, but:

Technically, in math, division by zero yields an UNDEFINED value, not infinity: https://en.wikipedia.org/wiki/Division_by_zero However, it is accurate to state that: for Y=Z/X, as X approaches 0, Y approaches infinity. (sorry to be nit-picky)

avatar image Nerevar Glurth · Feb 17, 2016 at 04:42 PM 1
Share

True :=) I just did not want to introduce the idea limits. But to be even more precise a decimal float is never really zero so my guess is that unity engine can't handle the result of the division of such a small number close to 0.In that case ins$$anonymous$$d of throwing a stack overflow it says infinity (pure hypothesis). I also think that the engine behind the scene is working with double (that actually supports infinity).

Stun resist should be 1 by default then. And above 1 when you want to add resistance.

do you agree?
Show more comments

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

105 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 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 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 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 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

Rotate a Vector2 around the Z axis on a mathematical level 1 Answer

float value carries over from runtime causing issues + it doesnt update in the inspector 0 Answers

Calculate arithmetic problem from text 1 Answer

Unity problems with bigger number than 10^39 2 Answers

How do I convert speed and heading to a vector? 3 Answers


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