Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] View of /sml/trunk/src/compiler/MiscUtil/bignums/bigint.sml
ViewVC logotype

View of /sml/trunk/src/compiler/MiscUtil/bignums/bigint.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 17 - (download) (annotate)
Wed Mar 11 21:00:18 1998 UTC (22 years, 7 months ago)
Original Path: sml/branches/SMLNJ/src/compiler/MiscUtil/bignums/bigint.sml
File size: 1368 byte(s)
This commit was manufactured by cvs2svn to create branch 'SMLNJ'.
(* Copyright 1989 by AT&T Bell Laboratories *)
structure Bigint :> BIGINT = struct

type bigint = bool list

fun bigint 0 = nil
  | bigint i = let val x = i div 2
		in (x+x<i)::bigint x
	       end

fun adwc(false::ar, false::br, carry) = carry::adwc(ar,br,false)
  | adwc(a::ar,  false::br, false) = a::adwc(ar,br,false)
  | adwc(false::ar, b::br, false) = b::adwc(ar,br,false)
  | adwc(true::ar, true::br, carry) = carry::adwc(ar,br,true)
  | adwc(a::ar, true::br, true) = a::adwc(ar,br,true)
  | adwc(true::ar, b::br, true) = b::adwc(ar,br,true)
  | adwc(nil, false::br, carry) = carry::adwc(nil,br,false)
  | adwc(nil, b::br, false) = b::adwc(nil,br,false)
  | adwc(nil, true::br, true) = false::adwc(nil,br,true)
  | adwc(nil, nil, false) = nil
  | adwc(nil, nil, true) = [true]
  | adwc(a, nil, carry) = adwc(nil, a, carry)

fun a + b = adwc(a,b,false)

fun a * nil = nil
  | (false::a) * b = a * (false::b)
  | (true::a) * b = b + a * (false::b)
  | nil * b = nil

fun getbit(a::r, 0) = a
  | getbit(_::r, i) = getbit(r,i-1)
  | getbit(nil, i) = false

fun >>(a,0) = a
  | >>(a::r,i) = >>(r,i-1)
  | >>(nil,i) = nil

fun size x = length x

end

(*
 * $Log: bigint.sml,v $
 * Revision 1.2  1997/01/31  20:39:40  jhr
 * Replaced uses of "abstraction" with opaque signature matching.
 *
 * Revision 1.1.1.1  1997/01/14  01:38:12  george
 *   Version 109.24
 *
 *)

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0