Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion float2IEEE numbers - 64 bit?
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Ihug  
View profile  
 More options Jul 19 2005, 8:47 pm
Newsgroups: comp.lang.tcl
From: "Ihug" <p...@fastbase.co.nz>
Date: Wed, 20 Jul 2005 12:47:44 +1200
Local: Tues, Jul 19 2005 8:47 pm
Subject: Re: float2IEEE numbers - 64 bit?
I found my own solution by taking the original wiki script and maintaining
it myself for double precion:
(there may be bugs!!!)

proc ieee754 { value } {
 # covert value to double precision IEEE754 number
 if {$value > 0} {
  set sign 0
 } else {
  set sign 1
  set value [expr {-1. * $value}]
 }

 # If the following math fails, then it's because of the logarithm. That
means that value is indistinguishable from zero
 if {[catch {
  set exponent [expr {int(floor(log($value)/0.69314718055994529))+1023}]
  set fraction [expr {($value/pow(2.,double($exponent-1023)))-1.}]
 }]} {
  set exponent 0
  set fraction 0.0
 } else {
  # round off too-small values to zero, throw error for too-large values
  if {$exponent < 0} {
   set exponent 0
   set fraction 0.0
  } elseif {$exponent > 2047} {
   error "value $value outside legal range for a float"
  }
 }

 set fraction [expr {$fraction * 16.}]
 set f1f      [expr {floor($fraction)}]

 set fraction [expr {($fraction - $f1f) * 256.}]
 set f2f      [expr {floor($fraction)}]

 set fraction [expr {($fraction - $f2f) * 256.}]
 set f3f      [expr {floor($fraction)}]

 set fraction [expr {($fraction - $f3f) * 256.}]
 set f4f      [expr {floor($fraction)}]

 set fraction [expr {($fraction - $f4f) * 256.}]
 set f5f      [expr {floor($fraction)}]

 set fraction [expr {($fraction - $f5f) * 256.}]
 set f6f      [expr {floor($fraction)}]

 set fraction [expr {($fraction - $f6f) * 256.}]
 set f7f      [expr {floor($fraction)}]

 for {set i 1} {$i <= 7} {incr i} {
  set var "f$i"
  append var "f"
  set f$i [expr {int([set $var])}]
 }

 set se1 [expr {($sign ? 128 : 0) | ($exponent >> 4)}]
 set e2f1 [expr {(($exponent & 15) * 16) | $f1}]

 set bytes [binary format cccccccc $f7 $f6 $f5 $f4 $f3 $f2 $e2f1 $se1]

 return $bytes

}
"Ihug" <p...@fastbase.co.nz> wrote in message

news:dbi1fv$utu$1@lust.ihug.co.nz...
>I am trying to write IEEE 754 64 bit numbers.
> The following wiki page has a procedure "float2IEEE" that writes a 32 bit
> number.

> http://wiki.tcl.tk/756

> How would I modify this to output 64 bit?
> Is this possible/easy?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.