Jump to content

check if a value is NaN


IIYAMA

Recommended Posts

  • Moderators
Posted

What is the best way to detect a NaN value?

I found this: (but it doesn't seems to work, I still get warnings in the rest of the code when I check it like that)

function isnan(x) return x ~= x end 

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

Posted

This should work fine.

  
-- Source: [url=http://stackoverflow.com/questions/12102222/how-to-test-for-1-ind-indeterminate-in-lua#answer-12103118]http://stackoverflow.com/questions/1210 ... r-12103118[/url] 
local function isnan(x) 
    if (x ~= x) then 
        return true 
    end 
    if type(x) ~= "number" then 
       return false 
    end 
    if tostring(x) == tostring((-1)^0.5) then 
        return true 
    end 
    return false 
end 

Do you require a paid scripter? Contact me! (Unavailable) Currently I am experienced in Lua, PHP, HTML, CSS, SQL and JS.

Developer and owner of

https://projectbea.st - Project Beast
  • Moderators
Posted

thx, I will try.

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

  • Moderators
Posted

This function returns somtimes NaN https://wiki.multitheftauto.com/wiki/Ge ... ldPosition in combination with https://wiki.multitheftauto.com/wiki/GetPedTargetEnd

There is not much I can do about it Afaik. Also I get sometimes NaN values when I am playing around with vectors of my serverside bullet collision system. (checking the distance between 2 lines in 3D)

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...