Given two floating point variables a and b, set a to a to a quiet NaN and b to a signalling NaN. Use standard features of the language only, without invoking undefined behavior.
a = ieee_value (a, IEEE_QUIET_NAN)
b = ieee_value (b, IEEE_SIGNALING_NAN)
local a = 0/0
Lua does not differentiate between quiet or signalling NaN's.
math
a := NaN;
Pascal makes no effort to distinguish signaling NaNs from quiet NaNs, and behavior for signaling NaNs remains unspecified.
use feature 'say';
# built-in support (use POSIX not needed))my $a = 'nan';
say $a;
# prints string value: nansay0 + $a;
# prints numeric value: NaN
Part 1: built-in support. You can assign 'nan' to a scalar variable and perl will create a dualvar that has 'nan' as it's string value and NaN as it's numeric value. Adding 0 to $a forces numeric context, yielding NaN.
use feature 'say';
use POSIX qw(:nan_payload nan isnan issignaling getpayload);
say isnan($a) ? 'true' : 'false';;
# prints truesay $a == $a ? 'true' : 'false';
# prints false because NaN does not equal NaNsay issignaling($a) ? 'true' : 'false';
# prints false because $a is non-signalingmy $b = nan(999); # set to signaling NaN by adding a payloadsay $b;
# prints NaNsay getpayload($b);
# prints 999
Part 2: Not built-in, but the core POSIX module is included in the perl installation and provides a lot of other functionality for NaN as well as Inf.
Python makes no effort to distinguish signaling NaNs from quiet NaNs, and behavior for signaling NaNs remains unspecified. Typical behavior is to treat all NaNs as though they were quiet.
say isnan($a) ? 'true' : 'false';;
# prints true
say $a == $a ? 'true' : 'false';
# prints false because NaN does not equal NaN
say issignaling($a) ? 'true' : 'false';
# prints false because $a is non-signaling
my $b = nan(999); # set to signaling NaN by adding a payload
say $b;
# prints NaN
say getpayload($b);
# prints 999