floating point number conversion (exponent)

frank desben's icon

Hi all,

wow, I just see the post was corrupt. Now I correct it again.

I have a text file with float numbers in the format as below - namely with the exponent at the end. I would like to parse / transform these values so I can work with them in max like the other regular floats.

Does somebody have an idea?

All the best, Frank

2.407984776842665653e+00 , 1.026246200945576947e-01, -4.199148397133440902e-01, 1.070413891257866013e+00, 3.143613106199010243e-01, 1.098853903730688808e+00, -2.615247118173250840e+00, -2.168776277283647858e+00, 2.015239213655302564e+00, 6.651139564676828986e-01, -2.783131615676956994e+00, 4.478815897509044186e-01, -1.752832527393801965e-01, 1.124858962910230686e-01, -9.191722312541685813e-01, 2.202444664313242040e+00, -3.014634240577966917e+00, -2.014694117463378120e-01, 1.832255260807410302e+00, -2.240739517056415497e+00, -7.013570608432873055e-01, -3.645136418459745009e+00, 3.214913178261057158e+00, 7.574115179775657847e-01

frank desben's icon

wow, I just see the post was corrupt. Now I correct it again.

Holland Hopson's icon

Regexp seems like a good place to start. I found this post https://codereview.stackexchange.com/questions/8428/python-program-for-converting-scientific-notation-to-fixed-point added extra slashes to make it Max-friendly. It's not all the way there, but maybe you can build on it. I'm not a regex wizard (only learn enough to solve the problem at hand...) and there are clearly problems: for example, the leading - is stripped.

Max Patch
Copy patch and select New From Clipboard in Max.

volker böhm's icon

It's probably easiest to use a language that can handle scientific notation natively to dump the data into max - e.g. javascript. Create a literal array with your data and bang it out. Something like this should do it:


var data = [2.407984776842665653e+00, 1.026246200945576947e-01, -4.199148397133440902e-01, ..., and_so_on, ...];

function bang() {
    outlet(0, data);
}

Roman Thilenius's icon


wolfram alpha takes arrays, too, but i think there is a limit of 10 or so.

https://www.wolframalpha.com/input/?i=2.407984776842665653e%2B00%2C+1.026246200945576947e-01