Logo

Programming-Idioms

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.
Implementation
Ruby

Implementation edit is for fixing errors and enhancing with metadata. Please do not replace the code below with a different implementation.

Instead of changing the code of the snippet, consider creating another Ruby implementation.

Be concise.

Be useful.

All contributions dictatorially edited by webmasters to match personal tastes.

Please do not paste any copyright violating material.

Please try to avoid dependencies to third-party libraries and frameworks.

Other implementations
    use, intrinsic :: ieee_arithmetic, only: IEEE_Value, IEEE_QUIET_NAN, IEEE_SIGNALING_NAN
 a = ieee_value (a, IEEE_QUIET_NAN)
 b = ieee_value (b, IEEE_SIGNALING_NAN)
a = float('nan')
math
a := NaN;
let a: f64 = f64::NAN;
use feature 'say';
# built-in support (use POSIX not needed))
my $a = 'nan';

say $a;
# prints string value: nan

say 0 + $a;
# prints numeric value: NaN

use feature 'say';
use POSIX qw(:nan_payload nan isnan issignaling getpayload);
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
local a = 0/0