When I import data from a .dat file, V11.3 emits the message: is too small to represent as a normalized machine number; precision may be lost.

How can I close the display or replace the offending number with 0.?

Here is my code:

ReadList[OpenRead["C:\\Users\\px\\Desktop\\1.DAT"], Real]

I know Import will not show this warning, but its speed is slow.

  • 3
    $\begingroup$ You can use Quiet[] of course, but this just hides problems. Can you post a sample .dat file that is triggering this warning? $\endgroup$ – J. M. will be back soon Mar 31 at 13:48
  • $\begingroup$ Except for you, no one else has the file 1.DAT. How do you expect to get help if you don't post that file? $\endgroup$ – J. M. will be back soon Mar 31 at 14:06
  • $\begingroup$ @J. M. is slightly pensive Sorry, I don't ’how to upload attachments $\endgroup$ – xin pei Mar 31 at 14:08
  • $\begingroup$ Copy the contents of 1.DAT, go to Pastebin, post the contents there, and then post a link here. $\endgroup$ – J. M. will be back soon Mar 31 at 14:09
  • 3
    $\begingroup$ $MinMachineNumber is 2.22507*10^-308 (Windows 10, Mathematica 10.4). Your dataset has 9 out of 15580 numbers between 1.094829709000000*10^-318and 1.319006165000000*10^-316. If it is appropriate you could modify the data or maybe the following would be helpful: mathematica.stackexchange.com/questions/161031/…. $\endgroup$ – JimB Mar 31 at 14:48

If we multiply the exponents by, say, 10^20, then the data will fall within machine-precision range. There may be a more natural way to rescale (based on units, for instance), but we have only raw numbers to work with. (One can also convert the mantissas to arbitrary-precision number before multiplying by the exponent; however, I suspect that machine numbers are to be preferred.)

data = #1*10.^(#2 + 20) & @@ Transpose[
      StringSplit[#, "E"] & /@
       (raw = Import["https://pastebin.com/raw/gkB6zKVC", "Table", "Numeric" -> False])
     {2, 3, 1}]; // AbsoluteTiming
(*  {0.216465, Null}  *)

Some checks. There are some rounding differences between the imported data and the converted data.

  {76, 205}
  {76, 205}

Quiet@Block[{Indeterminate = 0},
  Import["https://pastebin.com/raw/gkB6zKVC", "Table"]/data // 
    Flatten // DeleteDuplicates
{0, 1.0000000000000001`*^-20, 1.0000000000000002`*^-20, 
    9.999999999999998`*^-21,  9.999999996284607`*^-21, 
    9.99999999915014`*^-21,   1.0000000000496418`*^-20, 
    1.0000000001289331`*^-20, 1.0000000002912905`*^-20, 
    1.000000000045069`*^-20,  9.999999995966217`*^-21, 
    1.0000000002256684`*^-20, 9.99999999965454`*^-21} 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.