summaryrefslogtreecommitdiffstats
path: root/bytenumb.txi
diff options
context:
space:
mode:
authorSteve Langasek <vorlon@debian.org>2005-01-10 08:53:33 +0000
committerBryan Newbold <bnewbold@robocracy.org>2017-02-20 00:05:30 -0800
commite33f9eb9cf5cc29c36ce2aa7e10cd0f37ae0cc8e (patch)
treeabbf06041619e445f9d0b772b0d58132009d8234 /bytenumb.txi
parentf559c149c83da84d0b1c285f0298c84aec564af9 (diff)
parent8466d8cfa486fb30d1755c4261b781135083787b (diff)
downloadslib-e33f9eb9cf5cc29c36ce2aa7e10cd0f37ae0cc8e.tar.gz
slib-e33f9eb9cf5cc29c36ce2aa7e10cd0f37ae0cc8e.zip
Import Debian changes 3a1-4.2debian/3a1-4.2
slib (3a1-4.2) unstable; urgency=low * Non-maintainer upload. * Add guile.init.local for use within the build dir, since otherwise we have an (earlier unnoticed) circular build-dep due to a difference between scm and guile. slib (3a1-4.1) unstable; urgency=low * Non-maintainer upload. * Build-depend on guile-1.6 instead of scm, since the new version of scm is wedged in unstable (closes: #281809). slib (3a1-4) unstable; urgency=low * Also check for expected creation on slibcat. (Closes: #240096) slib (3a1-3) unstable; urgency=low * Also check for /usr/share/guile/1.6/slib before installing for guile 1.6. (Closes: #239267) slib (3a1-2) unstable; urgency=low * Add format.scm back into slib until gnucash stops using it. * Call guile-1.6 new-catalog (Closes: #238231) slib (3a1-1) unstable; urgency=low * New upstream release * Remove Info section from doc-base file (Closes: #186950) * Remove period from end of description (linda, lintian) * html gen fixed upstream (Closes: #111778) slib (2d4-2) unstable; urgency=low * Fix url for upstream source (Closes: #144981) * Fix typo in slib.texi (enquque->enqueue) (Closes: #147475) * Add build depends. slib (2d4-1) unstable; urgency=low * New upstream. slib (2d3-1) unstable; urgency=low * New upstream. * Remove texi2html call in debian/rules. Now done upstream. Add make html instead. * Changes to rules and doc-base to conform to upstream html gen * Clean up upstream makefile to make sure it cleans up after itself.
Diffstat (limited to 'bytenumb.txi')
-rw-r--r--bytenumb.txi181
1 files changed, 181 insertions, 0 deletions
diff --git a/bytenumb.txi b/bytenumb.txi
new file mode 100644
index 0000000..67c340b
--- /dev/null
+++ b/bytenumb.txi
@@ -0,0 +1,181 @@
+@code{(require 'byte-number)}
+@ftindex byte-number
+
+@noindent
+The multi-byte sequences produced and used by numeric conversion
+routines are always big-endian. Endianness can be changed during
+reading and writing bytes using @code{read-bytes} and
+@code{write-bytes} @xref{Byte, read-bytes}.
+
+@noindent
+The sign of the length argument to bytes/integer conversion
+procedures determines the signedness of the number.
+
+
+@defun bytes->integer bytes n
+
+Converts the first @code{(abs @var{n})} bytes of big-endian @var{bytes} array
+to an integer. If @var{n} is negative then the integer coded by the
+bytes are treated as two's-complement (can be negative).
+
+@example
+(bytes->integer (bytes 0 0 0 15) -4) @result{} 15
+(bytes->integer (bytes 0 0 0 15) 4) @result{} 15
+(bytes->integer (bytes 255 255 255 255) -4) @result{} -1
+(bytes->integer (bytes 255 255 255 255) 4) @result{} 4294967295
+(bytes->integer (bytes 128 0 0 0) -4) @result{} -2147483648
+(bytes->integer (bytes 128 0 0 0) 4) @result{} 2147483648
+@end example
+@end defun
+
+@defun integer->bytes n len
+
+Converts the integer @var{n} to a byte-array of @code{(abs @var{n})}
+bytes. If @var{n} and @var{len} are both negative, then the bytes in the
+returned array are coded two's-complement.
+
+@example
+(bytes->list (integer->bytes 15 -4)) @result{} (0 0 0 15)
+(bytes->list (integer->bytes 15 4)) @result{} (0 0 0 15)
+(bytes->list (integer->bytes -1 -4)) @result{} (255 255 255 255)
+(bytes->list (integer->bytes 4294967295 4)) @result{} (255 255 255 255)
+(bytes->list (integer->bytes -2147483648 -4)) @result{} (128 0 0 0)
+(bytes->list (integer->bytes 2147483648 4)) @result{} (128 0 0 0)
+@end example
+@end defun
+
+@defun bytes->ieee-float bytes
+
+@var{bytes} must be a 4-element byte-array. @code{bytes->ieee-float} calculates and returns the
+value of @var{bytes} interpreted as a big-endian IEEE 4-byte (32-bit) number.
+@end defun
+@example
+(bytes->ieee-float (bytes #x40 0 0 0)) @result{} 2.0
+(bytes->ieee-float (bytes #x40 #xd0 0 0)) @result{} 6.5
+(bytes->ieee-float (bytes #xc0 #xd0 0 0)) @result{} -6.5
+
+(bytes->ieee-float (bytes 0 #x80 0 0)) @result{} 11.754943508222875e-39
+(bytes->ieee-float (bytes 0 #x40 0 0)) @result{} 5.877471754111437e-39
+(bytes->ieee-float (bytes 0 0 0 1)) @result{} 1.401298464324817e-45
+
+(bytes->ieee-float (bytes #xff #x80 0 0)) @result{} -1/0
+(bytes->ieee-float (bytes #x7f #x80 0 0)) @result{} 1/0
+(bytes->ieee-float (bytes #x7f #x80 0 1)) @result{} 0/0
+@end example
+
+
+@defun bytes->ieee-double bytes
+
+@var{bytes} must be a 8-element byte-array. @code{bytes->ieee-double} calculates and returns the
+value of @var{bytes} interpreted as a big-endian IEEE 8-byte (64-bit) number.
+@end defun
+@example
+(bytes->ieee-double (bytes 0 0 0 0 0 0 0 0)) @result{} 0.0
+(bytes->ieee-double (bytes #x40 0 0 0 0 0 0 0)) @result{} 2
+(bytes->ieee-double (bytes #x40 #x1A 0 0 0 0 0 0)) @result{} 6.5
+(bytes->ieee-double (bytes #xC0 #x1A 0 0 0 0 0 0)) @result{} -6.5
+
+(bytes->ieee-double (bytes 0 8 0 0 0 0 0 0)) @result{} 11.125369292536006e-309
+(bytes->ieee-double (bytes 0 4 0 0 0 0 0 0)) @result{} 5.562684646268003e-309
+(bytes->ieee-double (bytes 0 0 0 0 0 0 0 1)) @result{} 4.0e-324
+
+(bytes->ieee-double (bytes #xFF #xF0 0 0 0 0 0 0)) @result{} -1/0
+(bytes->ieee-double (bytes #x7F #xF0 0 0 0 0 0 0)) @result{} 1/0
+(bytes->ieee-double (bytes #x7F #xF8 0 0 0 0 0 0)) @result{} 0/0
+@end example
+
+
+@defun ieee-float->bytes x
+
+Returns a 4-element byte-array encoding the IEEE single-precision
+floating-point of @var{x}.
+@end defun
+@example
+(bytes->list (ieee-float->bytes 2.0)) @result{} (64 0 0 0)
+(bytes->list (ieee-float->bytes 6.5)) @result{} (64 208 0 0)
+(bytes->list (ieee-float->bytes -6.5)) @result{} (192 208 0 0)
+
+(bytes->list (ieee-float->bytes 11.754943508222875e-39)) @result{} ( 0 128 0 0)
+(bytes->list (ieee-float->bytes 5.877471754111438e-39)) @result{} ( 0 64 0 0)
+(bytes->list (ieee-float->bytes 1.401298464324817e-45)) @result{} ( 0 0 0 1)
+
+(bytes->list (ieee-float->bytes -1/0)) @result{} (255 128 0 0)
+(bytes->list (ieee-float->bytes 1/0)) @result{} (127 128 0 0)
+(bytes->list (ieee-float->bytes 0/0)) @result{} (127 128 0 1)
+@end example
+
+
+@defun ieee-double->bytes x
+
+Returns a 8-element byte-array encoding the IEEE double-precision
+floating-point of @var{x}.
+@end defun
+@example
+(bytes->list (ieee-double->bytes 2.0)) @result{} (64 0 0 0 0 0 0 0)
+(bytes->list (ieee-double->bytes 6.5)) @result{} (64 26 0 0 0 0 0 0)
+(bytes->list (ieee-double->bytes -6.5)) @result{} (192 26 0 0 0 0 0 0)
+
+(bytes->list (ieee-double->bytes 11.125369292536006e-309))
+ @result{} ( 0 8 0 0 0 0 0 0)
+(bytes->list (ieee-double->bytes 5.562684646268003e-309))
+ @result{} ( 0 4 0 0 0 0 0 0)
+(bytes->list (ieee-double->bytes 4.0e-324))
+ @result{} ( 0 0 0 0 0 0 0 1)
+
+(bytes->list (ieee-double->bytes -1/0)) @result{} (255 240 0 0 0 0 0 0)
+(bytes->list (ieee-double->bytes 1/0)) @result{} (127 240 0 0 0 0 0 0)
+(bytes->list (ieee-double->bytes 0/0)) @result{} (127 248 0 0 0 0 0 0)
+@end example
+
+@subsubheading Byte Collation Order
+
+@noindent
+The @code{string<?} ordering of big-endian byte-array
+representations of fixed and IEEE floating-point numbers agrees with
+the numerical ordering only when those numbers are non-negative.
+
+@noindent
+Straighforward modification of these formats can extend the
+byte-collating order to work for their entire ranges. This
+agreement enables the full range of numbers as keys in
+@dfn{indexed-sequential-access-method} databases.
+@cindex indexed-sequential-access-method
+
+
+@deffn {Procedure} integer-byte-collate! byte-vector
+
+Modifies sign bit of @var{byte-vector} so that @code{string<?} ordering of
+two's-complement byte-vectors matches numerical order. @code{integer-byte-collate!} returns
+@var{byte-vector} and is its own functional inverse.
+@end deffn
+
+@defun integer-byte-collate byte-vector
+
+Returns copy of @var{byte-vector} with sign bit modified so that @code{string<?}
+ordering of two's-complement byte-vectors matches numerical order.
+@code{integer-byte-collate} is its own functional inverse.
+@end defun
+
+@deffn {Procedure} ieee-byte-collate! byte-vector
+
+Modifies @var{byte-vector} so that @code{string<?} ordering of IEEE floating-point
+byte-vectors matches numerical order. @code{ieee-byte-collate!} returns @var{byte-vector}.
+@end deffn
+
+@deffn {Procedure} ieee-byte-decollate! byte-vector
+
+Given @var{byte-vector} modified by @code{IEEE-byte-collate!}, reverses the @var{byte-vector}
+modifications.
+@end deffn
+
+@defun ieee-byte-collate byte-vector
+
+Returns copy of @var{byte-vector} encoded so that @code{string<?} ordering of IEEE
+floating-point byte-vectors matches numerical order.
+@end defun
+
+@defun ieee-byte-decollate byte-vector
+
+Given @var{byte-vector} returned by @code{IEEE-byte-collate}, reverses the @var{byte-vector}
+modifications.
+@end defun