3 This file is part of the Free Pascal run time library.
4 Copyright (c) 1999-2000 by the Free Pascal development team
6 Implementation of mathamatical Routines (only for real)
8 See the file COPYING.FPC, included in this distribution,
9 for details about the copyright.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15 **********************************************************************}
18 {****************************************************************************
19 EXTENDED data type routines
20 ****************************************************************************}
22 {$ifdef hasinternmath}
23 function pi : extended;[internproc:in_pi];
24 function abs(d : extended) : extended;[internproc:in_abs_extended];
25 function sqr(d : extended) : extended;[internproc:in_sqr_extended];
26 function sqrt(d : extended) : extended;[internproc:in_sqrt_extended];
27 function arctan(d : extended) : extended;[internproc:in_arctan_extended];
28 function ln(d : extended) : extended;[internproc:in_ln_extended];
29 function sin(d : extended) : extended;[internproc:in_sin_extended];
30 function cos(d : extended) : extended;[internproc:in_cos_extended];
32 function pi : extended;assembler;[internconst:in_const_pi];
38 function abs(d : extended) : extended;assembler;[internconst:in_const_abs];
45 function sqr(d : extended) : extended;assembler;[internconst:in_const_sqr];
53 function sqrt(d : extended) : extended;assembler;[internconst:in_const_sqrt];
60 function arctan(d : extended) : extended;assembler;[internconst:in_const_arctan];
67 function cos(d : extended) : extended;assembler;[internconst:in_const_cos];
86 function ln(d : extended) : extended;assembler;[internconst:in_const_ln];
94 function sin(d : extended) : extended;assembler;[internconst:in_const_sin];
114 {$endif hasinternmath}
116 function exp(d : extended) : extended;assembler;[internconst:in_const_exp];
138 // store some help data in the data segment
149 function frac(d : extended) : extended;assembler;[internconst:in_const_frac];
169 function int(d : extended) : extended;assembler;[internconst:in_const_int];
186 function trunc(d : extended) : longint;assembler;[internconst:in_const_trunc];
203 function round(d : extended) : longint;assembler;[internconst:in_const_round];
208 movw $0x1372,-8(%ebp)
218 function power(bas,expo : extended) : extended;
230 { bas < 0 is not allowed }
234 power:=exp(ln(bas)*expo);
238 {****************************************************************************
239 Longint data type routines
240 ****************************************************************************}
242 function power(bas,expo : longint) : longint;
258 power:=-round(exp(ln(-bas)*expo))
260 power:=round(exp(ln(-bas)*expo));
263 power:=round(exp(ln(bas)*expo));
268 {****************************************************************************
269 Fixed data type routines
270 ****************************************************************************}
272 {$ifdef HASFIXED} { Not yet allowed }
274 function sqrt(d : fixed) : fixed;
303 function int(d : fixed) : fixed;
304 {*****************************************************************}
305 { Returns the integral part of d }
306 {*****************************************************************}
308 int:=d and $ffff0000; { keep only upper bits }
312 function trunc(d : fixed) : longint;
313 {*****************************************************************}
314 { Returns the Truncated integral part of d }
315 {*****************************************************************}
317 trunc:=longint(integer(d shr 16)); { keep only upper 16 bits }
320 function frac(d : fixed) : fixed;
321 {*****************************************************************}
322 { Returns the Fractional part of d }
323 {*****************************************************************}
325 frac:=d AND $ffff; { keep only decimal parts - lower 16 bits }
328 function abs(d : fixed) : fixed;
329 {*****************************************************************}
330 { Returns the Absolute value of d }
331 {*****************************************************************}
335 rol $16,%eax { Swap high & low word.}
336 {Absolute value: Invert all bits and increment when <0 .}
337 cwd { When ax<0, dx contains $ffff}
338 xorw %dx,%ax { Inverts all bits when dx=$ffff.}
339 subw %dx,%ax { Increments when dx=$ffff.}
340 rol $16,%eax { Swap high & low word.}
347 function sqr(d : fixed) : fixed;
348 {*****************************************************************}
349 { Returns the Absolute squared value of d }
350 {*****************************************************************}
352 {16-bit precision needed, not 32 =)}
354 { sqr := (d SHR 8 * d) SHR 8; }
358 function Round(x: fixed): longint;
359 {*****************************************************************}
360 { Returns the Rounded value of d as a longint }
361 {*****************************************************************}
366 lowf:=x and $ffff; { keep decimal part ... }
367 highf :=integer(x shr 16);
373 { here we must check the sign ... }
374 { if greater or equal to zero, then }
375 { greater value will be found by adding }
380 Round:= longint(highf);
387 Revision 1.1 2002/02/19 08:25:18 sasu
390 Revision 1.1 2000/07/13 06:30:42 michael
393 Revision 1.23 2000/05/02 10:37:50 pierre
394 * 0**n where n<>0 is 0; 0**0 generates RTE 207
396 Revision 1.22 2000/04/07 21:29:00 pierre
397 changed to get nasm to compile system
399 Revision 1.21 2000/02/15 14:37:36 florian
400 * disabled FIXED data type per default
402 Revision 1.20 2000/02/09 16:59:29 peter
405 Revision 1.19 2000/01/07 16:41:33 daniel
408 Revision 1.18 2000/01/07 16:32:24 daniel
409 * copyright 2000 added
411 Revision 1.17 1999/10/06 17:44:43 peter
412 * fixed power(int,int) with negative base
413 * power(ext,ext) with negative base gives rte 207
415 Revision 1.16 1999/09/15 20:24:11 florian
416 * some math functions are now coded inline by the compiler