nan

nan(f)

Returns NaN (not-a-number) of the floating point type f or of the same floating point type as f

Examples

In the Julia programming language, the function nan(f)

Returns NaN (not-a-number) of the floating-point type f or of the same floating-point type as f.

julia> nan(Float64)
NaN

julia> nan(Float32)
NaNf0

Here are some common examples of its use:

  1. Create a NaN value of type Float64:

    julia> x = nan(Float64)
    NaN
  2. Create a NaN value of type Float32:

    julia> y = nan(Float32)
    NaNf0
  3. Use the input's type to generate NaN:

    julia> z = 2.5
    2.5
    
    julia> w = nan(typeof(z))
    NaN

Common mistake example:

julia> x = nan(Int64)
ERROR: InexactError: trunc(Int64, NaN)

In this example, the nan function is being used with an unsupported type. The nan function is specifically designed for floating-point types, and using it with other types, like Int64, will result in an error. Make sure to use nan with appropriate floating-point types.

See Also

digits, inf, isdigit, iseven, isfinite, isless, islower, isnumber, isodd, isprime, isqrt, issorted, issubnormal, isxdigit, nan,

User Contributed Notes

Add a Note

The format of note supported is markdown, use triple backtick to start and end a code block.

*Required Field
Details

Checking you are not a robot: