How to use the isnan() method in Julia?
Overview
The isnan(x) method checks whether or not the given value is
Syntax
isnan(f) -> Bool
The Julia isnan function
Argument(s)
x: This is the value that is to be checked.
Return value
This method returns true if the provided value is NaN. Otherwise, it returns false.
Code
The code below demonstrates the use of the isnan() method:
## find isnan of 0 / 0println( "isnan(0 / 0) => $(isnan(0 / 0))")## find isnan of NaNprintln( "isnan(NaN) => $(isnan(NaN))")## find isnan of 10println( "isnan(10) => $(isnan(10))")
Explanation
- Line 2: We use the
isnan()method with(0/0)as an argument. Dividing zero by0produces aNaNvalue. Therefore, theisnan(0/0)returnstrue.
- Line 5: We use the
isnan()method withNaNas an argument. Theisnan(NaN)returnstrue.
- Line 8: We use the
isnan()method with10as an argument. Theisnan(10)returnsfalsebecause10is a finite value and not aNaNvalue.