home *** CD-ROM | disk | FTP | other *** search
- /*
- Listing 24.12 Real2iee()
- Author: Joe Booth
- Excerpted from "Clipper 5: A Developer's Guide"
- Copyright (c) 1991 M&T Books
- 501 Galveston Drive
- Redwood City, CA 94063-4728
- (415) 366-3600
- */
-
- //───── NOTE: must compile with the /N option!
-
- function real2iee(nReal)
- LOCAL retval:=replicate(chr(0),8), exponent, sign ,j
- if nReal<>0 // If non-zero
- sign := if(nReal<0,128,0) // Set the sign bit
- exponent:= 1075 // Offset of 1023 + 52 bits max
- nReal := abs(nReal) // We already know the sign
- do while nReal < 2**52 // 2 raised to 52 power
- nReal *= 2 // Multiply number by 2
- exponent-- // Subtract one from exponent
- enddo
- do while nReal > 2*4503599627370496-1
- nReal /= 2
- exponent++
- enddo
- nReal := int(nReal) // Number is now an integer
- retval := '' // Build the first 48 bits in reverse
- for j = 1 to 6 // by dividing by 256 and writing
- retval += chr(nReal%256) // remainder to string
- nReal := int(nReal/256)
- next
- nReal -= 16 // Strip out four high end bits
- retval += chr(nReal+16*(exponent%16)) + chr(sign+int(exponent/16))
- endif
- return retval
-
- // end of file CHP2412.PRG
-