aboutsummaryrefslogtreecommitdiff
path: root/binary.tcl
diff options
context:
space:
mode:
authorSteve Bennett <steveb@workware.net.au>2013-08-11 10:02:22 +1000
committerSteve Bennett <steveb@workware.net.au>2013-08-19 21:15:56 +1000
commitab939f33357c7ee7825aff0ecf51f3f77b0dde30 (patch)
tree65440129d292272054d4e2cea454ca2c755d5ca8 /binary.tcl
parent37df8a6098f0b7876fade21fccb08023b2f978d3 (diff)
downloadjimtcl-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.tcl16
1 files changed, 12 insertions, 4 deletions
diff --git a/binary.tcl b/binary.tcl
index bb99dd6..33f4cd3 100644
--- a/binary.tcl
+++ b/binary.tcl
@@ -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}
}