1
$\begingroup$

When I try to import data with ReadList from a file containing very small numbers (~10^-318), positive data is handled well, whereas negative data casts an error:

"General::digit: "Digit at position 1 in !(\"-5.5137726\") is too large to be used in base 10."

The actual number in the file is -5.5137726e-318. It works fine for positive numbers, or smaller exponents. I know Import handles well the data, but wanted to use ReadList since its ~10 times faster. I also tried truncating the data in the text file (in case it was a precission problem), to no avail.

Using Mathematica 9.0.1 with Windows 7 Home Premium.

EDIT

Here is a sample of the data; its a list of the components of a 3D vector:

   124000            0            0
   124000 -5.5137726e-318 4.9011312e-318
   124000 -6.0038857e-317 -8.1481306e-317
   124000 8.7730249e-316 -6.6839177e-316
   124000 7.2959464e-315 9.1491867e-315
   124000 -9.4449699e-314 7.9490222e-314
   124000 -8.6193193e-313 -9.6701831e-313
   124000 9.823401e-312 -9.2906591e-312
   124000 9.9467387e-311 9.9039764e-311
   124000 -9.9117558e-310 1.0571814e-309
   124000 -1.1151265e-308 -9.8472336e-309
   124000 9.7116423e-308 -1.1671959e-307
   124000 1.2122543e-306 9.5070421e-307
   124000 -9.2363979e-306 1.2493669e-305

I ran the processing code again, and it seems now that any numbers (positive or negative) smaller than 2e-318 ($MinMachineNumber) give the same error.

The Import command automatically truncates small numbers to 0:

{124000, 0, 0}, {124000, 0., 0.}, {124000, 0., 0.}, {124000, 0., 0.}, {124000, 0., 0.}, 
{124000, 0., 0.}, {124000, 0., 0.}, {124000, 0., 0.}, {124000, 0., 0.}, {124000, 0., 0.}, 
{124000, 0., 0.}, {124000, 9.71164*10^-308, -1.1672*10^-307}, 
{124000, 1.21225*10^-306, 9.50704*10^-307},  {124000, -9.2364*10^-306, 1.24937*10^-305}

I was looking for an output in this way, but with ReadList.

$\endgroup$
0

1 Answer 1

1
$\begingroup$

You can do the following:

data = ReadList["filename.ext", {Word, Word, Word}];

Then a little post processing:

ToExpression@StringReplace[#, {"e" -> "*^"}] & /@ data

Mathematica graphics

$\endgroup$
2
  • $\begingroup$ Thanks, that works well. It performs faster than Import (65ms vs 145ms), although ReadList without postprocessing is still much faster (7ms). Is there a way to make mathematica read it as an arbitrary precision number, or to change $MinMachineNumber? $\endgroup$
    – Noel
    Mar 19, 2014 at 13:51
  • $\begingroup$ @NoelPerezGonzalez Well, there's no way to change $MinMachineNumber since it's based on your hardware. You will notice more speed up if your file is much larger, I think this is your best approach. $\endgroup$
    – RunnyKine
    Mar 19, 2014 at 13:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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