wasCSharpSQLite – Blame information for rev 4

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 /*
2 * TclDouble.java --
3 *
4 * Implements the TclDouble internal object representation, as well
5 * variable traces for the tcl_precision variable.
6 *
7 * Copyright (c) 1997 Sun Microsystems, Inc.
8 *
9 * See the file "license.terms" for information on usage and
10 * redistribution of this file, and for a DISCLAIMER OF ALL
11 * WARRANTIES.
12 *
13 * Included in SQLite3 port to C# for use in testharness only; 2008 Noah B Hart
14 *
15 * RCS @(#) $Id: TclDouble.java,v 1.2 2000/10/29 06:00:42 mdejong Exp $
16 *
17 */
18 using System;
19 namespace tcl.lang
20 {
21  
22 /*
23 * This class implements the double object type in Tcl.
24 */
25  
26 public class TclDouble : InternalRep
27 {
28  
29 /*
30 * Internal representation of a double value.
31 */
32  
33 private double value;
34  
35 private TclDouble( double i )
36 {
37 value = i;
38 }
39 private TclDouble( Interp interp, string str )
40 {
41 value = Util.getDouble( interp, str );
42 }
43 public InternalRep duplicate()
44 {
45 return new TclDouble( value );
46 }
47 public void dispose()
48 {
49 }
50 public static TclObject newInstance( double d )
51 // Initial value.
52 {
53 return new TclObject( new TclDouble( d ) );
54 }
55 private static void setDoubleFromAny( Interp interp, TclObject tobj )
56 {
57 InternalRep rep = tobj.InternalRep;
58  
59 if ( rep is TclDouble )
60 {
61 /*
62 * Do nothing.
63 */
64 }
65 else if ( rep is TclBoolean )
66 {
67 /*
68 * Short-cut.
69 */
70  
71 bool b = TclBoolean.get( interp, tobj );
72 if ( b )
73 {
74 tobj.InternalRep = new TclDouble( 1.0 );
75 }
76 else
77 {
78 tobj.InternalRep = new TclDouble( 0.0 );
79 }
80 }
81 else if ( rep is TclInteger )
82 {
83 /*
84 * Short-cut.
85 */
86  
87 int i = TclInteger.get( interp, tobj );
88 tobj.InternalRep = new TclDouble( i );
89 }
90 else
91 {
92 tobj.InternalRep = new TclDouble( interp, tobj.ToString() );
93 }
94 }
95 public static double get( Interp interp, TclObject tobj )
96 {
97 InternalRep rep = tobj.InternalRep;
98 TclDouble tdouble;
99  
100 if ( !( rep is TclDouble ) )
101 {
102 setDoubleFromAny( interp, tobj );
103 tdouble = (TclDouble)( tobj.InternalRep );
104 }
105 else
106 {
107 tdouble = (TclDouble)rep;
108 }
109  
110 return tdouble.value;
111 }
112 public static void set( TclObject tobj, double d )
113 // The new value for the object.
114 {
115 tobj.invalidateStringRep();
116 InternalRep rep = tobj.InternalRep;
117  
118 if ( rep is TclDouble )
119 {
120 TclDouble tdouble = (TclDouble)rep;
121 tdouble.value = d;
122 }
123 else
124 {
125 tobj.InternalRep = new TclDouble( d );
126 }
127 }
128 public override string ToString()
129 {
130 return Util.printDouble( value );
131 }
132 } // end TclDouble
133 }