src/HOL/Matrix/ExactFloatingPoint.ML
author paulson
Fri, 04 Mar 2005 10:58:04 +0100
changeset 15572 9c89b1adf573
parent 15178 5f621aa35c25
permissions -rw-r--r--
removed dead code
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15178
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
     1
structure ExactFloatingPoint :
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
     2
sig
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
     3
    exception Destruct_floatstr of string
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
     4
				   
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
     5
    val destruct_floatstr : (char -> bool) -> (char -> bool) -> string -> bool * string * string * bool * string
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
     6
									  
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
     7
    exception Floating_point of string
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
     8
				
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
     9
    type floatrep = IntInf.int * IntInf.int
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    10
    val approx_dec_by_bin : IntInf.int -> floatrep -> floatrep * floatrep
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    11
    val approx_decstr_by_bin : int -> string -> floatrep * floatrep
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    12
end 
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    13
=
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    14
struct
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    15
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    16
fun fst (a,b) = a
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    17
fun snd (a,b) = b
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    18
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    19
val filter = List.filter;
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    20
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    21
exception Destruct_floatstr of string;
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    22
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    23
fun destruct_floatstr isDigit isExp number = 
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    24
    let
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    25
	val numlist = filter (not o Char.isSpace) (String.explode number)
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    26
	
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    27
	fun countsigns ((#"+")::cs) = countsigns cs
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    28
	  | countsigns ((#"-")::cs) = 
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    29
	    let	
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    30
		val (positive, rest) = countsigns cs 
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    31
	    in
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    32
		(not positive, rest)
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    33
	    end
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    34
	  | countsigns cs = (true, cs)
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    35
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    36
	fun readdigits [] = ([], [])
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    37
	  | readdigits (q as c::cs) = 
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    38
	    if (isDigit c) then 
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    39
		let
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    40
		    val (digits, rest) = readdigits cs
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    41
		in
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    42
		    (c::digits, rest)
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    43
		end
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    44
	    else
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    45
		([], q)		
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    46
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    47
	fun readfromexp_helper cs =
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    48
	    let
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    49
		val (positive, rest) = countsigns cs
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    50
		val (digits, rest') = readdigits rest
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    51
	    in
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    52
		case rest' of
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    53
		    [] => (positive, digits)
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    54
		  | _ => raise (Destruct_floatstr number)
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    55
	    end	    
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    56
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    57
	fun readfromexp [] = (true, [])
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    58
	  | readfromexp (c::cs) = 
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    59
	    if isExp c then
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    60
		readfromexp_helper cs
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    61
	    else 
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    62
		raise (Destruct_floatstr number)		
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    63
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    64
	fun readfromdot [] = ([], readfromexp [])
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    65
	  | readfromdot ((#".")::cs) = 
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    66
	    let		
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    67
		val (digits, rest) = readdigits cs
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    68
		val exp = readfromexp rest
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    69
	    in
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    70
		(digits, exp)
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    71
	    end		
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    72
	  | readfromdot cs = readfromdot ((#".")::cs)
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    73
			    
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    74
	val (positive, numlist) = countsigns numlist				 
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    75
	val (digits1, numlist) = readdigits numlist				 
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    76
 	val (digits2, exp) = readfromdot numlist
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    77
    in
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    78
	(positive, String.implode digits1, String.implode digits2, fst exp, String.implode (snd exp))
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    79
    end
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    80
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    81
type floatrep = IntInf.int * IntInf.int
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    82
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    83
exception Floating_point of string;
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    84
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    85
val ln2_10 = (Math.ln 10.0)/(Math.ln 2.0)
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    86
	
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    87
fun intmul a b = IntInf.* (a,b)
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    88
fun intsub a b = IntInf.- (a,b)	
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    89
fun intadd a b = IntInf.+ (a,b) 		 
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    90
fun intpow a b = IntInf.pow (a, IntInf.toInt b);
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    91
fun intle a b = IntInf.<= (a, b);
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    92
fun intless a b = IntInf.< (a, b);
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    93
fun intneg a = IntInf.~ a;
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    94
val zero = IntInf.fromInt 0;
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    95
val one = IntInf.fromInt 1;
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    96
val two = IntInf.fromInt 2;
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    97
val ten = IntInf.fromInt 10;
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    98
val five = IntInf.fromInt 5;
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
    99
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   100
fun find_most_significant q r = 
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   101
    let 
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   102
	fun int2real i = 
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   103
	    case Real.fromString (IntInf.toString i) of 
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   104
		SOME r => r 
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   105
	      | NONE => raise (Floating_point "int2real")	
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   106
	fun subtract (q, r) (q', r') = 
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   107
	    if intle r r' then
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   108
		(intsub q (intmul q' (intpow ten (intsub r' r))), r)
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   109
	    else
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   110
		(intsub (intmul q (intpow ten (intsub r r'))) q', r')
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   111
	fun bin2dec d =
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   112
	    if intle zero d then 
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   113
		(intpow two d, zero)
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   114
	    else
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   115
		(intpow five (intneg d), d)				
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   116
		
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   117
	val L = IntInf.fromInt (Real.floor (int2real (IntInf.fromInt (IntInf.log2 q)) + (int2real r) * ln2_10))	
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   118
	val L1 = intadd L one
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   119
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   120
	val (q1, r1) = subtract (q, r) (bin2dec L1) 		
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   121
    in
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   122
	if intle zero q1 then 
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   123
	    let
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   124
		val (q2, r2) = subtract (q, r) (bin2dec (intadd L1 one))
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   125
	    in
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   126
		if intle zero q2 then 
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   127
		    raise (Floating_point "find_most_significant")
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   128
		else
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   129
		    (L1, (q1, r1))
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   130
	    end
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   131
	else
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   132
	    let
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   133
		val (q0, r0) = subtract (q, r) (bin2dec L)
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   134
	    in
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   135
		if intle zero q0 then
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   136
		    (L, (q0, r0))
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   137
		else
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   138
		    raise (Floating_point "find_most_significant")
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   139
	    end		    
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   140
    end
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   141
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   142
fun approx_dec_by_bin n (q,r) =
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   143
    let	
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   144
	fun addseq acc d' [] = acc
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   145
	  | addseq acc d' (d::ds) = addseq (intadd acc (intpow two (intsub d d'))) d' ds
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   146
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   147
	fun seq2bin [] = (zero, zero)
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   148
	  | seq2bin (d::ds) = (intadd (addseq zero d ds) one, d)
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   149
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   150
	fun approx d_seq d0 precision (q,r) = 
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   151
	    if q = zero then 
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   152
		let val x = seq2bin d_seq in
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   153
		    (x, x)
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   154
		end
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   155
	    else    
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   156
		let 
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   157
		    val (d, (q', r')) = find_most_significant q r
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   158
		in	
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   159
		    if intless precision (intsub d0 d) then 
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   160
			let 
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   161
			    val d' = intsub d0 precision
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   162
			    val x1 = seq2bin (d_seq)
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   163
			    val x2 = (intadd (intmul (fst x1) (intpow two (intsub (snd x1) d'))) one,  d') (* = seq2bin (d'::d_seq) *) 
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   164
			in
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   165
			    (x1, x2)
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   166
			end
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   167
		    else
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   168
			approx (d::d_seq) d0 precision (q', r') 						    		
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   169
		end		
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   170
	
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   171
	fun approx_start precision (q, r) =
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   172
	    if q = zero then 
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   173
		((zero, zero), (zero, zero))
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   174
	    else
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   175
		let 
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   176
		    val (d, (q', r')) = find_most_significant q r
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   177
		in	
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   178
		    if intle precision zero then 
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   179
			let
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   180
			    val x1 = seq2bin [d]
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   181
			in
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   182
			    if q' = zero then 
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   183
				(x1, x1)
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   184
			    else
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   185
				(x1, seq2bin [intadd d one])
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   186
			end
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   187
		    else
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   188
			approx [d] d precision (q', r')
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   189
		end		
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   190
    in
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   191
	if intle zero q then 
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   192
	    approx_start n (q,r)
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   193
	else
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   194
	    let 
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   195
		val ((a1,b1), (a2, b2)) = approx_start n (intneg q, r) 
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   196
	    in
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   197
		((intneg a2, b2), (intneg a1, b1))
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   198
	    end					
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   199
    end
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   200
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   201
fun approx_decstr_by_bin n decstr =
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   202
    let 
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   203
	fun str2int s = case IntInf.fromString s of SOME x => x | NONE => zero 
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   204
	fun signint p x = if p then x else intneg x
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   205
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   206
	val (p, d1, d2, ep, e) = destruct_floatstr Char.isDigit (fn e => e = #"e" orelse e = #"E") decstr
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   207
	val s = IntInf.fromInt (size d2)
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   208
		
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   209
	val q = signint p (intadd (intmul (str2int d1) (intpow ten s)) (str2int d2))
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   210
	val r = intsub (signint ep (str2int e)) s
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   211
    in
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   212
	approx_dec_by_bin (IntInf.fromInt n) (q,r)
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   213
    end
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   214
5f621aa35c25 Matrix theory, linear programming
obua
parents:
diff changeset
   215
end;