26
26
EXTENDED data type routines
27
27
****************************************************************************}
29
{$define FPC_SYSTEM_HAS_PI}
30
function pi : double;[internproc:in_pi];
32
{$define FPC_SYSTEM_HAS_ABS}
33
function abs(d : extended) : extended;[internproc:in_abs_extended];
35
{$define FPC_SYSTEM_HAS_SQR}
36
function sqr(d : extended) : extended;[internproc:in_sqr_extended];
39
function arctan(d : extended) : extended;[internconst:in_arctan_extended];
44
function ln(d : extended) : extended;[internconst:in_ln_extended];
49
function sin(d : extended) : extended;[internconst: in_sin_extended];
54
function cos(d : extended) : extended;[internconst:in_cos_extended];
59
function exp(d : extended) : extended;[internconst:in_const_exp];
29
{$ifdef INTERNCONSTINTF}
30
{$define FPC_SYSTEM_HAS_PI}
31
function fpc_pi_real : valreal;compilerproc;
33
{ Function is handled internal in the compiler }
38
{$define FPC_SYSTEM_HAS_ABS}
39
function fpc_abs_real(d : valreal) : valreal;compilerproc;
41
{ Function is handled internal in the compiler }
46
{$define FPC_SYSTEM_HAS_SQR}
47
function fpc_sqr_real(d : valreal) : valreal;compilerproc;
49
{ Function is handled internal in the compiler }
55
{$define FPC_SYSTEM_HAS_PI}
56
function pi : double;[internproc:fpc_in_pi];
58
{$define FPC_SYSTEM_HAS_ABS}
59
function abs(d : extended) : extended;[internproc:fpc_in_abs_real];
61
{$define FPC_SYSTEM_HAS_SQR}
62
function sqr(d : extended) : extended;[internproc:fpc_in_sqr_real];
63
{$endif ndef INTERNCONSTINTF}
67
66
factor: double = double(int64(1) shl 32);
68
67
factor2: double = double(int64(1) shl 31);
69
{$ifndef FPC_SYSTEM_HAS_TRUNC}
70
70
{$define FPC_SYSTEM_HAS_TRUNC}
71
function trunc(d : extended) : int64;assembler;[internconst:in_const_trunc];
71
{$ifdef INTERNCONSTINTF}
72
function fpc_trunc_real(d : valreal) : int64;assembler;compilerproc;
74
function trunc(d : extended) : int64;assembler;[internconst:fpc_in_const_trunc];
72
76
{ input: d in fr1 }
73
77
{ output: result in r3 }
161
{$endif not FPC_SYSTEM_HAS_TRUNC}
165
{$ifndef FPC_SYSTEM_HAS_ROUND}
159
166
{$define FPC_SYSTEM_HAS_ROUND}
160
167
{$ifdef hascompilerproc}
161
function round(d : extended) : int64;[internconst:in_const_round, external name 'FPC_ROUND'];
168
function round(d : extended) : int64;{$ifndef INTERNCONSTINTF}[internconst:fpc_in_const_round, external name 'FPC_ROUND'];{$endif}
163
170
function fpc_round(d : extended) : int64;assembler;[public, alias:'FPC_ROUND'];{$ifdef hascompilerproc}compilerproc;{$endif hascompilerproc}
165
function round(d : extended) : int64;assembler;[internconst:in_const_round];
172
function round(d : extended) : int64;assembler;{$ifndef INTERNCONSTINTF}[internconst:fpc_in_const_round];{$endif}
166
173
{$endif hascompilerproc}
167
174
{ exactly the same as trunc, except that one fctiwz has become fctiw }
168
175
{ input: d in fr1 }
255
{$define FPC_SYSTEM_HAS_POWER}
256
function power(bas,expo : extended) : extended;
268
{ bas < 0 is not allowed }
272
power:=exp(ln(bas)*expo);
276
{****************************************************************************
277
Longint data type routines
278
****************************************************************************}
280
{$define FPC_SYSTEM_HAS_POWER_INT64}
281
function power(bas,expo : int64) : int64;
297
power:=-round(exp(ln(-bas)*expo))
299
power:=round(exp(ln(-bas)*expo));
302
power:=round(exp(ln(bas)*expo));
306
{****************************************************************************
307
Helper routines to support old TP styled reals
308
****************************************************************************}
310
{ warning: the following converts a little-endian TP-style real }
311
{ to a big-endian double. So don't byte-swap the TP real! }
312
{$define FPC_SYSTEM_HAS_REAL2DOUBLE}
313
function real2double(r : real48) : double;
316
res : array[0..7] of byte;
323
res[4]:=(r[1] shr 3) or (r[2] shl 5);
324
res[3]:=(r[2] shr 3) or (r[3] shl 5);
325
res[2]:=(r[3] shr 3) or (r[4] shl 5);
326
res[1]:=(r[4] shr 3) or (r[5] and $7f) shl 5;
327
res[0]:=(r[5] and $7f) shr 3;
330
{ correct exponent: }
331
exponent:=(word(r[0])+(1023-129));
332
res[1]:=res[1] or ((exponent and $f) shl 4);
333
res[0]:=exponent shr 4;
336
res[0]:=res[0] or (r[5] and $80);
337
real2double:=double(res);
260
{$endif not FPC_SYSTEM_HAS_ROUND}
341
264
{****************************************************************************
428
351
$Log: math.inc,v $
429
Revision 1.33 2004/02/09 20:21:06 olle
430
* fixed global variable access in asm
432
Revision 1.32 2003/12/07 19:55:37 jonas
433
- reverted previous patch, solved with the new assembler reader
434
(which didn't understand the new syntax)
436
Revision 1.30 2003/11/15 19:01:27 florian
437
* fixed rtl to work with the integrated fpc ppc assembler reader
439
Revision 1.29 2003/09/04 16:07:31 florian
440
* fixed qword_to_double conversion on powerpc
442
Revision 1.28 2003/09/03 14:09:37 florian
443
* arm fixes to the common rtl code
444
* some generic math code fixed
447
Revision 1.27 2003/08/08 22:02:05 olle
450
Revision 1.26 2003/06/14 12:41:08 jonas
451
* fixed compilation problems (removed unnecessary modified registers
452
lists from procedures)
454
Revision 1.25 2003/05/31 20:22:06 jonas
455
* fixed 64 bit results of trunc and round
457
Revision 1.24 2003/05/30 23:56:41 florian
458
* fixed parameter passing for int64
460
Revision 1.23 2003/05/24 13:39:32 jonas
461
* fsqrt is an optional instruction in the ppc architecture and isn't
462
implemented by any current ppc afaik, so use the generic sqrt routine
463
instead (adapted so it works with compilerproc)
465
Revision 1.22 2003/05/16 16:04:33 jonas
466
* fixed round() (almost the same as trunc)
468
Revision 1.21 2003/05/11 18:09:45 jonas
469
* fixed qword and int64 to double conversion
471
Revision 1.20 2003/05/02 15:12:19 jonas
472
- removed empty ppc-specific frac()
473
+ added correct generic frac() implementation for doubles (translated
476
Revision 1.19 2003/04/26 20:36:24 jonas
477
* trunc now also supports int64 (no NaN's etc though)
479
Revision 1.18 2003/04/26 17:20:16 florian
480
* fixed trunc, now it's working at least for longint range
482
Revision 1.17 2003/04/23 21:28:21 peter
483
* fpc_round added, needed for int64 currency
485
Revision 1.16 2003/01/16 11:29:11 olle
486
* changed access of globals to be indirect via TOC
488
Revision 1.15 2003/01/15 01:09:04 florian
489
* changed power(...) prototype to int64
491
Revision 1.14 2002/11/28 11:04:16 olle
492
* macos: refs to globals in asm adapted to macos
494
Revision 1.13 2002/10/21 18:08:28 jonas
495
* round has int64 instead of longint result
497
Revision 1.12 2002/09/08 13:00:21 jonas
498
* made pi an internproc instead of internconst
500
Revision 1.11 2002/09/07 16:01:26 peter
501
* old logs removed and tabs fixed
503
Revision 1.10 2002/08/18 22:11:10 florian
504
* fixed remaining assembler errors
506
Revision 1.9 2002/08/18 21:37:48 florian
507
* several errors in inline assembler fixed
509
Revision 1.8 2002/08/10 17:14:36 jonas
510
* various fixes, mostly changing the names of the modifies registers to
511
upper case since that seems to be required by the compiler
513
Revision 1.7 2002/07/31 16:58:12 jonas
514
* fixed conversion from int64/qword to double errors
516
Revision 1.6 2002/07/29 21:28:17 florian
517
* several fixes to get further with linux/ppc system unit compilation
519
Revision 1.5 2002/07/28 21:39:29 florian
520
* made abs a compiler proc if it is generic
522
Revision 1.4 2002/07/28 20:43:49 florian
523
* several fixes for linux/powerpc
524
* several fixes to MT
352
Revision 1.39 2005/02/14 17:13:31 peter