Floats

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Floats

Mateusz Grotek
How to write Floats to a file. Is using at:1 and at: 2 the only method
of doing it. If so, why there is no support for Float writing in streams?

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Floats

Levente Uzonyi-2
On Fri, 5 Nov 2010, Mateusz Grotek wrote:

> How to write Floats to a file. Is using at:1 and at: 2 the only method
> of doing it. If so, why there is no support for Float writing in streams?

If the file is binary, then you can use #nextWordsPutAll:. Here's an
example:

FileStream newFileNamed: 'BinaryFloatTest.txt' do: [ :file |
  file binary.
  file nextWordsPutAll: 1.2345 ].

It will store the words in big-endian format.
If the file is not binary, then you can use #printOn: or #storeOn::

FileStream newFileNamed: 'FloatTest.txt' do: [ :file |
  1.2345 printOn: file ].


Levente


>
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://lists.squeakfoundation.org/mailman/listinfo/beginners
>
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Floats

Mateusz Grotek
Levente Uzonyi pisze:

> On Fri, 5 Nov 2010, Mateusz Grotek wrote:
>
>> How to write Floats to a file. Is using at:1 and at: 2 the only method
>> of doing it. If so, why there is no support for Float writing in streams?
>
> If the file is binary, then you can use #nextWordsPutAll:. Here's an
> example:
>
> FileStream newFileNamed: 'BinaryFloatTest.txt' do: [ :file |
>     file binary.
>     file nextWordsPutAll: 1.2345 ].
>
> It will store the words in big-endian format.
> If the file is not binary, then you can use #printOn: or #storeOn::
>
> FileStream newFileNamed: 'FloatTest.txt' do: [ :file |
>     1.2345 printOn: file ].
>
>
> Levente
>
>

Thanks.

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners