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
2
Question by khellstr · Sep 30, 2013 at 09:06 AM · mathsignexponential

Keep sign when exponentiating variable?

Is there some function that keeps variables sign after exponentiating it or is this best way to do it:

 Mathf.Pow(speedLocal.x, 2)*Mathf.Sign(speedLocal.x)
Comment
Add comment · Show 3
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 KiraSensei · Sep 30, 2013 at 09:09 AM 0
Share

I think it is a nice way to do it :)

avatar image Owen-Reynolds · Oct 01, 2013 at 06:18 PM 1
Share

I was wondering why anyone would want to do this. $$anonymous$$aybe some special type of math everyone knows but me? But from OPs comments below, not really a math guy, so I feel more confident writing this:

If you think you need to square a number and keep the sign, recheck the math. You probably don't.

avatar image Hoeloe · Oct 01, 2013 at 09:33 PM 0
Share

There are obscure cases when you might need to, but for the most part, you don't.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Hoeloe · Sep 30, 2013 at 09:12 AM

That is the best way to do it. Squaring any number will necessarily make it positive (as will any even power), so you will lose the information. Getting and multiplying by the sign using a built-in method is the most appropriate and fastest method.

Comment
Add comment · Show 8 · 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 khellstr · Sep 30, 2013 at 11:49 AM 0
Share

Thanks

I was just wondering if there is some build in method like this:

 $$anonymous$$athf.Pow2Sign(speedLocal.x) 
 =
 $$anonymous$$athf.Pow(speedLocal.x, 2)*$$anonymous$$athf.Sign(speedLocal.x)

cause there are lot of things in physics that are related to square of some other value. And usually it's needed to keep signs so vectors go right direction.

avatar image Owen-Reynolds · Sep 30, 2013 at 03:39 PM 0
Share

re: square ... keep signs so vectors go right direction

Not as much as you'd think. The sign is usually added back naturally. Take normalizing. In x_n = x/(sqrt(x*x+y*y)) you want x and y squared to be always positive, so you always get a positive length. The sign of x is added back in that first "x divided by".

avatar image khellstr · Sep 30, 2013 at 11:52 PM 0
Share

I'm an artist, I refuse to understand Logarithms

avatar image Hoeloe · Oct 01, 2013 at 12:03 AM 0
Share

No-one mentioned logarithms at all, and if you ever want to be at all successful at program$$anonymous$$g, mathematics of all form is necessary.

avatar image khellstr · Oct 01, 2013 at 12:28 AM 0
Share

"In x_n" << darn, I read that like ln x... something and stopped reading. If someone mentions Neper or natural logarithm I will refuse to understand.

Show more comments

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

17 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

Related Questions

Unity Exponentiation question. 1 Answer

Increase the speed but keep the spacing between the objects 1 Answer

Math exponential number conversion 1 Answer

Why does Mathf.Sign(0.0f) return 1? 2 Answers

Matrix Multiplication, Standard Deviant and More usefull methods 2 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