diff options
author | Steve Bennett <steveb@workware.net.au> | 2013-08-11 10:02:22 +1000 |
---|---|---|
committer | Steve Bennett <steveb@workware.net.au> | 2013-08-19 21:15:56 +1000 |
commit | ab939f33357c7ee7825aff0ecf51f3f77b0dde30 (patch) | |
tree | 65440129d292272054d4e2cea454ca2c755d5ca8 /binary.tcl | |
parent | 37df8a6098f0b7876fade21fccb08023b2f978d3 (diff) | |
download | jimtcl-ab939f33357c7ee7825aff0ecf51f3f77b0dde30.zip jimtcl-ab939f33357c7ee7825aff0ecf51f3f77b0dde30.tar.gz jimtcl-ab939f33357c7ee7825aff0ecf51f3f77b0dde30.tar.bz2 |
Add floating point support for [binary]
From work by Vadim Zborovskii
Signed-off-by: Steve Bennett <steveb@workware.net.au>
Diffstat (limited to 'binary.tcl')
-rw-r--r-- | binary.tcl | 16 |
1 files changed, 12 insertions, 4 deletions
@@ -77,7 +77,7 @@ proc "binary format" {formatString args} { return -code error "bad field specifier \"$t\"" } - # A scalar type + # A scalar (integer or float) type lassign $::binary::scalarinfo($t) type convtype size prefix set value [binary::nextarg args] @@ -191,7 +191,7 @@ proc "binary scan" {value formatString {args varName}} { if {![info exists ::binary::scalarinfo($t)} { return -code error "bad field specifier \"$t\"" } - # A scalar float type + # A scalar (integer or float) type lassign $::binary::scalarinfo($t) type convtype size prefix set var [binary::nextarg varName] @@ -258,13 +258,21 @@ set binary::scalarinfo { H {hex be 4 0x} b {bin le 1} B {bin be 1} + r {float fle 32} + R {float fbe 32} + f {float fhost 32} + q {float fle 64} + Q {float fbe 64} + d {float fhost 64} } set binary::convtype { be intbe le intle + fbe floatbe + fle floatle } if {$::tcl_platform(byteOrder) eq "bigEndian"} { - array set binary::convtype {host intbe} + array set binary::convtype {host intbe fhost floatbe} } else { - array set binary::convtype {host intle} + array set binary::convtype {host intle fhost floatle} } |