writing a float into a file
in the past i have used systems which were using [fileout] and [filein] to store and recall integer numbers in either decimal or hexadecimal format.
it is pretty straight forward, except that decimal numbers will get "converted" into hex (when you look at it with a disk editor or text program) and must be converted back when reading from the file. (easy enough in max using sprintf, regexp, or a numberbox. i think even [i] will do it)
now i need to change this system to work with max-style 32 bit floating point numbers. how does that work?
somehow i fail to understand what i need to do to be able to store a float in a file. when i attempt to write 3050.0017 as LONG, it of course only stores 3050.
so how to split it into parts? so that it remains a float when you read it back in with [filein]? what is that what i am not seeing?
-110
No Javascript? No Java? No Pattrstorage? Max 4?
In my case, no [fileout].
It seems that Max doesn't understand [sprintf %a]…
Can't you split your float in two ints (with [regexp (-?\\d*).?(\\d*)] for example)?
no regexp either, but therefore [fileout]. :)
but i wouldnt mind moving this part (making floats writable) to OSX if that is the only chance. writing (in 4.1) is only required to produce the content, as long as there is filein in 7.3 all is good.
yeah maybe one should just split the number into before and after the comma and write it as 2 ints. (or as 4?) but that feels strange, and one is loosing some precision.
i was looking more to solve it with bitwise operators but it seems a nogo?
Afaik, binary operators convert (i.e. truncates) floats to ints.
[filein] is still in 7.3. This thread may be of some interest, but won't help the float->int conversion.
And what about a good old [* 100000000.] ;-) ? Not precise enough?
in many cases 7 digits would be enough. in others not.
somehow it is weird that you dont have access to the binary representation of floats.
and [tosymbol] cuts floats even further than the display correction ... to 4 digits behind the comma.
i think i want to store the binary represenation right as if it was hex.
it would require 8 bytes of space and if there are other data formats stored in the samew file i would eventually need to preeed it by 4 more bytes to announce it.
can you make me a simple [mxf] which outputs the binary digits as single numbers?
"1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, "
will it be possible anway?