]> gitweb.factorcode.org Git - factor.git/commitdiff
bits>float bits>double primitives'
authorSlava Pestov <slava@factorcode.org>
Mon, 13 Jun 2005 00:55:30 +0000 (00:55 +0000)
committerSlava Pestov <slava@factorcode.org>
Mon, 13 Jun 2005 00:55:30 +0000 (00:55 +0000)
20 files changed:
CHANGES.txt
doc/handbook.tex
library/alien/aliens.factor
library/bootstrap/boot-stage1.factor
library/bootstrap/primitives.factor
library/generic/generic.factor
library/generic/tuple.factor
library/test/alien.factor
library/test/image.factor
library/test/math/float.factor
library/tools/debugger.factor
native/bignum.c
native/debug.c
native/float.c
native/float.h
native/gc.h
native/primitives.c
native/s48_bignum.c
native/s48_bignum.h
native/s48_bignumint.h

index 9e8b736917d528f0f421e76b219cf41659b67f24..81c554ceff415b898b24858028606f754907a2bf 100644 (file)
@@ -57,6 +57,8 @@ Factor 0.75:
 
 - OpenGL binding in contrib/gl/ (Alex Chapman).
 
+- PostgreSQL binding in contrib/postgresql/ (Doug Coleman).
+
 - HTTP server now supports virtual hosting.
 
 - The Factor plugin now supports connecting to Factor instances on
index 18e24598bd6f3dac1befbd78017e8548121217bc..dd0b7ccd773b6c66a6dfd34169ba09854e80c132 100644 (file)
@@ -1911,8 +1911,9 @@ Tests if the sequence contains any elements. The default implementation of this
 \wordtable{
 \vocabulary{sequences}
 \ordinaryword{index}{index ( obj seq -- n )}
+\ordinaryword{index*}{index* ( obj i seq -- n )}
 }
-Outputs the index of the first element in the sequence equal to \texttt{obj}. If no element is found, outputs $-1$.
+Outputs the index of the first element in the sequence equal to \texttt{obj}. If no element is found, outputs $-1$. The \verb|index*| form allows a start index to be specified.
 \wordtable{
 \vocabulary{sequences}
 \ordinaryword{contains?}{contains?~( elt seq -- ?~)}
@@ -1920,6 +1921,12 @@ Outputs the index of the first element in the sequence equal to \texttt{obj}. If
 Tests if \texttt{seq} contains an element equal to \texttt{elt}.
 \wordtable{
 \vocabulary{sequences}
+\ordinaryword{start}{start ( subseq seq -- n )}
+\ordinaryword{start*}{start* ( subseq i seq -- n )}
+}
+Outputs the start index of a subsequence, or $-1$ if the subsequence does not occur in the sequence. The \verb|start*| form allows a start index to be specified.
+\wordtable{
+\vocabulary{sequences}
 \ordinaryword{subseq?}{subseq?~( s1 s2 -- ?~)}
 }
 Tests if \texttt{s2} contains \texttt{s1} as a subsequence.
@@ -1930,11 +1937,7 @@ Tests if \texttt{s2} contains \texttt{s1} as a subsequence.
 
 }
 Tests if \texttt{s1} starts or ends with \texttt{s1}. If \texttt{s1} is longer than \texttt{s2}, outputs \texttt{f}.
-\wordtable{
-\vocabulary{sequences}
-\ordinaryword{index*}{index* ( obj i seq -- n )}
-}
-Outputs the index of the first element in the sequence equal to \texttt{obj}, starting from \texttt{i}. If no element is found, outputs $-1$.
+
 \wordtable{
 \vocabulary{sequences}
 \ordinaryword{peek}{peek ( sequence -- element )}
@@ -3259,7 +3262,7 @@ Deconstructs rational numbers into their numerator and denominator. The denomina
 \textbf{12}
 \end{alltt}
 
-\section{Floating point numbers}\label{floats}
+\section{Floats}\label{floats}
 
 \wordtable{
 \vocabulary{math}
@@ -3299,6 +3302,24 @@ Tests if the top of the stack is a floating point number.
 }
 Turn any real number into a floating point approximation.
 
+\subsection{Binary representation of floats}\label{float-bits}
+
+Floating point numbers are represented internally in IEEE 754 double-precision format. This internal representation can be accessed for advanced operations and input/output purposes.
+
+\wordtable{
+\vocabulary{math}
+\ordinaryword{float>bits}{float>bits ( x -- n )}
+\ordinaryword{double>bits}{double>bits ( x -- n )}
+}
+Converts the floating point number $x$ into IEEE 754 single or double precision form, and outputs an integer holding the binary representation of the result.
+
+\wordtable{
+\vocabulary{math}
+\ordinaryword{bits>float}{float>bits ( n -- x )}
+\ordinaryword{bits>double}{double>bits ( n -- x )}
+}
+Converts an integer representation $n$ of an IEEE 754 single or double precision float into a \verb|float| object.
+
 \section{Complex numbers}\label{complex-numbers}
 
 \wordtable{
@@ -3870,7 +3891,7 @@ a string and returned.
 description={a representation of an integer as a sequence of bytes, ordered from most significant to least significant. This is the native byte ordering for PowerPC, SPARC, Alpha and ARM processors}}
 \glossary{name=little endian,
 description={a representation of an integer as a sequence of bytes, ordered from least significant to most significant. This is the native byte ordering for x86 and x86-64 processors}}
-The core stream words read and write strings. Packed binary integers can be read and written by converting to and from sequences of bytes.
+The core stream words read and write strings. Packed binary integers can be read and written by converting to and from sequences of bytes. Floating point numbers can be read and written by converting them into a their bitwise integer representation (\ref{float-bits}).
 
 There are two ways to order the bytes making up an integer; \emph{little endian} byte order outputs the least significant byte first, and the most significant byte last, whereas \emph{big endian} is the other way around.
 
@@ -4541,6 +4562,8 @@ This word is used to implement end-of-line comments:
 
 \chapter{Web framework}
 
+Factor includes facilities for interoperating with web-based services. This includes an HTTP client, and an HTTP server with a continuation-based web application framework.
+
 \section{HTTP client}
 
 \wordtable{
@@ -4554,6 +4577,58 @@ Attempts to connect to the server specified in the URL. If the connection fails,
 \item[\texttt{stream}] a stream for reading the resource.
 \end{description}
 
+\section{HTTP server}\label{httpd}
+
+The HTTP server listens for requests on a port and hands them off to responders. A responder takes action based on the type of request.
+
+\wordtable{
+\vocabulary{httpd}
+\ordinaryword{httpd}{httpd ( port -- )}
+}
+Starts listening for HTTP requests on \verb|port|.
+
+The HTTP server is usually started with a phrase like the following:
+\begin{alltt}
+\textbf{ok} USING: httpd threads ;
+\textbf{ok} [ 8888 httpd ] in-thread
+\end{alltt}
+
+\wordtable{
+\vocabulary{httpd}
+\ordinaryword{stop-httpd}{stop-httpd ( -- )}
+}
+Stops the HTTP server.
+
+A useful application of the HTTP server is the built-in vocabulary browser. You can use it simply by starting the HTTP server then visiting the following location:
+
+\begin{verbatim}
+http://localhost:8888/responder/browser/
+\end{verbatim}
+
+\subsection{Serving static content}
+
+Static content may be served by setting the \verb|"doc-root"| variable to a directory holding the content. This variable may be set in the global namespace, or indeed, individually on each virtual host.
+\begin{verbatim}
+"/var/www/" "doc-root" set
+\end{verbatim}
+
+If a directory holds an \verb|index.html| file, the file is served when the directory is requested, otherwise a directory listing is produced. The directory listing references icons sent via the resource responder. The icons are located in the Factor source tree, and the \verb|"resource-path"| variable may be set to the root of the source tree in order for the icons to be located:
+\begin{verbatim}
+"/home/slava/work/Factor/" "resource-path" set
+\end{verbatim}
+A facility for ad-hoc server-side scripting exists. If a file with the \verb|.factsp| filename extension is requested, the file is run with \verb|run-file| and any output it sends to the default stream is sent to the client (\ref{stdio}). These ``Factor server pages'' are slower and less powerful than responders, so it is recommended that responders be used instead.
+
+\subsection{Responders}
+
+\glossary{name=responder,
+description={A named handler for HTTP requests, installed in the \texttt{responders} variable}}
+\glossary{name=HTTP responder,
+description={See responder}}
+
+The HTTP server listens on a port number for HTTP requests and issues requests to \emph{responders}.
+
+\subsection{Virtual hosts}
+
 \section{HTML output}\label{html}
 
 An HTML stream wraps an existing stream. Strings written to the HTML stream have their special characters converted to HTML entities before being passed on to the wrapped stream. Also, the \texttt{attrs} parameter to the \texttt{stream-write-attr} word may be filled out to wrap the text being written in various HTML tags.
@@ -5256,25 +5331,6 @@ M: list prettyprint*
     ] check-recursion ;}
 \end{alltt}
 
-\section{Browsing via the HTTP server}
-
-
-A more sophisticated way to browse the library is using the integrated HTTP server. You can start the HTTP server using the following pair of commands:
-
-\begin{alltt}
-\textbf{ok} USE: httpd
-\textbf{ok} USE: threads
-\textbf{ok} [ 8888 httpd ] in-thread
-\end{alltt}
-
-Then, point your browser to the following URL, and start browsing:
-
-\begin{quote}
-\texttt{http://localhost:8888/responder/inspect/vocabularies}
-\end{quote}
-
-To stop the HTTP server, evaluate the \verb|stop-httpd| word.
-
 \chapter{Dealing with runtime errors}
 
 \section{Looking at stacks}
index 2e9c7682ff72050614673384a29c19f72b5bb279..d9904f4a608d1026014dbb8e723851266f8168b9 100644 (file)
@@ -18,9 +18,6 @@ BUILTIN: displaced-alien 20 displaced-alien? ;
 
 : null? ( alien -- ? ) dup alien? [ alien-address 0 = ] when ;
 
-: null>f ( alien -- alien/f )
-    dup alien-address 0 = [ drop f ] when ;
-
 M: alien hashcode ( obj -- n )
     alien-address >fixnum ;
 
index 208606e9ff9445476b4ecb26446574e0254751aa..64a61dd9e9268965a8845edeef1a36e26f9b6506 100644 (file)
@@ -107,7 +107,6 @@ parser prettyprint sequences stdio vectors words ;
     ] pull-in
 ] make-list
 
-"delegate" [ "generic" ] search
 "object" [ "generic" ] search
 "typemap" [ "generic" ] search
 "builtins" [ "generic" ] search
@@ -117,7 +116,6 @@ vocabularies get [ "generic" off ] bind
 reveal
 reveal
 reveal
-reveal
 
 [
     [
@@ -146,8 +144,6 @@ reveal
     
         "/library/bootstrap/init.factor"
     ] pull-in
-    
-    ! uncomment this if type numbers change. it takes a long time...
 
     [
         "Building generics..." print
index 480bb82b78d84e7ee82907c89d9449458dace5a0..7e184780174e24f013f6669a86b8d80bcede171f 100644 (file)
@@ -55,8 +55,10 @@ vocabularies get [
     [ "(fraction>)" "math-internals"          [ [ integer integer ] [ rational ] ] ]
     [ "str>float" "parser"                    [ [ string ] [ float ] ] ]
     [ "(unparse-float)" "unparser"            [ [ float ] [ string ] ] ]
-    [ "float-bits" "math"                     [ [ real ] [ integer ] ] ]
-    [ "double-bits" "math"                    [ [ real ] [ integer ] ] ]
+    [ "float>bits" "math"                     [ [ real ] [ integer ] ] ]
+    [ "double>bits" "math"                    [ [ real ] [ integer ] ] ]
+    [ "bits>float" "math"                     [ [ integer ] [ float ] ] ]
+    [ "bits>double" "math"                    [ [ integer ] [ float ] ] ]
     [ "<complex>" "math-internals"            [ [ real real ] [ number ] ] ]
     [ "fixnum+" "math-internals"              [ [ fixnum fixnum ] [ integer ] ] ]
     [ "fixnum-" "math-internals"              [ [ fixnum fixnum ] [ integer ] ] ]
index 98cf90f41eb6d76c63c3862b5e6dde9f3795bb3a..f88beaf4456cc60aebd3a290d4f3c4939d0a819c 100644 (file)
@@ -22,6 +22,14 @@ math-internals ;
 ! properties: "builtin-supertypes" "priority" "add-method"
 ! "class<"
 
+! So far, only tuples can have delegates, which also must be
+! tuples (the UI uses numbers as delegates in a couple of places
+! but this is Unsupported(tm)).
+GENERIC: delegate
+GENERIC: set-delegate
+
+M: object delegate drop f ;
+
 ! Metaclasses have priority -- this induces an order in which
 ! methods are added to the vtable.
 
index 7d56015d06d0145ef447a765a516710305b3f972..d2767d2e7e5d9a9899c5d3d1bfb1f943c643b82a 100644 (file)
@@ -25,14 +25,6 @@ IN: generic
 DEFER: tuple?
 BUILTIN: tuple 18 tuple? ;
 
-! So far, only tuples can have delegates, which also must be
-! tuples (the UI uses numbers as delegates in a couple of places
-! but this is Unsupported(tm)).
-GENERIC: delegate
-GENERIC: set-delegate
-
-M: object delegate drop f ;
-
 M: tuple delegate 3 slot ;
 M: tuple set-delegate 3 set-slot ;
 
index 38e83f8d53b3d0e088c22106d3c9a7c82cd6a52e..edb11e8138e3f2590852370dbaa7bf7dbd8cb8f5 100644 (file)
@@ -1,19 +1,34 @@
 IN: temporary
-USE: alien
-USE: kernel
-USE: test
-USE: inference
+USING: alien kernel kernel-internals namespaces test ;
 
 [ t ] [ 0 <alien> 0 <alien> = ] unit-test
 [ f ] [ 0 <alien> 1024 <alien> = ] unit-test
 [ f ] [ "hello" 1024 <alien> = ] unit-test
 
-! : alien-inference-1
-!     "void" "foobar" "boo" [ "short" "short" ] alien-invoke ;
-! 
-! [ [[ 2 0 ]] ] [ [ alien-inference-1 ] infer old-effect ] unit-test
-! 
-! : alien-inference-2
-!     "int" "foobar" "boo" [ "short" "short" ] alien-invoke ;
-! 
-! [ [[ 2 1 ]] ] [ [ alien-inference-2 ] infer old-effect ] unit-test
+! Testing the various bignum accessor
+10 <byte-array> "dump" set
+
+[ 123 ] [
+    123 "dump" get 0 set-alien-signed-1
+    "dump" get 0 alien-signed-1
+] unit-test
+
+[ 12345 ] [
+    12345 "dump" get 0 set-alien-signed-2
+    "dump" get 0 alien-signed-2
+] unit-test
+
+[ 12345678 ] [
+    12345678 "dump" get 0 set-alien-signed-4
+    "dump" get 0 alien-signed-4
+] unit-test
+
+[ 12345678901234567 ] [
+    12345678901234567 "dump" get 0 set-alien-signed-8
+    "dump" get 0 alien-signed-8
+] unit-test
+
+[ -1 ] [
+    -1 "dump" get 0 set-alien-signed-8
+    "dump" get 0 alien-signed-8
+] unit-test
index 16d120ebfc1a148abf0b7db4c8dd3f90c2af9983..93b184e2f0262b2c0fc72b630884ac2579ff6ca5 100644 (file)
@@ -23,7 +23,7 @@ USE: math
 
 [ "\0\0\0\0\u000f\u000e\r\u000c" ]
 [
-    [ image-magic write-be64 ] with-string
+    [ image-magic write-be8 ] with-string
 ] unit-test
 
 [
index 89876c01d528856b7b748d3375624fcf2326085d..2bc397039b830b114ce4d0a7089d4d9e895a9c08 100644 (file)
@@ -29,3 +29,6 @@ USE: test
 
 [ t ] [ pi 3 > ] unit-test
 [ f ] [ e 2 <= ] unit-test
+
+[ t ] [ pi double>bits bits>double pi = ] unit-test
+[ t ] [ e double>bits bits>double e = ] unit-test
index 17ce7c42ac4f1b12c0350c3e0ae9c40c9cc37275..87a5cf5650dcacb49dec744af469d971770f72c8 100644 (file)
@@ -69,7 +69,7 @@ M: no-method error. ( error -- )
     
     dup parse-error-text dup string? [ print ] [ drop ] ifte
     
-    parse-error-col CHAR: \s fill write "^" print ;
+    parse-error-col [ 0 ] unless* CHAR: \s fill write "^" print ;
 
 M: parse-error error. ( error -- )
     dup parse-dump  delegate error. ;
index 187eeb10942406c1ea270ebe75acff8ea3dcb3f7..a15892ae14c6d6450a4317373680ec88e69b9a95 100644 (file)
@@ -236,15 +236,15 @@ void box_signed_8(s64 n)
 
 s64 unbox_signed_8(void)
 {
-       return 0; /* s48_bignum_to_long_long(to_bignum(dpop())); */
+       return s48_bignum_to_long_long(to_bignum(dpop()));
 }
 
 void box_unsigned_8(u64 n)
 {
-       dpush(tag_bignum(s48_long_long_to_bignum(n)));
+       dpush(tag_bignum(s48_ulong_long_to_bignum(n)));
 }
 
 u64 unbox_unsigned_8(void)
 {
-       return 0; /* s48_bignum_to_long_long(to_bignum(dpop())); */
+       return s48_bignum_to_ulong_long(to_bignum(dpop()));
 }
index a049c110b8d83b192425cfc43b7d175e0bf7ae2b..4e4c8c811322948427d485e0ef79342035bfcb0f 100644 (file)
@@ -315,7 +315,7 @@ void factorbug(void)
                        throw_error(T,true);
                else if(strcmp(cmd,"x") == 0)
                        return;
-               else if(strcmp(cmd,"y") == 0)
+               else if(strcmp(cmd,"im") == 0)
                        save_image("factor.crash.image");
                else
                        fprintf(stderr,"unknown command\n");
index 3affb9bb527b045a5ddc74f9b8a54bca5ec00fa1..432e4075bac2d3dd53dc363a5b443ce50ef434fc 100644 (file)
@@ -205,11 +205,25 @@ void primitive_float_bits(void)
        drepl(tag_cell(x_bits));
 }
 
+void primitive_bits_float(void)
+{
+       CELL x_ = unbox_unsigned_4();
+       float x = *(float*)(&x_);
+       dpush(tag_float(x));
+}
+
 void primitive_double_bits(void)
 {
-       double x = to_float(dpeek());
+       double x = to_float(dpop());
        u64 x_bits = *(u64*)(&x);
-       drepl(tag_bignum(s48_long_long_to_bignum(x_bits)));
+       box_unsigned_8(x_bits);
+}
+
+void primitive_bits_double(void)
+{
+       u64 x_ = unbox_unsigned_8();
+       double x = *(double*)(&x_);
+       dpush(tag_float(x));
 }
 
 #define DEFBOX(name,type)                                                      \
index fd62b25c274832c816589e1ef3e24183d68b9ace..ae61a867b980a4d544f00160d8bf79c22774cb06 100644 (file)
@@ -50,7 +50,9 @@ void primitive_fsinh(void);
 void primitive_fsqrt(void);
 
 void primitive_float_bits(void);
+void primitive_bits_float(void);
 void primitive_double_bits(void);
+void primitive_bits_double(void);
 
 void box_float(float flo);
 float unbox_float(void);
index 4d34e920f495e2c468c0da49fe4d5b7e091af1a7..e57f7252677a6e654ea142cbe3138265df1fe158 100644 (file)
@@ -69,7 +69,7 @@ INLINE bool should_copy(CELL untagged)
 }
 
 CELL copy_object(CELL pointer);
-#define COPY_OBJECT(lvalue) if(COLLECTING_GEN(lvalue)) lvalue = copy_object(lvalue)
+#define COPY_OBJECT(lvalue) if(should_copy(lvalue)) lvalue = copy_object(lvalue)
 
 INLINE void copy_handle(CELL *handle)
 {
index 064b71b034b8229dd78bbc84a4c1eab97c61c477..89685473e6491e2b5c7f0fb7b7c942aad94602dd 100644 (file)
@@ -23,6 +23,8 @@ void* primitives[] = {
        primitive_float_to_str,
        primitive_float_bits,
        primitive_double_bits,
+       primitive_bits_float,
+       primitive_bits_double,
        primitive_from_rect,
        primitive_fixnum_add,
        primitive_fixnum_subtract,
index 606a2e7d5c4d710b7fb9bd504ec6a933f7cc8bae..ba801294d86795ef232256cab7e90b779fcb9bc3 100644 (file)
@@ -1,4 +1,4 @@
-/* -*-C-*-
+/* :tabSize=2:indentSize=2:noTabs=true:
 
 $Id$
 
@@ -43,12 +43,13 @@ MIT in each case. */
 /* Changes for Factor:
  *  - Add s48_ prefix to file names
  *  - Adapt s48_bignumint.h for Factor memory manager
+ *  - Add more bignum <-> C type conversions
  */
 
 #include "factor.h"
 #include <limits.h>
 #include <stdio.h>
-#include <stdlib.h>    /* abort */
+#include <stdlib.h>        /* abort */
 #include <math.h>
 
 /* Exports */
@@ -60,10 +61,10 @@ s48_bignum_equal_p(bignum_type x, bignum_type y)
     ((BIGNUM_ZERO_P (x))
      ? (BIGNUM_ZERO_P (y))
      : ((! (BIGNUM_ZERO_P (y)))
-       && ((BIGNUM_NEGATIVE_P (x))
-           ? (BIGNUM_NEGATIVE_P (y))
-           : (! (BIGNUM_NEGATIVE_P (y))))
-       && (bignum_equal_p_unsigned (x, y))));
+        && ((BIGNUM_NEGATIVE_P (x))
+            ? (BIGNUM_NEGATIVE_P (y))
+            : (! (BIGNUM_NEGATIVE_P (y))))
+        && (bignum_equal_p_unsigned (x, y))));
 }
 
 enum bignum_comparison
@@ -83,21 +84,21 @@ s48_bignum_compare(bignum_type x, bignum_type y)
   return
     ((BIGNUM_ZERO_P (x))
      ? ((BIGNUM_ZERO_P (y))
-       ? bignum_comparison_equal
-       : (BIGNUM_NEGATIVE_P (y))
-       ? bignum_comparison_greater
-       : bignum_comparison_less)
+        ? bignum_comparison_equal
+        : (BIGNUM_NEGATIVE_P (y))
+        ? bignum_comparison_greater
+        : bignum_comparison_less)
      : (BIGNUM_ZERO_P (y))
      ? ((BIGNUM_NEGATIVE_P (x))
-       ? bignum_comparison_less
-       : bignum_comparison_greater)
+        ? bignum_comparison_less
+        : bignum_comparison_greater)
      : (BIGNUM_NEGATIVE_P (x))
      ? ((BIGNUM_NEGATIVE_P (y))
-       ? (bignum_compare_unsigned (y, x))
-       : (bignum_comparison_less))
+        ? (bignum_compare_unsigned (y, x))
+        : (bignum_comparison_less))
      : ((BIGNUM_NEGATIVE_P (y))
-       ? (bignum_comparison_greater)
-       : (bignum_compare_unsigned (x, y))));
+        ? (bignum_comparison_greater)
+        : (bignum_compare_unsigned (x, y))));
 }
 
 bignum_type
@@ -109,12 +110,12 @@ s48_bignum_add(bignum_type x, bignum_type y)
      : (BIGNUM_ZERO_P (y))
      ? (BIGNUM_MAYBE_COPY (x))
      : ((BIGNUM_NEGATIVE_P (x))
-       ? ((BIGNUM_NEGATIVE_P (y))
-          ? (bignum_add_unsigned (x, y, 1))
-          : (bignum_subtract_unsigned (y, x)))
-       : ((BIGNUM_NEGATIVE_P (y))
-          ? (bignum_subtract_unsigned (x, y))
-          : (bignum_add_unsigned (x, y, 0)))));
+        ? ((BIGNUM_NEGATIVE_P (y))
+           ? (bignum_add_unsigned (x, y, 1))
+           : (bignum_subtract_unsigned (y, x)))
+        : ((BIGNUM_NEGATIVE_P (y))
+           ? (bignum_subtract_unsigned (x, y))
+           : (bignum_add_unsigned (x, y, 0)))));
 }
 
 bignum_type
@@ -123,17 +124,17 @@ s48_bignum_subtract(bignum_type x, bignum_type y)
   return
     ((BIGNUM_ZERO_P (x))
      ? ((BIGNUM_ZERO_P (y))
-       ? (BIGNUM_MAYBE_COPY (y))
-       : (bignum_new_sign (y, (! (BIGNUM_NEGATIVE_P (y))))))
+        ? (BIGNUM_MAYBE_COPY (y))
+        : (bignum_new_sign (y, (! (BIGNUM_NEGATIVE_P (y))))))
      : ((BIGNUM_ZERO_P (y))
-       ? (BIGNUM_MAYBE_COPY (x))
-       : ((BIGNUM_NEGATIVE_P (x))
-          ? ((BIGNUM_NEGATIVE_P (y))
-             ? (bignum_subtract_unsigned (y, x))
-             : (bignum_add_unsigned (x, y, 1)))
-          : ((BIGNUM_NEGATIVE_P (y))
-             ? (bignum_add_unsigned (x, y, 0))
-             : (bignum_subtract_unsigned (x, y))))));
+        ? (BIGNUM_MAYBE_COPY (x))
+        : ((BIGNUM_NEGATIVE_P (x))
+           ? ((BIGNUM_NEGATIVE_P (y))
+              ? (bignum_subtract_unsigned (y, x))
+              : (bignum_add_unsigned (x, y, 1)))
+           : ((BIGNUM_NEGATIVE_P (y))
+              ? (bignum_add_unsigned (x, y, 0))
+              : (bignum_subtract_unsigned (x, y))))));
 }
 
 bignum_type
@@ -162,24 +163,24 @@ s48_bignum_multiply(bignum_type x, bignum_type y)
     {
       bignum_digit_type digit = (BIGNUM_REF (x, 0));
       if (digit == 1)
-       return (bignum_maybe_new_sign (y, negative_p));
+        return (bignum_maybe_new_sign (y, negative_p));
       if (digit < BIGNUM_RADIX_ROOT)
-       return (bignum_multiply_unsigned_small_factor (y, digit, negative_p));
+        return (bignum_multiply_unsigned_small_factor (y, digit, negative_p));
     }
   if (y_length == 1)
     {
       bignum_digit_type digit = (BIGNUM_REF (y, 0));
       if (digit == 1)
-       return (bignum_maybe_new_sign (x, negative_p));
+        return (bignum_maybe_new_sign (x, negative_p));
       if (digit < BIGNUM_RADIX_ROOT)
-       return (bignum_multiply_unsigned_small_factor (x, digit, negative_p));
+        return (bignum_multiply_unsigned_small_factor (x, digit, negative_p));
     }
   return (bignum_multiply_unsigned (x, y, negative_p));
 }
 
 void
 s48_bignum_divide(bignum_type numerator, bignum_type denominator,
-                 bignum_type * quotient, bignum_type * remainder)
+                  bignum_type * quotient, bignum_type * remainder)
 {
   if (BIGNUM_ZERO_P (denominator))
     {
@@ -195,57 +196,57 @@ s48_bignum_divide(bignum_type numerator, bignum_type denominator,
     {
       int r_negative_p = (BIGNUM_NEGATIVE_P (numerator));
       int q_negative_p =
-       ((BIGNUM_NEGATIVE_P (denominator)) ? (! r_negative_p) : r_negative_p);
+        ((BIGNUM_NEGATIVE_P (denominator)) ? (! r_negative_p) : r_negative_p);
       switch (bignum_compare_unsigned (numerator, denominator))
-       {
-       case bignum_comparison_equal:
-         {
-           (*quotient) = (BIGNUM_ONE (q_negative_p));
-           (*remainder) = (BIGNUM_ZERO ());
-           break;
-         }
-       case bignum_comparison_less:
-         {
-           (*quotient) = (BIGNUM_ZERO ());
-           (*remainder) = (BIGNUM_MAYBE_COPY (numerator));
-           break;
-         }
-       case bignum_comparison_greater:
-         {
-           if ((BIGNUM_LENGTH (denominator)) == 1)
-             {
-               bignum_digit_type digit = (BIGNUM_REF (denominator, 0));
-               if (digit == 1)
-                 {
-                   (*quotient) =
-                     (bignum_maybe_new_sign (numerator, q_negative_p));
-                   (*remainder) = (BIGNUM_ZERO ());
-                   break;
-                 }
-               else if (digit < BIGNUM_RADIX_ROOT)
-                 {
-                   bignum_divide_unsigned_small_denominator
-                     (numerator, digit,
-                      quotient, remainder,
-                      q_negative_p, r_negative_p);
-                   break;
-                 }
-               else
-                 {
-                   bignum_divide_unsigned_medium_denominator
-                     (numerator, digit,
-                      quotient, remainder,
-                      q_negative_p, r_negative_p);
-                   break;
-                 }
-             }
-           bignum_divide_unsigned_large_denominator
-             (numerator, denominator,
-              quotient, remainder,
-              q_negative_p, r_negative_p);
-           break;
-         }
-       }
+        {
+        case bignum_comparison_equal:
+          {
+            (*quotient) = (BIGNUM_ONE (q_negative_p));
+            (*remainder) = (BIGNUM_ZERO ());
+            break;
+          }
+        case bignum_comparison_less:
+          {
+            (*quotient) = (BIGNUM_ZERO ());
+            (*remainder) = (BIGNUM_MAYBE_COPY (numerator));
+            break;
+          }
+        case bignum_comparison_greater:
+          {
+            if ((BIGNUM_LENGTH (denominator)) == 1)
+              {
+                bignum_digit_type digit = (BIGNUM_REF (denominator, 0));
+                if (digit == 1)
+                  {
+                    (*quotient) =
+                      (bignum_maybe_new_sign (numerator, q_negative_p));
+                    (*remainder) = (BIGNUM_ZERO ());
+                    break;
+                  }
+                else if (digit < BIGNUM_RADIX_ROOT)
+                  {
+                    bignum_divide_unsigned_small_denominator
+                      (numerator, digit,
+                       quotient, remainder,
+                       q_negative_p, r_negative_p);
+                    break;
+                  }
+                else
+                  {
+                    bignum_divide_unsigned_medium_denominator
+                      (numerator, digit,
+                       quotient, remainder,
+                       q_negative_p, r_negative_p);
+                    break;
+                  }
+              }
+            bignum_divide_unsigned_large_denominator
+              (numerator, denominator,
+               quotient, remainder,
+               q_negative_p, r_negative_p);
+            break;
+          }
+        }
     }
 }
 
@@ -267,36 +268,36 @@ s48_bignum_quotient(bignum_type numerator, bignum_type denominator)
     switch (bignum_compare_unsigned (numerator, denominator))
       {
       case bignum_comparison_equal:
-       return (BIGNUM_ONE (q_negative_p));
+        return (BIGNUM_ONE (q_negative_p));
       case bignum_comparison_less:
-       return (BIGNUM_ZERO ());
+        return (BIGNUM_ZERO ());
       case bignum_comparison_greater:
-      default:                                 /* to appease gcc -Wall */
-       {
-         bignum_type quotient;
-         if ((BIGNUM_LENGTH (denominator)) == 1)
-           {
-             bignum_digit_type digit = (BIGNUM_REF (denominator, 0));
-             if (digit == 1)
-               return (bignum_maybe_new_sign (numerator, q_negative_p));
-             if (digit < BIGNUM_RADIX_ROOT)
-               bignum_divide_unsigned_small_denominator
-                 (numerator, digit,
-                  (&quotient), ((bignum_type *) 0),
-                  q_negative_p, 0);
-             else
-               bignum_divide_unsigned_medium_denominator
-                 (numerator, digit,
-                  (&quotient), ((bignum_type *) 0),
-                  q_negative_p, 0);
-           }
-         else
-           bignum_divide_unsigned_large_denominator
-             (numerator, denominator,
-              (&quotient), ((bignum_type *) 0),
-              q_negative_p, 0);
-         return (quotient);
-       }
+      default:                                        /* to appease gcc -Wall */
+        {
+          bignum_type quotient;
+          if ((BIGNUM_LENGTH (denominator)) == 1)
+            {
+              bignum_digit_type digit = (BIGNUM_REF (denominator, 0));
+              if (digit == 1)
+                return (bignum_maybe_new_sign (numerator, q_negative_p));
+              if (digit < BIGNUM_RADIX_ROOT)
+                bignum_divide_unsigned_small_denominator
+                  (numerator, digit,
+                   (&quotient), ((bignum_type *) 0),
+                   q_negative_p, 0);
+              else
+                bignum_divide_unsigned_medium_denominator
+                  (numerator, digit,
+                   (&quotient), ((bignum_type *) 0),
+                   q_negative_p, 0);
+            }
+          else
+            bignum_divide_unsigned_large_denominator
+              (numerator, denominator,
+               (&quotient), ((bignum_type *) 0),
+               q_negative_p, 0);
+          return (quotient);
+        }
       }
   }
 }
@@ -318,194 +319,109 @@ s48_bignum_remainder(bignum_type numerator, bignum_type denominator)
     case bignum_comparison_less:
       return (BIGNUM_MAYBE_COPY (numerator));
     case bignum_comparison_greater:
-    default:                                   /* to appease gcc -Wall */
+    default:                                        /* to appease gcc -Wall */
       {
-       bignum_type remainder;
-       if ((BIGNUM_LENGTH (denominator)) == 1)
-         {
-           bignum_digit_type digit = (BIGNUM_REF (denominator, 0));
-           if (digit == 1)
-             return (BIGNUM_ZERO ());
-           if (digit < BIGNUM_RADIX_ROOT)
-             return
-               (bignum_remainder_unsigned_small_denominator
-                (numerator, digit, (BIGNUM_NEGATIVE_P (numerator))));
-           bignum_divide_unsigned_medium_denominator
-             (numerator, digit,
-              ((bignum_type *) 0), (&remainder),
-              0, (BIGNUM_NEGATIVE_P (numerator)));
-         }
-       else
-         bignum_divide_unsigned_large_denominator
-           (numerator, denominator,
-            ((bignum_type *) 0), (&remainder),
-            0, (BIGNUM_NEGATIVE_P (numerator)));
-       return (remainder);
+        bignum_type remainder;
+        if ((BIGNUM_LENGTH (denominator)) == 1)
+          {
+            bignum_digit_type digit = (BIGNUM_REF (denominator, 0));
+            if (digit == 1)
+              return (BIGNUM_ZERO ());
+            if (digit < BIGNUM_RADIX_ROOT)
+              return
+                (bignum_remainder_unsigned_small_denominator
+                 (numerator, digit, (BIGNUM_NEGATIVE_P (numerator))));
+            bignum_divide_unsigned_medium_denominator
+              (numerator, digit,
+               ((bignum_type *) 0), (&remainder),
+               0, (BIGNUM_NEGATIVE_P (numerator)));
+          }
+        else
+          bignum_divide_unsigned_large_denominator
+            (numerator, denominator,
+             ((bignum_type *) 0), (&remainder),
+             0, (BIGNUM_NEGATIVE_P (numerator)));
+        return (remainder);
       }
     }
 }
 
-/* These procedures depend on the non-portable type `unsigned long'.
-   If your compiler doesn't support this type, either define the
-   switch `BIGNUM_NO_ULONG' to disable them (in "bignum.h"), or write
-   new versions that don't use this type. */
-
-#ifndef BIGNUM_NO_ULONG
-
-bignum_type
-s48_long_to_bignum(long n)
-{
-  int negative_p;
-  bignum_digit_type result_digits [BIGNUM_DIGITS_FOR_LONG];
-  bignum_digit_type * end_digits = result_digits;
-  /* Special cases win when these small constants are cached. */
-  if (n == 0) return (BIGNUM_ZERO ());
-  if (n == 1) return (BIGNUM_ONE (0));
-  if (n == -1) return (BIGNUM_ONE (1));
-  {
-    unsigned long accumulator = ((negative_p = (n < 0)) ? (-n) : n);
-    do
-      {
-       (*end_digits++) = (accumulator & BIGNUM_DIGIT_MASK);
-       accumulator >>= BIGNUM_DIGIT_LENGTH;
-      }
-    while (accumulator != 0);
+#define FOO_TO_BIGNUM(name,type,utype) \
+  bignum_type s48_##name##_to_bignum(type n)                           \
+  {                                                                    \
+    int negative_p;                                                    \
+    bignum_digit_type result_digits [BIGNUM_DIGITS_FOR(type)];         \
+    bignum_digit_type * end_digits = result_digits;                    \
+    /* Special cases win when these small constants are cached. */     \
+    if (n == 0) return (BIGNUM_ZERO ());                               \
+    if (n == 1) return (BIGNUM_ONE (0));                               \
+    if (n == -1) return (BIGNUM_ONE (1));                              \
+    {                                                                  \
+      utype accumulator = ((negative_p = (n < 0)) ? (-n) : n);         \
+      do                                                               \
+        {                                                              \
+          (*end_digits++) = (accumulator & BIGNUM_DIGIT_MASK);         \
+          accumulator >>= BIGNUM_DIGIT_LENGTH;                         \
+        }                                                              \
+      while (accumulator != 0);                                        \
+    }                                                                  \
+    {                                                                  \
+      bignum_type result =                                             \
+        (bignum_allocate ((end_digits - result_digits), negative_p));  \
+      bignum_digit_type * scan_digits = result_digits;                 \
+      bignum_digit_type * scan_result = (BIGNUM_START_PTR (result));   \
+      while (scan_digits < end_digits)                                 \
+        (*scan_result++) = (*scan_digits++);                           \
+      return (result);                                                 \
+    }                                                                  \
   }
-  {
-    bignum_type result =
-      (bignum_allocate ((end_digits - result_digits), negative_p));
-    bignum_digit_type * scan_digits = result_digits;
-    bignum_digit_type * scan_result = (BIGNUM_START_PTR (result));
-    while (scan_digits < end_digits)
-      (*scan_result++) = (*scan_digits++);
-    return (result);
-  }
-}
 
-bignum_type
-s48_long_long_to_bignum(s64 n)
-{
-  int negative_p;
-  bignum_digit_type result_digits [BIGNUM_DIGITS_FOR_LONG_LONG];
-  bignum_digit_type * end_digits = result_digits;
-  /* Special cases win when these small constants are cached. */
-  if (n == 0) return (BIGNUM_ZERO ());
-  if (n == 1) return (BIGNUM_ONE (0));
-  if (n == -1) return (BIGNUM_ONE (1));
-  {
-    u64 accumulator = ((negative_p = (n < 0)) ? (-n) : n);
-    do
-      {
-       (*end_digits++) = (accumulator & BIGNUM_DIGIT_MASK);
-       accumulator >>= BIGNUM_DIGIT_LENGTH;
-      }
-    while (accumulator != 0);
-  }
-  {
-    bignum_type result =
-      (bignum_allocate ((end_digits - result_digits), negative_p));
-    bignum_digit_type * scan_digits = result_digits;
-    bignum_digit_type * scan_result = (BIGNUM_START_PTR (result));
-    while (scan_digits < end_digits)
-      (*scan_result++) = (*scan_digits++);
-    return (result);
+FOO_TO_BIGNUM(long,long,unsigned long)
+FOO_TO_BIGNUM(ulong,unsigned long,unsigned long)
+FOO_TO_BIGNUM(long_long,s64,u64)
+FOO_TO_BIGNUM(ulong_long,u64,u64)
+
+#define BIGNUM_TO_FOO(name,type,utype) \
+  type s48_bignum_to_##name(bignum_type bignum)                                     \
+  {                                                                                 \
+    if (BIGNUM_ZERO_P (bignum))                                                     \
+      return (0);                                                                   \
+    {                                                                               \
+      utype accumulator = 0;                                                        \
+      bignum_digit_type * start = (BIGNUM_START_PTR (bignum));                      \
+      bignum_digit_type * scan = (start + (BIGNUM_LENGTH (bignum)));                \
+      while (start < scan)                                                          \
+        accumulator = ((accumulator << BIGNUM_DIGIT_LENGTH) + (*--scan));           \
+      return ((BIGNUM_NEGATIVE_P (bignum)) ? (-((type)accumulator)) : accumulator); \
+    }                                                                               \
   }
-}
 
-bignum_type
-s48_ulong_long_to_bignum(u64 n)
-{
-  bignum_digit_type result_digits [BIGNUM_DIGITS_FOR_LONG_LONG];
-  bignum_digit_type * end_digits = result_digits;
-  /* Special cases win when these small constants are cached. */
-  if (n == 0) return (BIGNUM_ZERO ());
-  if (n == 1) return (BIGNUM_ONE (0));
-  {
-    u64 accumulator = n;
-    do
-      {
-       (*end_digits++) = (accumulator & BIGNUM_DIGIT_MASK);
-       accumulator >>= BIGNUM_DIGIT_LENGTH;
-      }
-    while (accumulator != 0);
-  }
-  {
-    bignum_type result =
-      (bignum_allocate ((end_digits - result_digits), 0));
-    bignum_digit_type * scan_digits = result_digits;
-    bignum_digit_type * scan_result = (BIGNUM_START_PTR (result));
-    while (scan_digits < end_digits)
-      (*scan_result++) = (*scan_digits++);
-    return (result);
-  }
-}
+BIGNUM_TO_FOO(long,long,unsigned long)
+BIGNUM_TO_FOO(ulong,unsigned long,unsigned long)
+BIGNUM_TO_FOO(long_long,s64,u64)
+BIGNUM_TO_FOO(ulong_long,u64,u64)
 
-long
-s48_bignum_to_long(bignum_type bignum)
-{
-  if (BIGNUM_ZERO_P (bignum))
-    return (0);
-  {
-    unsigned long accumulator = 0;
-    bignum_digit_type * start = (BIGNUM_START_PTR (bignum));
-    bignum_digit_type * scan = (start + (BIGNUM_LENGTH (bignum)));
-    while (start < scan)
-      accumulator = ((accumulator << BIGNUM_DIGIT_LENGTH) + (*--scan));
-    return ((BIGNUM_NEGATIVE_P (bignum)) ? (-((long)accumulator)) : accumulator);
-  }
-}
-
-bignum_type
-s48_ulong_to_bignum(unsigned long n)
-{
-  bignum_digit_type result_digits [BIGNUM_DIGITS_FOR_LONG];
-  bignum_digit_type * end_digits = result_digits;
-  /* Special cases win when these small constants are cached. */
-  if (n == 0) return (BIGNUM_ZERO ());
-  if (n == 1) return (BIGNUM_ONE (0));
-  {
-    unsigned long accumulator = n;
-    do
-      {
-       (*end_digits++) = (accumulator & BIGNUM_DIGIT_MASK);
-       accumulator >>= BIGNUM_DIGIT_LENGTH;
-      }
-    while (accumulator != 0);
-  }
-  {
-    bignum_type result =
-      (bignum_allocate ((end_digits - result_digits), 0));
-    bignum_digit_type * scan_digits = result_digits;
-    bignum_digit_type * scan_result = (BIGNUM_START_PTR (result));
-    while (scan_digits < end_digits)
-      (*scan_result++) = (*scan_digits++);
-    return (result);
-  }
-}
-
-unsigned long
-s48_bignum_to_ulong(bignum_type bignum)
+double
+s48_bignum_to_double(bignum_type bignum)
 {
   if (BIGNUM_ZERO_P (bignum))
     return (0);
   {
-    unsigned long accumulator = 0;
+    double accumulator = 0;
     bignum_digit_type * start = (BIGNUM_START_PTR (bignum));
     bignum_digit_type * scan = (start + (BIGNUM_LENGTH (bignum)));
     while (start < scan)
-      accumulator = ((accumulator << BIGNUM_DIGIT_LENGTH) + (*--scan));
-    return (accumulator);
+      accumulator = ((accumulator * BIGNUM_RADIX) + (*--scan));
+    return ((BIGNUM_NEGATIVE_P (bignum)) ? (-accumulator) : accumulator);
   }
 }
 
-#endif /* not BIGNUM_NO_ULONG */
-
-#define DTB_WRITE_DIGIT(factor)                                                \
-{                                                                      \
-  significand *= (factor);                                             \
-  digit = ((bignum_digit_type) significand);                           \
-  (*--scan) = digit;                                                   \
-  significand -= ((double) digit);                                     \
+#define DTB_WRITE_DIGIT(factor)                                                \
+{                                                                        \
+  significand *= (factor);                                                \
+  digit = ((bignum_digit_type) significand);                                \
+  (*--scan) = digit;                                                        \
+  significand -= ((double) digit);                                        \
 }
 
 bignum_type
@@ -527,13 +443,13 @@ s48_double_to_bignum(double x)
       DTB_WRITE_DIGIT (1L << odd_bits);
     while (start < scan)
       {
-       if (significand == 0)
-         {
-           while (start < scan)
-             (*--scan) = 0;
-           break;
-         }
-       DTB_WRITE_DIGIT (BIGNUM_RADIX);
+        if (significand == 0)
+          {
+            while (start < scan)
+              (*--scan) = 0;
+            break;
+          }
+        DTB_WRITE_DIGIT (BIGNUM_RADIX);
       }
     return (result);
   }
@@ -541,24 +457,9 @@ s48_double_to_bignum(double x)
 
 #undef DTB_WRITE_DIGIT
 
-double
-s48_bignum_to_double(bignum_type bignum)
-{
-  if (BIGNUM_ZERO_P (bignum))
-    return (0);
-  {
-    double accumulator = 0;
-    bignum_digit_type * start = (BIGNUM_START_PTR (bignum));
-    bignum_digit_type * scan = (start + (BIGNUM_LENGTH (bignum)));
-    while (start < scan)
-      accumulator = ((accumulator * BIGNUM_RADIX) + (*--scan));
-    return ((BIGNUM_NEGATIVE_P (bignum)) ? (-accumulator) : accumulator);
-  }
-}
-
 int
 s48_bignum_fits_in_word_p(bignum_type bignum, long word_length,
-                         int twos_complement_p)
+                          int twos_complement_p)
 {
   unsigned int n_bits = (twos_complement_p ? (word_length - 1) : word_length);
   BIGNUM_ASSERT (n_bits > 0);
@@ -569,11 +470,11 @@ s48_bignum_fits_in_word_p(bignum_type bignum, long word_length,
     return
       ((length < max_digits) ||
        ((length == max_digits) &&
-       ((((msd = (BIGNUM_REF (bignum, (length - 1)))) <
-          (max = (1L << (n_bits - ((length - 1) * BIGNUM_DIGIT_LENGTH))))) ||
-         (twos_complement_p &&
-          (msd == max) &&
-          (BIGNUM_NEGATIVE_P (bignum)))))));
+        ((((msd = (BIGNUM_REF (bignum, (length - 1)))) <
+           (max = (1L << (n_bits - ((length - 1) * BIGNUM_DIGIT_LENGTH))))) ||
+          (twos_complement_p &&
+           (msd == max) &&
+           (BIGNUM_NEGATIVE_P (bignum)))))));
   }
 }
 
@@ -591,8 +492,8 @@ s48_bignum_length_in_bits(bignum_type bignum)
     bignum_destructive_scale_up (result, BIGNUM_DIGIT_LENGTH);
     while (digit > 0)
       {
-       bignum_destructive_add (result, ((bignum_digit_type) 1));
-       digit >>= 1;
+        bignum_destructive_add (result, ((bignum_digit_type) 1));
+        digit >>= 1;
       }
     return (bignum_trim (result));
   }
@@ -609,10 +510,10 @@ s48_bignum_length_upper_limit(void)
 
 bignum_type
 s48_digit_stream_to_bignum(unsigned int n_digits,
-                          unsigned int *producer(bignum_procedure_context),
-                          bignum_procedure_context context,
-                          unsigned int radix,
-                          int negative_p)
+                           unsigned int *producer(bignum_procedure_context),
+                           bignum_procedure_context context,
+                           unsigned int radix,
+                           int negative_p)
 {
   BIGNUM_ASSERT ((radix > 1) && (radix <= BIGNUM_RADIX_ROOT));
   if (n_digits == 0)
@@ -628,21 +529,21 @@ s48_digit_stream_to_bignum(unsigned int n_digits,
       unsigned int radix_copy = radix;
       unsigned int log_radix = 0;
       while (radix_copy > 0)
-       {
-         radix_copy >>= 1;
-         log_radix += 1;
-       }
+        {
+          radix_copy >>= 1;
+          log_radix += 1;
+        }
       /* This length will be at least as large as needed. */
       length = (BIGNUM_BITS_TO_DIGITS (n_digits * log_radix));
     }
     {
       bignum_type result = (bignum_allocate_zeroed (length, negative_p));
       while ((n_digits--) > 0)
-       {
-         bignum_destructive_scale_up (result, ((bignum_digit_type) radix));
-         bignum_destructive_add
-           (result, ((bignum_digit_type) ((*producer) (context))));
-       }
+        {
+          bignum_destructive_scale_up (result, ((bignum_digit_type) radix));
+          bignum_destructive_add
+            (result, ((bignum_digit_type) ((*producer) (context))));
+        }
       return (bignum_trim (result));
     }
   }
@@ -668,8 +569,8 @@ bignum_equal_p_unsigned(bignum_type x, bignum_type y)
       bignum_digit_type * scan_y = (BIGNUM_START_PTR (y));
       bignum_digit_type * end_x = (scan_x + length);
       while (scan_x < end_x)
-       if ((*scan_x++) != (*scan_y++))
-         return (0);
+        if ((*scan_x++) != (*scan_y++))
+          return (0);
       return (1);
     }
 }
@@ -689,12 +590,12 @@ bignum_compare_unsigned(bignum_type x, bignum_type y)
     bignum_digit_type * scan_y = ((BIGNUM_START_PTR (y)) + y_length);
     while (start_x < scan_x)
       {
-       bignum_digit_type digit_x = (*--scan_x);
-       bignum_digit_type digit_y = (*--scan_y);
-       if (digit_x < digit_y)
-         return (bignum_comparison_less);
-       if (digit_x > digit_y)
-         return (bignum_comparison_greater);
+        bignum_digit_type digit_x = (*--scan_x);
+        bignum_digit_type digit_y = (*--scan_y);
+        if (digit_x < digit_y)
+          return (bignum_comparison_less);
+        if (digit_x > digit_y)
+          return (bignum_comparison_greater);
       }
   }
   return (bignum_comparison_equal);
@@ -722,42 +623,42 @@ bignum_add_unsigned(bignum_type x, bignum_type y, int negative_p)
       bignum_digit_type * scan_y = (BIGNUM_START_PTR (y));
       bignum_digit_type * end_y = (scan_y + (BIGNUM_LENGTH (y)));
       while (scan_y < end_y)
-       {
-         sum = ((*scan_x++) + (*scan_y++) + carry);
-         if (sum < BIGNUM_RADIX)
-           {
-             (*scan_r++) = sum;
-             carry = 0;
-           }
-         else
-           {
-             (*scan_r++) = (sum - BIGNUM_RADIX);
-             carry = 1;
-           }
-       }
+        {
+          sum = ((*scan_x++) + (*scan_y++) + carry);
+          if (sum < BIGNUM_RADIX)
+            {
+              (*scan_r++) = sum;
+              carry = 0;
+            }
+          else
+            {
+              (*scan_r++) = (sum - BIGNUM_RADIX);
+              carry = 1;
+            }
+        }
     }
     {
       bignum_digit_type * end_x = ((BIGNUM_START_PTR (x)) + x_length);
       if (carry != 0)
-       while (scan_x < end_x)
-         {
-           sum = ((*scan_x++) + 1);
-           if (sum < BIGNUM_RADIX)
-             {
-               (*scan_r++) = sum;
-               carry = 0;
-               break;
-             }
-           else
-             (*scan_r++) = (sum - BIGNUM_RADIX);
-         }
+        while (scan_x < end_x)
+          {
+            sum = ((*scan_x++) + 1);
+            if (sum < BIGNUM_RADIX)
+              {
+                (*scan_r++) = sum;
+                carry = 0;
+                break;
+              }
+            else
+              (*scan_r++) = (sum - BIGNUM_RADIX);
+          }
       while (scan_x < end_x)
-       (*scan_r++) = (*scan_x++);
+        (*scan_r++) = (*scan_x++);
     }
     if (carry != 0)
       {
-       (*scan_r) = 1;
-       return (r);
+        (*scan_r) = 1;
+        return (r);
       }
     return (bignum_shorten_length (r, x_length));
   }
@@ -775,9 +676,9 @@ bignum_subtract_unsigned(bignum_type x, bignum_type y)
       return (BIGNUM_ZERO ());
     case bignum_comparison_less:
       {
-       bignum_type z = x;
-       x = y;
-       y = z;
+        bignum_type z = x;
+        x = y;
+        y = z;
       }
       negative_p = 1;
       break;
@@ -796,38 +697,38 @@ bignum_subtract_unsigned(bignum_type x, bignum_type y)
       bignum_digit_type * scan_y = (BIGNUM_START_PTR (y));
       bignum_digit_type * end_y = (scan_y + (BIGNUM_LENGTH (y)));
       while (scan_y < end_y)
-       {
-         difference = (((*scan_x++) - (*scan_y++)) - borrow);
-         if (difference < 0)
-           {
-             (*scan_r++) = (difference + BIGNUM_RADIX);
-             borrow = 1;
-           }
-         else
-           {
-             (*scan_r++) = difference;
-             borrow = 0;
-           }
-       }
+        {
+          difference = (((*scan_x++) - (*scan_y++)) - borrow);
+          if (difference < 0)
+            {
+              (*scan_r++) = (difference + BIGNUM_RADIX);
+              borrow = 1;
+            }
+          else
+            {
+              (*scan_r++) = difference;
+              borrow = 0;
+            }
+        }
     }
     {
       bignum_digit_type * end_x = ((BIGNUM_START_PTR (x)) + x_length);
       if (borrow != 0)
-       while (scan_x < end_x)
-         {
-           difference = ((*scan_x++) - borrow);
-           if (difference < 0)
-             (*scan_r++) = (difference + BIGNUM_RADIX);
-           else
-             {
-               (*scan_r++) = difference;
-               borrow = 0;
-               break;
-             }
-         }
+        while (scan_x < end_x)
+          {
+            difference = ((*scan_x++) - borrow);
+            if (difference < 0)
+              (*scan_r++) = (difference + BIGNUM_RADIX);
+            else
+              {
+                (*scan_r++) = difference;
+                borrow = 0;
+                break;
+              }
+          }
       BIGNUM_ASSERT (borrow == 0);
       while (scan_x < end_x)
-       (*scan_r++) = (*scan_x++);
+        (*scan_r++) = (*scan_x++);
     }
     return (bignum_trim (r));
   }
@@ -835,9 +736,9 @@ bignum_subtract_unsigned(bignum_type x, bignum_type y)
 
 /* Multiplication
    Maximum value for product_low or product_high:
-       ((R * R) + (R * (R - 2)) + (R - 1))
+        ((R * R) + (R * (R - 2)) + (R - 1))
    Maximum value for carry: ((R * (R - 1)) + (R - 1))
-       where R == BIGNUM_RADIX_ROOT */
+        where R == BIGNUM_RADIX_ROOT */
 
 bignum_type
 bignum_multiply_unsigned(bignum_type x, bignum_type y, int negative_p)
@@ -871,33 +772,33 @@ bignum_multiply_unsigned(bignum_type x, bignum_type y, int negative_p)
 #define product_high carry
     while (scan_x < end_x)
       {
-       x_digit = (*scan_x++);
-       x_digit_low = (HD_LOW (x_digit));
-       x_digit_high = (HD_HIGH (x_digit));
-       carry = 0;
-       scan_y = start_y;
-       scan_r = (start_r++);
-       while (scan_y < end_y)
-         {
-           y_digit = (*scan_y++);
-           y_digit_low = (HD_LOW (y_digit));
-           y_digit_high = (HD_HIGH (y_digit));
-           product_low =
-             ((*scan_r) +
-              (x_digit_low * y_digit_low) +
-              (HD_LOW (carry)));
-           product_high =
-             ((x_digit_high * y_digit_low) +
-              (x_digit_low * y_digit_high) +
-              (HD_HIGH (product_low)) +
-              (HD_HIGH (carry)));
-           (*scan_r++) =
-             (HD_CONS ((HD_LOW (product_high)), (HD_LOW (product_low))));
-           carry =
-             ((x_digit_high * y_digit_high) +
-              (HD_HIGH (product_high)));
-         }
-       (*scan_r) += carry;
+        x_digit = (*scan_x++);
+        x_digit_low = (HD_LOW (x_digit));
+        x_digit_high = (HD_HIGH (x_digit));
+        carry = 0;
+        scan_y = start_y;
+        scan_r = (start_r++);
+        while (scan_y < end_y)
+          {
+            y_digit = (*scan_y++);
+            y_digit_low = (HD_LOW (y_digit));
+            y_digit_high = (HD_HIGH (y_digit));
+            product_low =
+              ((*scan_r) +
+               (x_digit_low * y_digit_low) +
+               (HD_LOW (carry)));
+            product_high =
+              ((x_digit_high * y_digit_low) +
+               (x_digit_low * y_digit_high) +
+               (HD_HIGH (product_low)) +
+               (HD_HIGH (carry)));
+            (*scan_r++) =
+              (HD_CONS ((HD_LOW (product_high)), (HD_LOW (product_low))));
+            carry =
+              ((x_digit_high * y_digit_high) +
+               (HD_HIGH (product_high)));
+          }
+        (*scan_r) += carry;
       }
     return (bignum_trim (r));
 #undef x_digit
@@ -908,7 +809,7 @@ bignum_multiply_unsigned(bignum_type x, bignum_type y, int negative_p)
 
 bignum_type
 bignum_multiply_unsigned_small_factor(bignum_type x, bignum_digit_type y,
-                                     int negative_p)
+                                      int negative_p)
 {
   bignum_length_type length_x = (BIGNUM_LENGTH (x));
   bignum_type p = (bignum_allocate ((length_x + 1), negative_p));
@@ -933,9 +834,9 @@ bignum_destructive_scale_up(bignum_type bignum, bignum_digit_type factor)
       two_digits = (*scan);
       product_low = ((factor * (HD_LOW (two_digits))) + (HD_LOW (carry)));
       product_high =
-       ((factor * (HD_HIGH (two_digits))) +
-        (HD_HIGH (product_low)) +
-        (HD_HIGH (carry)));
+        ((factor * (HD_HIGH (two_digits))) +
+         (HD_HIGH (product_low)) +
+         (HD_HIGH (carry)));
       (*scan++) = (HD_CONS ((HD_LOW (product_high)), (HD_LOW (product_low))));
       carry = (HD_HIGH (product_high));
     }
@@ -964,10 +865,10 @@ bignum_destructive_add(bignum_type bignum, bignum_digit_type n)
     {
       digit = ((*scan) + 1);
       if (digit < BIGNUM_RADIX)
-       {
-         (*scan) = digit;
-         return;
-       }
+        {
+          (*scan) = digit;
+          return;
+        }
       (*scan++) = (digit - BIGNUM_RADIX);
     }
 }
@@ -981,11 +882,11 @@ bignum_destructive_add(bignum_type bignum, bignum_digit_type n)
 
 void
 bignum_divide_unsigned_large_denominator(bignum_type numerator,
-                                        bignum_type denominator,
-                                        bignum_type * quotient,
-                                        bignum_type * remainder,
-                                        int q_negative_p,
-                                        int r_negative_p)
+                                         bignum_type denominator,
+                                         bignum_type * quotient,
+                                         bignum_type * remainder,
+                                         int q_negative_p,
+                                         int r_negative_p)
 {
   bignum_length_type length_n = ((BIGNUM_LENGTH (numerator)) + 1);
   bignum_length_type length_d = (BIGNUM_LENGTH (denominator));
@@ -1000,8 +901,8 @@ bignum_divide_unsigned_large_denominator(bignum_type numerator,
     bignum_digit_type v1 = (BIGNUM_REF ((denominator), (length_d - 1)));
     while (v1 < (BIGNUM_RADIX / 2))
       {
-       v1 <<= 1;
-       shift += 1;
+        v1 <<= 1;
+        shift += 1;
       }
   }
   if (shift == 0)
@@ -1018,7 +919,7 @@ bignum_divide_unsigned_large_denominator(bignum_type numerator,
       bignum_divide_unsigned_normalized (u, v, q);
       BIGNUM_DEALLOCATE (v);
       if (remainder != ((bignum_type *) 0))
-       bignum_destructive_unnormalization (u, shift);
+        bignum_destructive_unnormalization (u, shift);
     }
   if (quotient != ((bignum_type *) 0))
     (*quotient) = (bignum_trim (q));
@@ -1043,60 +944,60 @@ bignum_divide_unsigned_normalized(bignum_type u, bignum_type v, bignum_type q)
   bignum_digit_type * q_scan;
   bignum_digit_type v1 = (v_end[-1]);
   bignum_digit_type v2 = (v_end[-2]);
-  bignum_digit_type ph;        /* high half of double-digit product */
-  bignum_digit_type pl;        /* low half of double-digit product */
+  bignum_digit_type ph;        /* high half of double-digit product */
+  bignum_digit_type pl;        /* low half of double-digit product */
   bignum_digit_type guess;
-  bignum_digit_type gh;        /* high half-digit of guess */
-  bignum_digit_type ch;        /* high half of double-digit comparand */
+  bignum_digit_type gh;        /* high half-digit of guess */
+  bignum_digit_type ch;        /* high half of double-digit comparand */
   bignum_digit_type v2l = (HD_LOW (v2));
   bignum_digit_type v2h = (HD_HIGH (v2));
-  bignum_digit_type cl;        /* low half of double-digit comparand */
-#define gl ph                  /* low half-digit of guess */
+  bignum_digit_type cl;        /* low half of double-digit comparand */
+#define gl ph                        /* low half-digit of guess */
 #define uj pl
 #define qj ph
-  bignum_digit_type gm;                /* memory loc for reference parameter */
+  bignum_digit_type gm;                /* memory loc for reference parameter */
   if (q != BIGNUM_OUT_OF_BAND)
     q_scan = ((BIGNUM_START_PTR (q)) + (BIGNUM_LENGTH (q)));
   while (u_scan_limit < u_scan)
     {
       uj = (*--u_scan);
       if (uj != v1)
-       {
-         /* comparand =
-            (((((uj * BIGNUM_RADIX) + uj1) % v1) * BIGNUM_RADIX) + uj2);
-            guess = (((uj * BIGNUM_RADIX) + uj1) / v1); */
-         cl = (u_scan[-2]);
-         ch = (bignum_digit_divide (uj, (u_scan[-1]), v1, (&gm)));
-         guess = gm;
-       }
+        {
+          /* comparand =
+             (((((uj * BIGNUM_RADIX) + uj1) % v1) * BIGNUM_RADIX) + uj2);
+             guess = (((uj * BIGNUM_RADIX) + uj1) / v1); */
+          cl = (u_scan[-2]);
+          ch = (bignum_digit_divide (uj, (u_scan[-1]), v1, (&gm)));
+          guess = gm;
+        }
       else
-       {
-         cl = (u_scan[-2]);
-         ch = ((u_scan[-1]) + v1);
-         guess = (BIGNUM_RADIX - 1);
-       }
+        {
+          cl = (u_scan[-2]);
+          ch = ((u_scan[-1]) + v1);
+          guess = (BIGNUM_RADIX - 1);
+        }
       while (1)
-       {
-         /* product = (guess * v2); */
-         gl = (HD_LOW (guess));
-         gh = (HD_HIGH (guess));
-         pl = (v2l * gl);
-         ph = ((v2l * gh) + (v2h * gl) + (HD_HIGH (pl)));
-         pl = (HD_CONS ((HD_LOW (ph)), (HD_LOW (pl))));
-         ph = ((v2h * gh) + (HD_HIGH (ph)));
-         /* if (comparand >= product) */
-         if ((ch > ph) || ((ch == ph) && (cl >= pl)))
-           break;
-         guess -= 1;
-         /* comparand += (v1 << BIGNUM_DIGIT_LENGTH) */
-         ch += v1;
-         /* if (comparand >= (BIGNUM_RADIX * BIGNUM_RADIX)) */
-         if (ch >= BIGNUM_RADIX)
-           break;
-       }
+        {
+          /* product = (guess * v2); */
+          gl = (HD_LOW (guess));
+          gh = (HD_HIGH (guess));
+          pl = (v2l * gl);
+          ph = ((v2l * gh) + (v2h * gl) + (HD_HIGH (pl)));
+          pl = (HD_CONS ((HD_LOW (ph)), (HD_LOW (pl))));
+          ph = ((v2h * gh) + (HD_HIGH (ph)));
+          /* if (comparand >= product) */
+          if ((ch > ph) || ((ch == ph) && (cl >= pl)))
+            break;
+          guess -= 1;
+          /* comparand += (v1 << BIGNUM_DIGIT_LENGTH) */
+          ch += v1;
+          /* if (comparand >= (BIGNUM_RADIX * BIGNUM_RADIX)) */
+          if (ch >= BIGNUM_RADIX)
+            break;
+        }
       qj = (bignum_divide_subtract (v_start, v_end, guess, (--u_scan_start)));
       if (q != BIGNUM_OUT_OF_BAND)
-       (*--q_scan) = qj;
+        (*--q_scan) = qj;
     }
   return;
 #undef gl
@@ -1106,9 +1007,9 @@ bignum_divide_unsigned_normalized(bignum_type u, bignum_type v, bignum_type q)
 
 bignum_digit_type
 bignum_divide_subtract(bignum_digit_type * v_start,
-                      bignum_digit_type * v_end,
-                      bignum_digit_type guess,
-                      bignum_digit_type * u_start)
+                       bignum_digit_type * v_end,
+                       bignum_digit_type guess,
+                       bignum_digit_type * u_start)
 {
   bignum_digit_type * v_scan = v_start;
   bignum_digit_type * u_scan = u_start;
@@ -1125,22 +1026,22 @@ bignum_divide_subtract(bignum_digit_type * v_start,
 #define diff pl
     while (v_scan < v_end)
       {
-       v = (*v_scan++);
-       vl = (HD_LOW (v));
-       vh = (HD_HIGH (v));
-       pl = ((vl * gl) + (HD_LOW (carry)));
-       ph = ((vl * gh) + (vh * gl) + (HD_HIGH (pl)) + (HD_HIGH (carry)));
-       diff = ((*u_scan) - (HD_CONS ((HD_LOW (ph)), (HD_LOW (pl)))));
-       if (diff < 0)
-         {
-           (*u_scan++) = (diff + BIGNUM_RADIX);
-           carry = ((vh * gh) + (HD_HIGH (ph)) + 1);
-         }
-       else
-         {
-           (*u_scan++) = diff;
-           carry = ((vh * gh) + (HD_HIGH (ph)));
-         }
+        v = (*v_scan++);
+        vl = (HD_LOW (v));
+        vh = (HD_HIGH (v));
+        pl = ((vl * gl) + (HD_LOW (carry)));
+        ph = ((vl * gh) + (vh * gl) + (HD_HIGH (pl)) + (HD_HIGH (carry)));
+        diff = ((*u_scan) - (HD_CONS ((HD_LOW (ph)), (HD_LOW (pl)))));
+        if (diff < 0)
+          {
+            (*u_scan++) = (diff + BIGNUM_RADIX);
+            carry = ((vh * gh) + (HD_HIGH (ph)) + 1);
+          }
+        else
+          {
+            (*u_scan++) = diff;
+            carry = ((vh * gh) + (HD_HIGH (ph)));
+          }
       }
     if (carry == 0)
       return (guess);
@@ -1149,8 +1050,8 @@ bignum_divide_subtract(bignum_digit_type * v_start,
       (*u_scan) = (diff + BIGNUM_RADIX);
     else
       {
-       (*u_scan) = diff;
-       return (guess);
+        (*u_scan) = diff;
+        return (guess);
       }
 #undef vh
 #undef ph
@@ -1165,15 +1066,15 @@ bignum_divide_subtract(bignum_digit_type * v_start,
     {
       bignum_digit_type sum = ((*v_scan++) + (*u_scan) + carry);
       if (sum < BIGNUM_RADIX)
-       {
-         (*u_scan++) = sum;
-         carry = 0;
-       }
+        {
+          (*u_scan++) = sum;
+          carry = 0;
+        }
       else
-       {
-         (*u_scan++) = (sum - BIGNUM_RADIX);
-         carry = 1;
-       }
+        {
+          (*u_scan++) = (sum - BIGNUM_RADIX);
+          carry = 1;
+        }
     }
   if (carry == 1)
     {
@@ -1185,11 +1086,11 @@ bignum_divide_subtract(bignum_digit_type * v_start,
 
 void
 bignum_divide_unsigned_medium_denominator(bignum_type numerator,
-                                         bignum_digit_type denominator,
-                                         bignum_type * quotient,
-                                         bignum_type * remainder,
-                                         int q_negative_p,
-                                         int r_negative_p)
+                                          bignum_digit_type denominator,
+                                          bignum_type * quotient,
+                                          bignum_type * remainder,
+                                          int q_negative_p,
+                                          int r_negative_p)
 {
   bignum_length_type length_n = (BIGNUM_LENGTH (numerator));
   bignum_length_type length_q;
@@ -1220,24 +1121,24 @@ bignum_divide_unsigned_medium_denominator(bignum_type numerator,
     bignum_digit_type qj;
     if (quotient != ((bignum_type *) 0))
       {
-       while (start < scan)
-         {
-           r = (bignum_digit_divide (r, (*--scan), denominator, (&qj)));
-           (*scan) = qj;
-         }
-       (*quotient) = (bignum_trim (q));
+        while (start < scan)
+          {
+            r = (bignum_digit_divide (r, (*--scan), denominator, (&qj)));
+            (*scan) = qj;
+          }
+        (*quotient) = (bignum_trim (q));
       }
     else
       {
-       while (start < scan)
-         r = (bignum_digit_divide (r, (*--scan), denominator, (&qj)));
-       BIGNUM_DEALLOCATE (q);
+        while (start < scan)
+          r = (bignum_digit_divide (r, (*--scan), denominator, (&qj)));
+        BIGNUM_DEALLOCATE (q);
       }
     if (remainder != ((bignum_type *) 0))
       {
-       if (shift != 0)
-         r >>= shift;
-       (*remainder) = (bignum_digit_to_bignum (r, r_negative_p));
+        if (shift != 0)
+          r >>= shift;
+        (*remainder) = (bignum_digit_to_bignum (r, r_negative_p));
       }
   }
   return;
@@ -1245,7 +1146,7 @@ bignum_divide_unsigned_medium_denominator(bignum_type numerator,
 
 void
 bignum_destructive_normalization(bignum_type source, bignum_type target,
-                                int shift_left)
+                                 int shift_left)
 {
   bignum_digit_type digit;
   bignum_digit_type * scan_source = (BIGNUM_START_PTR (source));
@@ -1291,34 +1192,34 @@ bignum_destructive_unnormalization(bignum_type bignum, int shift_right)
    case of dividing two bignum digits by one bignum digit.  It is
    assumed that the numerator, denominator are normalized. */
 
-#define BDD_STEP(qn, j)                                                        \
-{                                                                      \
-  uj = (u[j]);                                                         \
-  if (uj != v1)                                                                \
-    {                                                                  \
-      uj_uj1 = (HD_CONS (uj, (u[j + 1])));                             \
-      guess = (uj_uj1 / v1);                                           \
-      comparand = (HD_CONS ((uj_uj1 % v1), (u[j + 2])));               \
-    }                                                                  \
-  else                                                                 \
-    {                                                                  \
-      guess = (BIGNUM_RADIX_ROOT - 1);                                 \
-      comparand = (HD_CONS (((u[j + 1]) + v1), (u[j + 2])));           \
-    }                                                                  \
-  while ((guess * v2) > comparand)                                     \
-    {                                                                  \
-      guess -= 1;                                                      \
-      comparand += (v1 << BIGNUM_HALF_DIGIT_LENGTH);                   \
-      if (comparand >= BIGNUM_RADIX)                                   \
-       break;                                                          \
-    }                                                                  \
-  qn = (bignum_digit_divide_subtract (v1, v2, guess, (&u[j])));                \
+#define BDD_STEP(qn, j)                                                        \
+{                                                                        \
+  uj = (u[j]);                                                                \
+  if (uj != v1)                                                                \
+    {                                                                        \
+      uj_uj1 = (HD_CONS (uj, (u[j + 1])));                                \
+      guess = (uj_uj1 / v1);                                                \
+      comparand = (HD_CONS ((uj_uj1 % v1), (u[j + 2])));                \
+    }                                                                        \
+  else                                                                        \
+    {                                                                        \
+      guess = (BIGNUM_RADIX_ROOT - 1);                                        \
+      comparand = (HD_CONS (((u[j + 1]) + v1), (u[j + 2])));                \
+    }                                                                        \
+  while ((guess * v2) > comparand)                                        \
+    {                                                                        \
+      guess -= 1;                                                        \
+      comparand += (v1 << BIGNUM_HALF_DIGIT_LENGTH);                        \
+      if (comparand >= BIGNUM_RADIX)                                        \
+        break;                                                                \
+    }                                                                        \
+  qn = (bignum_digit_divide_subtract (v1, v2, guess, (&u[j])));                \
 }
 
 bignum_digit_type
 bignum_digit_divide(bignum_digit_type uh, bignum_digit_type ul,
-                   bignum_digit_type v,
-                   bignum_digit_type * q) /* return value */
+                    bignum_digit_type v,
+                    bignum_digit_type * q) /* return value */
 {
   bignum_digit_type guess;
   bignum_digit_type comparand;
@@ -1332,15 +1233,15 @@ bignum_digit_divide(bignum_digit_type uh, bignum_digit_type ul,
   if (uh == 0)
     {
       if (ul < v)
-       {
-         (*q) = 0;
-         return (ul);
-       }
+        {
+          (*q) = 0;
+          return (ul);
+        }
       else if (ul == v)
-       {
-         (*q) = 1;
-         return (0);
-       }
+        {
+          (*q) = 1;
+          return (0);
+        }
     }
   (u[0]) = (HD_HIGH (uh));
   (u[1]) = (HD_LOW (uh));
@@ -1356,40 +1257,40 @@ bignum_digit_divide(bignum_digit_type uh, bignum_digit_type ul,
 
 #undef BDD_STEP
 
-#define BDDS_MULSUB(vn, un, carry_in)                                  \
-{                                                                      \
-  product = ((vn * guess) + carry_in);                                 \
-  diff = (un - (HD_LOW (product)));                                    \
-  if (diff < 0)                                                                \
-    {                                                                  \
-      un = (diff + BIGNUM_RADIX_ROOT);                                 \
-      carry = ((HD_HIGH (product)) + 1);                               \
-    }                                                                  \
-  else                                                                 \
-    {                                                                  \
-      un = diff;                                                       \
-      carry = (HD_HIGH (product));                                     \
-    }                                                                  \
-}
-
-#define BDDS_ADD(vn, un, carry_in)                                     \
-{                                                                      \
-  sum = (vn + un + carry_in);                                          \
-  if (sum < BIGNUM_RADIX_ROOT)                                         \
-    {                                                                  \
-      un = sum;                                                                \
-      carry = 0;                                                       \
-    }                                                                  \
-  else                                                                 \
-    {                                                                  \
-      un = (sum - BIGNUM_RADIX_ROOT);                                  \
-      carry = 1;                                                       \
-    }                                                                  \
+#define BDDS_MULSUB(vn, un, carry_in)                                        \
+{                                                                        \
+  product = ((vn * guess) + carry_in);                                        \
+  diff = (un - (HD_LOW (product)));                                        \
+  if (diff < 0)                                                                \
+    {                                                                        \
+      un = (diff + BIGNUM_RADIX_ROOT);                                        \
+      carry = ((HD_HIGH (product)) + 1);                                \
+    }                                                                        \
+  else                                                                        \
+    {                                                                        \
+      un = diff;                                                        \
+      carry = (HD_HIGH (product));                                        \
+    }                                                                        \
+}
+
+#define BDDS_ADD(vn, un, carry_in)                                        \
+{                                                                        \
+  sum = (vn + un + carry_in);                                                \
+  if (sum < BIGNUM_RADIX_ROOT)                                                \
+    {                                                                        \
+      un = sum;                                                                \
+      carry = 0;                                                        \
+    }                                                                        \
+  else                                                                        \
+    {                                                                        \
+      un = (sum - BIGNUM_RADIX_ROOT);                                        \
+      carry = 1;                                                        \
+    }                                                                        \
 }
 
 bignum_digit_type
 bignum_digit_divide_subtract(bignum_digit_type v1, bignum_digit_type v2,
-                            bignum_digit_type guess, bignum_digit_type * u)
+                             bignum_digit_type guess, bignum_digit_type * u)
 {
   {
     bignum_digit_type product;
@@ -1404,8 +1305,8 @@ bignum_digit_divide_subtract(bignum_digit_type v1, bignum_digit_type v2,
       (u[0]) = (diff + BIGNUM_RADIX);
     else
       {
-       (u[0]) = diff;
-       return (guess);
+        (u[0]) = diff;
+        return (guess);
       }
   }
   {
@@ -1424,11 +1325,11 @@ bignum_digit_divide_subtract(bignum_digit_type v1, bignum_digit_type v2,
 
 void
 bignum_divide_unsigned_small_denominator(bignum_type numerator,
-                                        bignum_digit_type denominator,
-                                        bignum_type * quotient,
-                                        bignum_type * remainder,
-                                        int q_negative_p,
-                                        int r_negative_p)
+                                         bignum_digit_type denominator,
+                                         bignum_type * quotient,
+                                         bignum_type * remainder,
+                                         int q_negative_p,
+                                         int r_negative_p)
 {
   bignum_type q = (bignum_new_sign (numerator, q_negative_p));
   bignum_digit_type r = (bignum_destructive_scale_down (q, denominator));
@@ -1478,9 +1379,9 @@ bignum_remainder_unsigned_small_denominator(
     {
       two_digits = (*--scan);
       r =
-       ((HD_CONS (((HD_CONS (r, (HD_HIGH (two_digits)))) % d),
-                  (HD_LOW (two_digits))))
-        % d);
+        ((HD_CONS (((HD_CONS (r, (HD_HIGH (two_digits)))) % d),
+                   (HD_LOW (two_digits))))
+         % d);
     }
   return (bignum_digit_to_bignum (r, negative_p));
 }
@@ -1587,7 +1488,7 @@ bignum_maybe_new_sign(bignum_type bignum, int negative_p)
 #endif /* not BIGNUM_FORCE_NEW_RESULTS */
     {
       bignum_type result =
-       (bignum_allocate ((BIGNUM_LENGTH (bignum)), negative_p));
+        (bignum_allocate ((BIGNUM_LENGTH (bignum)), negative_p));
       bignum_destructive_copy (bignum, result);
       return (result);
     }
@@ -1639,7 +1540,7 @@ s48_bignum_arithmetic_shift(bignum_type arg1, long n)
   if (BIGNUM_NEGATIVE_P(arg1) && n < 0)
     return
       s48_bignum_bitwise_not(bignum_magnitude_ash(s48_bignum_bitwise_not(arg1),
-                                                 n));
+                                                  n));
   else
     return bignum_magnitude_ash(arg1, n);
 }
@@ -1651,7 +1552,7 @@ s48_bignum_integer_length(bignum_type arg1)
 {
  return((BIGNUM_NEGATIVE_P (arg1)) 
         ? bignum_length_in_bits (s48_bignum_bitwise_not (arg1))
-       : bignum_length_in_bits (arg1));
+        : bignum_length_in_bits (arg1));
 }
 */
 
@@ -1660,7 +1561,7 @@ s48_bignum_bit_count(bignum_type arg1)
 {
  return((BIGNUM_NEGATIVE_P (arg1)) 
         ? bignum_unsigned_logcount (s48_bignum_bitwise_not (arg1))
-       : bignum_unsigned_logcount (arg1));
+        : bignum_unsigned_logcount (arg1));
 }
 
 #define AND_OP 0
@@ -1671,42 +1572,42 @@ bignum_type
 s48_bignum_bitwise_and(bignum_type arg1, bignum_type arg2)
 {
   return(
-        (BIGNUM_NEGATIVE_P (arg1))
-        ? (BIGNUM_NEGATIVE_P (arg2))
-          ? bignum_negneg_bitwise_op(AND_OP, arg1, arg2)
-          : bignum_posneg_bitwise_op(AND_OP, arg2, arg1)
-        : (BIGNUM_NEGATIVE_P (arg2))
-          ? bignum_posneg_bitwise_op(AND_OP, arg1, arg2)
-          : bignum_pospos_bitwise_op(AND_OP, arg1, arg2)
-        );
+         (BIGNUM_NEGATIVE_P (arg1))
+         ? (BIGNUM_NEGATIVE_P (arg2))
+           ? bignum_negneg_bitwise_op(AND_OP, arg1, arg2)
+           : bignum_posneg_bitwise_op(AND_OP, arg2, arg1)
+         : (BIGNUM_NEGATIVE_P (arg2))
+           ? bignum_posneg_bitwise_op(AND_OP, arg1, arg2)
+           : bignum_pospos_bitwise_op(AND_OP, arg1, arg2)
+         );
 }
 
 bignum_type
 s48_bignum_bitwise_ior(bignum_type arg1, bignum_type arg2)
 {
   return(
-        (BIGNUM_NEGATIVE_P (arg1))
-        ? (BIGNUM_NEGATIVE_P (arg2))
-          ? bignum_negneg_bitwise_op(IOR_OP, arg1, arg2)
-          : bignum_posneg_bitwise_op(IOR_OP, arg2, arg1)
-        : (BIGNUM_NEGATIVE_P (arg2))
-          ? bignum_posneg_bitwise_op(IOR_OP, arg1, arg2)
-          : bignum_pospos_bitwise_op(IOR_OP, arg1, arg2)
-        );
+         (BIGNUM_NEGATIVE_P (arg1))
+         ? (BIGNUM_NEGATIVE_P (arg2))
+           ? bignum_negneg_bitwise_op(IOR_OP, arg1, arg2)
+           : bignum_posneg_bitwise_op(IOR_OP, arg2, arg1)
+         : (BIGNUM_NEGATIVE_P (arg2))
+           ? bignum_posneg_bitwise_op(IOR_OP, arg1, arg2)
+           : bignum_pospos_bitwise_op(IOR_OP, arg1, arg2)
+         );
 }
 
 bignum_type
 s48_bignum_bitwise_xor(bignum_type arg1, bignum_type arg2)
 {
   return(
-        (BIGNUM_NEGATIVE_P (arg1))
-        ? (BIGNUM_NEGATIVE_P (arg2))
-          ? bignum_negneg_bitwise_op(XOR_OP, arg1, arg2)
-          : bignum_posneg_bitwise_op(XOR_OP, arg2, arg1)
-        : (BIGNUM_NEGATIVE_P (arg2))
-          ? bignum_posneg_bitwise_op(XOR_OP, arg1, arg2)
-          : bignum_pospos_bitwise_op(XOR_OP, arg1, arg2)
-        );
+         (BIGNUM_NEGATIVE_P (arg1))
+         ? (BIGNUM_NEGATIVE_P (arg2))
+           ? bignum_negneg_bitwise_op(XOR_OP, arg1, arg2)
+           : bignum_posneg_bitwise_op(XOR_OP, arg2, arg1)
+         : (BIGNUM_NEGATIVE_P (arg2))
+           ? bignum_posneg_bitwise_op(XOR_OP, arg1, arg2)
+           : bignum_pospos_bitwise_op(XOR_OP, arg1, arg2)
+         );
 }
 
 /* ash for the magnitude */
@@ -1728,7 +1629,7 @@ bignum_magnitude_ash(bignum_type arg1, long n)
     bit_offset =   n % BIGNUM_DIGIT_LENGTH;
     
     result = bignum_allocate_zeroed (BIGNUM_LENGTH (arg1) + digit_offset + 1,
-                                    BIGNUM_NEGATIVE_P(arg1));
+                                     BIGNUM_NEGATIVE_P(arg1));
 
     scanr = BIGNUM_START_PTR (result) + digit_offset;
     scan1 = BIGNUM_START_PTR (arg1);
@@ -1743,7 +1644,7 @@ bignum_magnitude_ash(bignum_type arg1, long n)
     }
   }
   else if (n < 0
-          && (-n >= (BIGNUM_LENGTH (arg1) * (bignum_length_type) BIGNUM_DIGIT_LENGTH)))
+           && (-n >= (BIGNUM_LENGTH (arg1) * (bignum_length_type) BIGNUM_DIGIT_LENGTH)))
     result = BIGNUM_ZERO ();
 
   else if (n < 0) {
@@ -1751,7 +1652,7 @@ bignum_magnitude_ash(bignum_type arg1, long n)
     bit_offset =   -n % BIGNUM_DIGIT_LENGTH;
     
     result = bignum_allocate_zeroed (BIGNUM_LENGTH (arg1) - digit_offset,
-                                    BIGNUM_NEGATIVE_P(arg1));
+                                     BIGNUM_NEGATIVE_P(arg1));
     
     scanr = BIGNUM_START_PTR (result);
     scan1 = BIGNUM_START_PTR (arg1) + digit_offset;
@@ -1760,7 +1661,7 @@ bignum_magnitude_ash(bignum_type arg1, long n)
     while (scanr < end) {
       *scanr =  (*scan1++ & BIGNUM_DIGIT_MASK) >> bit_offset ;
       *scanr = (*scanr | 
-       *scan1 << (BIGNUM_DIGIT_LENGTH - bit_offset)) & BIGNUM_DIGIT_MASK;
+        *scan1 << (BIGNUM_DIGIT_LENGTH - bit_offset)) & BIGNUM_DIGIT_MASK;
       scanr++;
     }
     *scanr =  (*scan1++ & BIGNUM_DIGIT_MASK) >> bit_offset ;
@@ -1797,8 +1698,8 @@ bignum_pospos_bitwise_op(int op, bignum_type arg1, bignum_type arg2)
     digit2 = (scan2 < end2) ? *scan2++ : 0;
     /*
     fprintf(stderr, "[pospos op = %d, i = %ld, d1 = %lx, d2 = %lx]\n",
-           op, endr - scanr, digit1, digit2);
-           */
+            op, endr - scanr, digit1, digit2);
+            */
     *scanr++ = (op == 0) ? digit1 & digit2 :
                (op == 1) ? digit1 | digit2 :
                            digit1 ^ digit2;
@@ -1841,8 +1742,8 @@ bignum_posneg_bitwise_op(int op, bignum_type arg1, bignum_type arg2)
       carry2 = 0;
     else
       {
-       digit2 = (digit2 - BIGNUM_RADIX);
-       carry2 = 1;
+        digit2 = (digit2 - BIGNUM_RADIX);
+        carry2 = 1;
       }
     
     *scanr++ = (op == AND_OP) ? digit1 & digit2 :
@@ -1891,16 +1792,16 @@ bignum_negneg_bitwise_op(int op, bignum_type arg1, bignum_type arg2)
       carry1 = 0;
     else
       {
-       digit1 = (digit1 - BIGNUM_RADIX);
-       carry1 = 1;
+        digit1 = (digit1 - BIGNUM_RADIX);
+        carry1 = 1;
       }
     
     if (digit2 < BIGNUM_RADIX)
       carry2 = 0;
     else
       {
-       digit2 = (digit2 - BIGNUM_RADIX);
-       carry2 = 1;
+        digit2 = (digit2 - BIGNUM_RADIX);
+        carry2 = 1;
       }
     
     *scanr++ = (op == 0) ? digit1 & digit2 :
@@ -1934,8 +1835,8 @@ bignum_negate_magnitude(bignum_type arg)
       carry = 0;
     else
       {
-       digit = (digit - BIGNUM_RADIX);
-       carry = 1;
+        digit = (digit - BIGNUM_RADIX);
+        carry = 1;
       }
     
     *scan++ = digit;
@@ -1963,7 +1864,7 @@ bignum_unsigned_logcount(bignum_type arg)
   while (scan < end) {
       digit = *scan++ & BIGNUM_DIGIT_MASK;
       for (i = 0; i++ < BIGNUM_DIGIT_LENGTH; digit = digit >> 1L)
-         result += digit & 1L;
+          result += digit & 1L;
   }
 
   return (result);
@@ -1973,8 +1874,8 @@ int
 bignum_logbitp(int shift, bignum_type arg)
 {
   return((BIGNUM_NEGATIVE_P (arg)) 
-        ? !bignum_unsigned_logbitp (shift, s48_bignum_bitwise_not (arg))
-        : bignum_unsigned_logbitp (shift,arg));
+         ? !bignum_unsigned_logbitp (shift, s48_bignum_bitwise_not (arg))
+         : bignum_unsigned_logbitp (shift,arg));
 }
 
 int
index cc182ab2b3df8fe51b685beceeebb1a88abc4b36..d28a485a0199e38e79811b1effde2a02b600246f 100644 (file)
@@ -71,6 +71,8 @@ DLLEXPORT bignum_type s48_ulong_long_to_bignum(u64 n);
 DLLEXPORT bignum_type s48_ulong_to_bignum(unsigned long);
 long s48_bignum_to_long(bignum_type);
 unsigned long s48_bignum_to_ulong(bignum_type);
+s64 s48_bignum_to_long_long(bignum_type);
+u64 s48_bignum_to_ulong_long(bignum_type);
 bignum_type s48_double_to_bignum(double);
 double s48_bignum_to_double(bignum_type);
 int s48_bignum_fits_in_word_p(bignum_type, long word_length,
index dc80e496086a23cf069b0b198c1c0f7c3fc6734e..c99ad1c775655303637dfe255435adedb0efe79a 100644 (file)
@@ -114,11 +114,8 @@ typedef long bignum_length_type;
 #define BIGNUM_BITS_TO_DIGITS(n)                                       \
   (((n) + (BIGNUM_DIGIT_LENGTH - 1)) / BIGNUM_DIGIT_LENGTH)
 
-#define BIGNUM_DIGITS_FOR_LONG                                         \
-  (BIGNUM_BITS_TO_DIGITS ((sizeof (long)) * CHAR_BIT))
-
-#define BIGNUM_DIGITS_FOR_LONG_LONG                                    \
-  (BIGNUM_BITS_TO_DIGITS ((sizeof (s64)) * CHAR_BIT))
+#define BIGNUM_DIGITS_FOR(type) \
+  (BIGNUM_BITS_TO_DIGITS ((sizeof (type)) * CHAR_BIT))
 
 #ifndef BIGNUM_DISABLE_ASSERTION_CHECKS