PageRenderTime 38ms CodeModel.GetById 17ms app.highlight 14ms RepoModel.GetById 1ms app.codeStats 0ms

/interpreter/tags/at2dist030708/src/edu/vub/at/objects/ATNumeric.java

http://ambienttalk.googlecode.com/
Java | 388 lines | 35 code | 34 blank | 319 comment | 0 complexity | 850ce6320b60f8279081451e6a8e315b MD5 | raw file
  1/**
  2 * AmbientTalk/2 Project
  3 * ATNumeric.java created on 18-aug-2006 at 11:00:01
  4 * (c) Programming Technology Lab, 2006 - 2007
  5 * Authors: Tom Van Cutsem & Stijn Mostinckx
  6 * 
  7 * Permission is hereby granted, free of charge, to any person
  8 * obtaining a copy of this software and associated documentation
  9 * files (the "Software"), to deal in the Software without
 10 * restriction, including without limitation the rights to use,
 11 * copy, modify, merge, publish, distribute, sublicense, and/or
 12 * sell copies of the Software, and to permit persons to whom the
 13 * Software is furnished to do so, subject to the following
 14 * conditions:
 15 *
 16 * The above copyright notice and this permission notice shall be
 17 * included in all copies or substantial portions of the Software.
 18 *
 19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 20 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 21 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 22 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 23 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 24 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 25 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 26 * OTHER DEALINGS IN THE SOFTWARE.
 27 */
 28package edu.vub.at.objects;
 29
 30import edu.vub.at.exceptions.InterpreterException;
 31import edu.vub.at.objects.grammar.ATExpression;
 32
 33/**
 34 * ATNumeric is the public interface common to numbers and fractions.
 35 * 
 36 * This interface extends ATExpression as a number or fraction can also be output by the parser as a literal.
 37 * 
 38 * @author tvc
 39 */
 40public interface ATNumeric extends ATExpression {
 41
 42	// base-level interface to both numbers and fractions
 43
 44	/**
 45	 * Returns the trigonometric cosine of the numeric data type representing an angle in radians.
 46	 *  
 47	 * @return the cosine of the receiver.
 48	 */
 49	public ATFraction base_cos() throws InterpreterException;
 50	
 51	/**
 52	 * Returns the trigonometric sine of the numeric data type representing an angle in radians.
 53	 *  
 54	 * @return the sine of the receiver.
 55	 */
 56	public ATFraction base_sin() throws InterpreterException;
 57	
 58	/**
 59	 * Returns the trigonometric tangent of the numeric data type representing an angle in radians.
 60	 *  
 61	 * @return the tangent of the receiver.
 62	 */
 63	public ATFraction base_tan() throws InterpreterException;
 64	
 65	/**
 66	 * Returns the natural logarithm (base e) of the numeric data type.
 67	 *   
 68	 * @return the natural logarithm of the receiver or NaN if the receiver is smaller than 0.0.
 69	 */
 70	public ATFraction base_log() throws InterpreterException;
 71	
 72	/**
 73	 * Returns the positive square root of the numeric data type.
 74	 * 
 75	 * @return the correctly rounded positive square root of a or NaN if the receiver is smaller than zero. 
 76	 */
 77	public ATFraction base_sqrt() throws InterpreterException;
 78	
 79	/**
 80	 * Returns the closest number to the fraction.
 81	 * <p>
 82	 * More specifically, rounding a number is equivalent to <code> (fraction + 0.5).floor() </code>
 83	 *
 84	 * @return an ATNumber resulting of rounding the receiver to the closest number value.
 85	 */	
 86	public ATNumber base_round() throws InterpreterException;
 87	
 88	/**
 89	 * Returns the closest number to positive infinity that is smaller than the fraction.
 90	 *
 91	 * @return the closest number to positive infinity that is smaller than the fraction.
 92	 */	
 93	public ATNumber base_floor() throws InterpreterException;
 94	
 95	/**
 96	 * Returns the closest number to negative infinity that is greater than the fraction.
 97	 *
 98	 * @return the closest number to negative infinity that is greater than the fraction.
 99	 */	
100	public ATNumber base_ceiling() throws InterpreterException;
101	
102	/**
103	 * Returns the numeric data type raised to the power of the argument.
104	 * 
105	 * @param pow a ATNumeric data type representing the exponent.
106	 * @return the receiver raised to the power of the argument.
107	 * @throws XTypeMismatch if the exponent is not an {@link ATNumeric} object.
108	 */
109	public ATFraction base_expt(ATNumeric pow) throws InterpreterException;	
110	
111	// addition +
112	/**
113	 * Addition infix operator. Returns the value resulting of the sum of the receiver and 
114	 * another numeric data type passed as argument.
115	 * <p>
116	 * More specifically, this operator actually calls:
117	 * <ul>
118	 * <li><code>other.addNumber(this) if the receiver is a {@link ATNumber}</code>
119	 * <li><code>other.addFraction(this) if the receiver is a {@link ATFraction}</code>
120	 * </ul>
121	 *  
122	 * @param other a numeric data type.
123	 * @return a ATNumeric resulting of the sum of the receiver and other. 
124	 */	
125	public ATNumeric base__oppls_(ATNumeric other) throws InterpreterException;
126	
127	/**
128	 * Returns the value resulting of the sum of the receiver and a number passed as argument.
129	 * <p>
130	 * More specifically, this method returns a {@link ATNumber} if both numeric data types to sum are {@link ATNumber} objects.
131	 * Otherwise, an {@link ATFraction} is returned. 
132	 * <p>
133	 * Note that this is a double-dispatch method used to determine the correct runtime type of both arguments of the addition operator.
134	 * 
135	 * @param other a number.
136	 * @return a ATNumeric resulting of the sum of the receiver and other. 
137	 * @throws XTypeMismatch if other is not an {@link ATNumber} object.
138	 */	
139	public ATNumeric base_addNumber(ATNumber other) throws InterpreterException;
140	
141	/**
142	 * Returns the value resulting of the sum of the receiver and a fraction passed as argument.
143	 * <p>
144	 * Note that this is a double-dispatch method used to determine the correct runtime type of both arguments of the addition operator.
145	 * 
146	 * @param other a fraction.
147	 * @return a {@link ATFraction} resulting of the sum of the receiver and other. 
148	 * @throws XTypeMismatch if other is not an {@link ATFraction} object.
149	 */	
150	public ATNumeric base_addFraction(ATFraction other) throws InterpreterException;
151	
152	// subtraction -
153	/**
154	 * Subtraction infix operator. Returns the value resulting of subtracting 
155	 * a numeric data type passed as argument from the receiver.
156	 * <p>
157	 * More specifically, this operator actually calls:
158	 * <ul>
159	 * <li><code>other.subtractNumber(this) if the receiver is a {@link ATNumber}</code>
160	 * <li><code>other.subtractFraction(this) if the receiver is a {@link ATFraction}</code>
161	 * </ul>
162	 * 
163	 * @param other a numeric data type.
164	 * @return a ATNumeric resulting of subtracting other from the receiver. 
165	 */	
166	public ATNumeric base__opmns_(ATNumeric other) throws InterpreterException;
167	
168	/** 
169	 * Returns the value resulting of subtracting the receiver from a number passed as argument.
170	 * <p>
171	 * More specifically, this method returns a {@link ATNumber} if both numeric data types to subtract are {@link ATNumber} objects.
172	 * Otherwise, an {@link ATFraction} is returned. 
173	 * <p>
174	 * Note that this is a double-dispatch method used to determine the correct runtime type of both arguments of the subtraction operator.
175	 * 
176	 * @param other a number.
177	 * @return a ATNumeric resulting of subtracting other from the receiver.
178	 * @throws XTypeMismatch if other is not an {@link ATNumber} object.
179	 */	
180	public ATNumeric base_subtractNumber(ATNumber other) throws InterpreterException;
181	
182	/**
183	 * Returns the value resulting of the subtracting the receiver from a fraction passed as argument.
184	 * <p>
185	 * Note that this is a double-dispatch method used to determine the correct runtime type of both arguments of the subtraction operator.
186	 *  
187	 * @param other a fraction.
188	 * @return a {@link ATFraction} resulting of subtracting other from the receiver. 
189	 * @throws XTypeMismatch if other is not an {@link ATFraction} object.
190	 */	
191	public ATNumeric base_subtractFraction(ATFraction other) throws InterpreterException;
192	
193	// multiplication *
194	/**
195	 * Multiplication infix operator. Returns the value resulting of multiplying the receiver by 
196	 * another numeric data type passed as argument.
197	 * <p>
198	 * More specifically, this operator actually calls:
199	 * <ul>
200	 * <li><code>other.timesNumber(this) if the receiver is a {@link ATNumber}</code>
201	 * <li><code>other.timesFraction(this) if the receiver is a {@link ATFraction}</code>
202	 * </ul>
203	 * 
204	 * @param other a numeric data type.
205	 * @return a ATNumeric resulting of multiplying the receiver by other. 
206	 */	
207	public ATNumeric base__optms_(ATNumeric other) throws InterpreterException;
208	
209	/**
210	 * Returns the value resulting of multiplying the receiver by a number passed as argument.
211	 * <p>
212	 * More specifically, this method returns a {@link ATNumber} if both numeric data types to multiply are {@link ATNumber} objects.
213	 * Otherwise, an {@link ATFraction} is returned. 
214	 * <p>
215     * Note that this is a double-dispatch method used to determine the correct runtime type of both arguments of the multiplication operator.
216     * 
217	 * @param other a number.
218	 * @return a ATNumeric resulting of multiplying the receiver by other. 
219	 * @throws XTypeMismatch if other is not an {@link ATNumber} object.
220	 */	
221	public ATNumeric base_timesNumber(ATNumber other) throws InterpreterException;
222	
223	/**
224	 * Returns the value resulting of multiplying the receiver by a fraction passed as argument.
225	 * <p>
226	 * Note that this is a double-dispatch method used to determine the correct runtime type of both arguments of the multiplication operator.
227	 *  
228	 * @param other a fraction.
229	 * @return a {@link ATFraction} resulting of multiplying the receiver by other. 
230	 * @throws XTypeMismatch if other is not an {@link ATFraction} object.
231	 */	
232	public ATNumeric base_timesFraction(ATFraction other) throws InterpreterException;
233	
234	// division /
235	/**
236	 * Division infix operator ("/"). Returns the value resulting of dividing the receiver by 
237	 * another numeric data type passed as argument.
238	 * <p>
239	 * More specifically, this operator actually calls:
240	 * <ul>
241	 * <li><code>other.divideNumber(this) if the receiver is a {@link ATNumber}</code>
242	 * <li><code>other.divideFraction(this) if the receiver is a {@link ATFraction}</code>
243	 * </ul>
244	 * 
245	 * @param other a numeric data type.
246	 * @return a ATNumeric resulting of dividing the receiver by other. 
247	 */	
248	public ATNumeric base__opdiv_(ATNumeric other) throws InterpreterException;
249	
250	/**
251	 * Returns the value resulting of dividing a number passed as argument by the receiver.
252	 * <p>
253	 * More specifically, this method returns a {@link ATNumber} if both numeric data types to multiply are {@link ATNumber} objects.
254	 * Otherwise, an {@link ATFraction} is returned. 
255	 * <p>
256	 * Note that this is a double-dispatch method used to determine the correct runtime type of both arguments of the division operator.
257	 * 
258	 * @param other a number.
259	 * @return a ATNumeric resulting of dividing a given number by the receiver. 
260	 * @throws XTypeMismatch if other is not an {@link ATNumber} object.
261	 * @throws XIllegalArgument if the receiver is 0.
262	 */	
263	public ATNumeric base_divideNumber(ATNumber other) throws InterpreterException;
264	
265	/**
266	 * Returns the value resulting of dividing a number passed as argument by the receiver.
267	 * <p>
268	 * Note that this is a double-dispatch method used to determine the correct runtime type of both arguments of the division operator.
269	 * 
270	 * @param other a fraction.
271	 * @return a {@link ATFraction} resulting of dividing a given number by the receiver. 
272	 * @throws XTypeMismatch if other is not an {@link ATFraction} object.
273	 * @throws XIllegalArgument if the receiver is 0.
274	 */
275	public ATNumeric base_divideFraction(ATFraction other) throws InterpreterException;
276	
277	// comparison: generalized equality <=>
278	/**
279	 * Generalized equality infix operator. Returns:
280	 * <ul>
281	 * <li>-1 if the receiver is smaller than the numeric data type passed as argument.
282	 * <li>1 if the receiver is greater than the numeric data type passed as argument.
283	 * <li>0 if the receiver is equal to the numeric data type passed as argument.
284	 * </ul>
285	 * <p>
286	 * This method actually calls:
287	 * <ul>
288	 * <li><code>other.gequalsNumber(this) if the receiver is a {@link ATNumber}</code>
289	 * <li><code>other.gequalsFraction(this) if the receiver is a {@link ATFraction}</code>
290	 * </ul>
291	 * 
292	 * @param other a numeric data type.
293	 * @return a ATNumber resulting of evaluating the generalized equality between the receiver and other. 
294	 */	
295	public ATNumeric base__opltx__opeql__opgtx_(ATNumeric other) throws InterpreterException;
296	
297	/**
298	 * Returns the value of evaluating the generalized equality between the numeric data type and a number.
299	 * <p>
300	 * The generalized equality returns:
301	 * <ul>
302	 * <li>-1 if the receiver is greater than the number passed as argument.
303	 * <li>1 if the receiver is smaller than the number passed as argument.
304	 * <li>0 if the receiver is equal to the number passed as argument.
305	 * </ul>
306	 * <p>
307	 * Note that this is a double-dispatch method used to determine the correct runtime type of both arguments of the generalized equality operator.
308	 *
309	 * @param other a number.
310	 * @return a {@link ATNumber} resulting of applying the generalized equality between the receiver and other. 
311	 * @throws XTypeMismatch if other is not an {@link ATNumber} object.
312	 */	
313	public ATNumeric base_gequalsNumber(ATNumber other) throws InterpreterException;
314	
315	/**
316	 * Returns the value of evaluating the generalized equality between the numeric data type and a fraction.
317	 * <p>
318	 * The generalized equality returns:
319	 * <ul>
320	 * <li>-1 if the receiver is greater than the fraction passed as argument.
321	 * <li>1 if the receiver is smaller than the fraction passed as argument.
322	 * <li>0 if the receiver is equal to the fraction passed as argument.
323	 * </ul>
324	 * <p>
325	 * Note that this is a double-dispatch method used to determine the correct runtime type of both arguments of the generalized equality operator.
326	 * 
327	 * @param other a number.
328	 * @return a {@link ATNumber} resulting of applying the generalized equality between the receiver and other. 
329	 * @throws XTypeMismatch if other is not an {@link ATFraction} object.
330	 */	
331	public ATNumeric base_gequalsFraction(ATFraction other) throws InterpreterException;
332	
333	// Comparable mixin based on <=>
334	/**
335	 * Returns true if the receiver is smaller than the numeric data type passed as argument.
336	 *
337	 * @param other a numeric data type.
338	 * @return a {@link ATBoolean} resulting of evaluating <code> (receiver <=> other) == -1</code> 
339	 * @throws XTypeMismatch if other is not an {@link ATNumeric} object.
340	 */	
341	public ATBoolean base__opltx_(ATNumeric other) throws InterpreterException; // <
342	
343	/**
344	 * Returns true if the receiver is greater than the numeric data type passed as argument.
345	 *
346	 * @param other a numeric data type.
347	 * @return a {@link ATBoolean} resulting of evaluating <code> (receiver <=> other) == 1</code> 
348	 * @throws XTypeMismatch if other is not an {@link ATNumeric} object.
349	 */	
350	public ATBoolean base__opgtx_(ATNumeric other) throws InterpreterException; // >
351	
352	/**
353	 * Returns true if the receiver is smaller than or equal to the numeric data type passed as argument.
354	 *
355	 * @param other a numeric data type.
356	 * @return a {@link ATBoolean} resulting of evaluating <code> (receiver <=> other) != 1</code> 
357	 * @throws XTypeMismatch if other is not an {@link ATNumeric} object.
358	 */	
359	public ATBoolean base__opltx__opeql_(ATNumeric other) throws InterpreterException; // <=
360	
361	/**
362	 * Returns true if the receiver is greater than or equal to the numeric data type passed as argument.
363	 *
364	 * @param other a numeric data type.
365	 * @return a {@link ATBoolean} resulting of evaluating <code> (receiver <=> other) != -1</code> 
366	 * @throws XTypeMismatch if other is not an {@link ATNumeric} object.
367	 */	
368	public ATBoolean base__opgtx__opeql_(ATNumeric other) throws InterpreterException; // >=
369	
370	/**
371	 * Returns true if the receiver is equal to the numeric data type passed as argument.
372	 *
373	 * @param other a numeric data type.
374	 * @return a {@link ATBoolean} resulting of evaluating <code> (receiver <=> other) == 0</code> 
375	 * @throws XTypeMismatch if other is not an {@link ATNumeric} object.
376	 */	
377	public ATBoolean base__opeql_(ATNumeric other) throws InterpreterException; // =
378	
379	/**
380	 * Returns true if the receiver is different than the numeric data type passed as argument.
381	 *
382	 * @param other a numeric data type.
383	 * @return a {@link ATBoolean} resulting of evaluating <code> (receiver <=> other) != 0</code> 
384	 * @throws XTypeMismatch if other is not an {@link ATNumeric} object.
385	 */	
386	public ATBoolean base__opnot__opeql_(ATNumeric other) throws InterpreterException; // !=
387
388}