• 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
Question by Tetrad · Sep 28, 2010 at 04:53 PM · iphonenan

Why is Mathf.Pow( <some float value>, <some value less than 1> ) returning NaN on iOS 4.2 beta?

I'm having a weird issue with people running iOS 4.2 beta (presumably on iPads).

The long and short of it is because this line of code that worked before now is returning zero:

percentageToWin = Mathf.Lerp( ( 1.0f / 3.0f ), .75f, Mathf.Pow( levelNumber / 85.0f, .333333f ) ); 

(Where percentageToWin is a float.)

I broke it down to this bit

Mathf.Pow( levelNumber / 85.0f, .333333f )

returning NaN. levelNumber is positive. I've searched for anything regarding Pow returning NaN, and haven't found any similar issues. This math is somewhat important to the balancing of our game, and I'm not sure how to work around it.

For reference, the game was compiled against Unity iPhone 1.7. I'm going to try it with Unity 3 to see if it goes away, but somehow I doubt it.

Has anybody seen any similar issues or have any solutions?

Comment

People who like this

0 Show 4
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 skovacs1 · Sep 28, 2010 at 06:30 PM 0
Share

If this problem only occurs on this beta OS, it's likely because it's a beta. Is it only this line that presents the problem or does it happen elsewhere? You're sure levelNumber is being assigned? You could always write your own Pow function. If you just want to do a root (yth root of x = x^(1.0/y)), you could just write a root function with Newton's Method or something, hardcoding whatever you can.

avatar image jjobby · Sep 28, 2010 at 08:17 PM 0
Share

If the Pow function is working correctly then I think that your Pow function will return NaN only when the first argument < 0 So, you should check and make sure that levelNumber is properly assigned. You may want to check if your variable is properly initialized too.

avatar image Tetrad · Sep 28, 2010 at 08:29 PM 0
Share

@slovacs1 there's another line of code that does a similar cube root calculation that also returns NaN for the pow. I'm sure my variable is being initialized; on pre-4.2 versions of the OS the math works as expected.

avatar image skovacs1 · Sep 29, 2010 at 08:53 PM 0
Share

I tested Pow through all relevant combinations, and as loginjjobby suggested, Pow returns NaN when the base is negative, but specifically only when the base is negative AND the exponent is a fraction. Since you are certain that levelNumber is positive and it only seems to happen on this beta OS, I would still look to the OS as the source. At this point, if you are 100% certain that levelNumber is positive, I can only suggest checking with Apple or writing your own cube root function (if you are only doing cube roots).

1 Reply

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by Tetrad · Oct 01, 2010 at 10:05 PM

So I made a test project with my current Unity iPhone 1.7 as well as the latest Unity 3.0 iPhone that is nothing more than a scene with the default camera and a script that does this:

void OnGUI()
{
    GUILayout.Label( Mathf.Pow( 8 / 35.0f, .333333f ).ToString() );
}

Running the app built with Unity 3.0 spits out the correct number. Running the app built with Unity iPhone 1.7 spits out NaN.

For now I'm just going to file a bug report and try to get our project built with the new version of Unity (which is going to be a pain because of all the project settings, etc).

Comment
starikcetin

People who like this

1 Show 0 · 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

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.

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

No one has followed this question yet.

Related Questions

altimeter gauge... 1 Answer

Is there a way to visually show the order in which geometry was rendered in your scene. 1 Answer

How to support Retina display 1 Answer

Unity iPhone app crashes on startup on iPhone3G but works fine on iPhone3GS, iPhone4 and iPad 3 Answers

Problem accessing vector properties 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