Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Dart

Idiom #270 Test for quiet or signaling NaN

Given a floating point number r1 classify it as follows:
If it is a signaling NaN, print "This is a signaling NaN."
If it is a quiet NaN, print "This s a quiet NaN."
If it is not a NaN, print "This is a number."

if (r1.isNaN) {
  print("This is a quiet NaN.");
} else {
  print("This is a number.");
}

Dart has no concept of signaling NaN. NaN are all quiet AFAIK.
use, intrinsic:: ieee_arithmetic
  character (len=:), allocatable :: msg
  if (ieee_support_nan(r1)) then
     if (ieee_class(r1) == ieee_quiet_nan) then
        msg = "This s a quiet NaN."
     else if (ieee_class(r1) == ieee_signaling_nan) then
        msg = "This is a signaling NaN."
     else
        msg = "This is a number."
     end if
  else
     msg = "NaNs are not supported."
  end if
  write (*,'(A)') msg

New implementation...
< >
tkoenig