ShortFloat.st
changeset 14924 7115c6830ed8
parent 14922 30546dbb18c6
child 14931 0de2fc03f23a
child 18037 4cf874da38c9
equal deleted inserted replaced
14923:d17a1105f17c 14924:7115c6830ed8
   344 
   344 
   345 !ShortFloat class methodsFor:'binary storage'!
   345 !ShortFloat class methodsFor:'binary storage'!
   346 
   346 
   347 readBinaryIEEESingleFrom:aStream
   347 readBinaryIEEESingleFrom:aStream
   348     "read a float value from the binary stream, aStream,
   348     "read a float value from the binary stream, aStream,
   349      interpreting the next bytes as an IEEE formatted 4-byte float"
   349      interpreting the next bytes as an IEEE formatted 4-byte float.
       
   350      The bytes are read in the native byte order (i.e.lsb on intel)"
   350 
   351 
   351     |f|
   352     |f|
   352 
   353 
   353     f := ShortFloat basicNew.
   354     f := ShortFloat basicNew.
   354     self readBinaryIEEESingleFrom:aStream into:f.
   355     self readBinaryIEEESingleFrom:aStream into:f.
   361 !
   362 !
   362 
   363 
   363 readBinaryIEEESingleFrom:aStream into:aFloat
   364 readBinaryIEEESingleFrom:aStream into:aFloat
   364     "read a float value from the binary stream, aStream,
   365     "read a float value from the binary stream, aStream,
   365      interpreting the next bytes as an IEEE formatted 4-byte float.
   366      interpreting the next bytes as an IEEE formatted 4-byte float.
   366      The bytes are read in the nativ byte order (i.e.lsb on intel)"
   367      The bytes are read in the native byte order (i.e.lsb on intel)"
   367 
   368 
   368     ^ self readBinaryIEEESingleFrom:aStream into:aFloat MSB:(UninterpretedBytes isBigEndian)
   369     ^ self readBinaryIEEESingleFrom:aStream into:aFloat MSB:(UninterpretedBytes isBigEndian)
   369 
   370 
   370     "Modified: / 23-08-2006 / 16:01:52 / cg"
   371     "Modified: / 23-08-2006 / 16:01:52 / cg"
   371 !
   372 !
   400     "Modified: / 23-08-2006 / 16:01:52 / cg"
   401     "Modified: / 23-08-2006 / 16:01:52 / cg"
   401 !
   402 !
   402 
   403 
   403 storeBinaryIEEESingle:aFloat on:aStream
   404 storeBinaryIEEESingle:aFloat on:aStream
   404     "store aFloat as an IEEE formatted 4-byte float
   405     "store aFloat as an IEEE formatted 4-byte float
   405      onto the binary stream, aStream"
   406      onto the binary stream, aStream.
       
   407      The bytes are written in the native byte order (i.e.lsb on intel)"
       
   408 
       
   409     self storeBinaryIEEESingle:aFloat on:aStream MSB:(UninterpretedBytes isBigEndian).
       
   410 !
       
   411 
       
   412 storeBinaryIEEESingle:aFloat on:aStream MSB:msb
       
   413     "store aFloat as an IEEE formatted 4-byte float
       
   414      onto the binary stream, aStream.
       
   415      If msb is true, the stream bytes are written most-significant-first."
   406 
   416 
   407     |float|
   417     |float|
   408 
   418 
   409     float := aFloat asShortFloat.
   419     float := aFloat asShortFloat.
   410 
   420 
   413      (to date all machines where ST/X is running on use
   423      (to date all machines where ST/X is running on use
   414       IEEE float format. Need more here, when porting ST/X to 370's)
   424       IEEE float format. Need more here, when porting ST/X to 370's)
   415     "
   425     "
   416     self isIEEEFormat ifFalse:[self error:'unsupported operation'].
   426     self isIEEEFormat ifFalse:[self error:'unsupported operation'].
   417 
   427 
   418     UninterpretedBytes isBigEndian ifFalse:[
   428     (UninterpretedBytes isBigEndian == msb) ifFalse:[
   419 	"swap the bytes"
   429         "swap the bytes"
   420 	4 to:1 by:-1 do:[:i |
   430         4 to:1 by:-1 do:[:i |
   421 	    aStream nextPut:(float basicAt:i).
   431             aStream nextPut:(float basicAt:i).
   422 	].
   432         ].
   423 	^ self
   433         ^ self
   424     ].
   434     ].
   425     1 to:4 do:[:i |
   435     1 to:4 do:[:i |
   426 	aStream nextPut:(float basicAt:i).
   436         aStream nextPut:(float basicAt:i).
   427     ]
   437     ]
   428 
   438 
   429     "not part of libboss, as this is also used by others (TIFFReader)"
   439     "not part of libboss, as this is also used by others (TIFFReader)"
   430 
   440 
   431     "Modified: / 23-08-2006 / 16:01:55 / cg"
   441     "Modified: / 23-08-2006 / 16:01:55 / cg"
  1857 ! !
  1867 ! !
  1858 
  1868 
  1859 !ShortFloat class methodsFor:'documentation'!
  1869 !ShortFloat class methodsFor:'documentation'!
  1860 
  1870 
  1861 version
  1871 version
  1862     ^ '$Header: /cvs/stx/stx/libbasic/ShortFloat.st,v 1.120 2013-03-20 15:01:14 cg Exp $'
  1872     ^ '$Header: /cvs/stx/stx/libbasic/ShortFloat.st,v 1.121 2013-03-20 15:42:38 cg Exp $'
  1863 !
  1873 !
  1864 
  1874 
  1865 version_CVS
  1875 version_CVS
  1866     ^ '$Header: /cvs/stx/stx/libbasic/ShortFloat.st,v 1.120 2013-03-20 15:01:14 cg Exp $'
  1876     ^ '$Header: /cvs/stx/stx/libbasic/ShortFloat.st,v 1.121 2013-03-20 15:42:38 cg Exp $'
  1867 ! !
  1877 ! !
  1868 
  1878