<div dir="ltr">I am working with a c++ generated floating point data stream that encodes certain events as NaN (not a number). When I try to print out this number, io_lib_format crashes.<div><br></div><div style><br></div>
<div style>Here is a [c++11] nif that creates a NaN:</div><div style><br></div>static ERL_NIF_TERM quiet_nan(ErlNifEnv* env, int, const ERL_NIF_TERM argv[])<br>{<br> double num = std::numeric_limits<double>::quiet_NaN();<br>
cerr << "quiet_nan: iostream prints num as " << num << endl;<br> return enif_make_double(env, num);<br>}<div><br></div><div><br></div><div>... and then when I run this interactively I get:<br>
<div><br></div><div><div>Erlang R15B01 (erts-5.9.1) [source] [smp:3:3] [async-threads:0]</div><div><br></div><div>Eshell V5.9.1 (abort with ^G)</div><div>1> channel_nif:quiet_nan().</div><div>quiet_nan: iostream prints num as nan</div>
<div> ** exception error: no case clause matching <<127,248,0,0,0,0,0,0>></div><div> in function io_lib_format:mantissa_exponent/1 (io_lib_format.erl, line 374)</div><div>
in call from io_lib_format:fwrite_g/1 (io_lib_format.erl, line 365)</div><div>2> </div></div></div><div><br></div><div><br></div><div style><br></div><div style>Expected behaviour is to just print "NaN" or something similar. For my use case I can work around this problem by just using binary representations.</div>
<div style><br></div><div style>For reference, there's a thread about inf and nan about 28 Feb 2012 that focuses on doing match with these numbers. (I do not want to do math, just move them around and print them without crashing)</div>
<div style><br></div><div style>Cheers,</div><div style>Dan.</div></div>