-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathAuxMath.pas
18839 lines (14670 loc) · 597 KB
/
AuxMath.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{-------------------------------------------------------------------------------
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
-------------------------------------------------------------------------------}
{===============================================================================
AuxMath
This library provides small set of auxiliary mathematical functions
implemented explicitly for more types than what is common (in RTL).
It was, at first, developed only to provide combined DivCeil, DivFloor and
Min and Max for mixed types, but more functionality was added during later
development.
Given nature of this library, there are many overloads for each function
that differ only by argument type. Unfortunately, some type overloads
cannot be properly processed (recognized) by older compilers. As a
workaround, almost all functions are provided in two forms/names.
First form is with one- or two-letter prefix in name that marks which
type group the function accepts. These functions are always implemented
for all supported types - the prefixes are here to better distinguish
types, so that the compiler does not have problem recognizing them and
selecting proper overload. Following prefixes are currently used:
i - signed integers
u - unsigned integers
f - floating point (real) numbers
c - characters
s - strings
p - pointers
o - objects/classes
v - variants
g - TGUID
b - general untyped buffer
Second form is without prefix - the function has normal expected name
(eg. Max, DivMod, ...). Given the abovementioned problems, these do not
provide overloads for all supported types in all compilers. For details
about which types and what functions are affected, refer to "Overloading
information symbols" further down.
Version 1.2.1 (2024-04-14)
Last change (2024-04-14)
©2024 František Milt
Contacts:
František Milt: [email protected]
Support:
If you find this code useful, please consider supporting its author(s) by
making a small donation using the following link(s):
https://www.paypal.me/FMilt
Changelog:
For detailed changelog and history please refer to this git repository:
github.com/TheLazyTomcat/Lib.AuxMath
Dependencies:
* AuxExceptions - github.com/TheLazyTomcat/Lib.AuxExceptions
AuxTypes - github.com/TheLazyTomcat/Lib.AuxTypes
Library AuxExceptions is required only when rebasing local exception classes
(see symbol AuxMath_UseAuxExceptions for details).
Indirect dependencies:
SimpleCPUID - github.com/TheLazyTomcat/Lib.SimpleCPUID
StrRect - github.com/TheLazyTomcat/Lib.StrRect
UInt64Utils - github.com/TheLazyTomcat/Lib.UInt64Utils
WinFileInfo - github.com/TheLazyTomcat/Lib.WinFileInfo
===============================================================================}
unit AuxMath;
{
AuxMath_PurePascal
If you want to compile this unit without ASM, don't want to or cannot define
PurePascal for the entire project and at the same time you don't want to or
cannot make changes to this unit, define this symbol for the entire project
and only this unit will be compiled in PurePascal mode.
}
{$IFDEF AuxMath_PurePascal}
{$DEFINE PurePascal}
{$ENDIF}
{
AuxMath_UseAuxExceptions
If you want library-specific exceptions to be based on more advanced classes
provided by AuxExceptions library instead of basic Exception class, and don't
want to or cannot change code in this unit, you can define global symbol
AuxMath_UseAuxExceptions to achieve this.
}
{$IF Defined(AuxMath_UseAuxExceptions)}
{$DEFINE UseAuxExceptions}
{$IFEND}
//------------------------------------------------------------------------------
{$IFDEF ENDIAN_BIG}
{$MESSAGE FATAL 'Big-endian system not supported'} // because of memory overlays
{$ENDIF}
{$IF Defined(CPU64) or Defined(CPU64BITS)}
{$DEFINE CPU64bit}
{$ELSEIF Defined(CPU16)}
{$MESSAGE FATAL '16bit CPU not supported'}
{$ELSE}
{$DEFINE CPU32bit}
{$IFEND}
{$IF Defined(CPUX86_64) or Defined(CPUX64)}
{$DEFINE x64}
{$ELSEIF Defined(CPU386)}
{$DEFINE x86}
{$ELSE}
{$DEFINE PurePascal}
{$IFEND}
{$IF Defined(WINDOWS) or Defined(MSWINDOWS)}
{$DEFINE Windows}
{$IFEND}
{$IFDEF FPC}
{$MODE ObjFPC}
{$INLINE ON}
{$DEFINE CanInline}
{$IFNDEF PurePascal}
{$ASMMODE Intel}
{$ENDIF}
{$ELSE}
{$IF (CompilerVersion >= 17)} // Delphi 2005+
{$DEFINE CanInline}
{$ELSE}
{$UNDEF CanInline}
{$IFEND}
{$ENDIF}
{$H+}
{$J-} // typed constants are not writeable
//------------------------------------------------------------------------------
// do not touch following defines!
{$UNDEF AM_OverflowChecks}
{$UNDEF AM_DistinctUCS4Str}
{$UNDEF AM_DistinctUTF8Str}
{$IFOPT Q+}
{$DEFINE AM_OverflowChecks}
{$ENDIF}
{$IFDEF FPC}
{$DEFINE AM_DistinctUCS4Str}
{$DEFINE AM_DistinctUTF8Str}
{$ELSE}
{$IF (CompilerVersion > 15)} // newer than Delphi 7
{$DEFINE AM_DistinctUCS4Str}
{$IF (CompilerVersion >= 17)} // Delphi 2005+
{$DEFINE AM_DistinctUTF8Str}
{$IFEND}
{$IFEND}
{$ENDIF}
interface
uses
SysUtils,
AuxTypes{$IFDEF UseAuxExceptions}, AuxExceptions{$ENDIF};
{===============================================================================
Overloading information symbols
===============================================================================}
{
This unit provides many overloaded variants for the same function, where
these differ only by arguments type. But in older compilers, some of these
types are either declared only as an alias for exiting type, or the compiler
might not be able to distinguish between some types when overloading based
only on input parameters (ie. no "var" or "out" modifier).
In such cases, it is not possible to provide all overloads, or those
overloads can be implemented but cannot be called (it will generate
"ambiguous overloaded call" compilation error) - therefore, these overloads
are not provided (they are removed from the compilation) in affected
compilers.
Following constants are here to provide a way of knowing whether such
overloads are present or not. Since these are true constants, they can be
used in conditional compilation, so there is no need for runtime binding -
all can be done statically at compilation.
There are always three constants for each problematic type. First is a
boolean (when true, overloads are present), second is numerical (N suffix,
integer, overloads are there when non-zero) and last (suffixed E) is only
declared when the overloads are provided (it can be used in Declared()
conditional).
For more details, refer to description of individual constants.
}
//------------------------------------------------------------------------------
{
Following constants are informing whether overloads accepting type UInt64
are available.
In old compilers, type UInt64 is not (fully) supported, therefore it is
declared only as an alias for type Int64 (to be more precise, Int64 is
retyped to UInt64). This means, among others, that overloads for types Int64
and UInt64 are basically the same and cannot be distinguished in calls
(although they can be compiled).
Unfortunatelly, this also means that, when UInt64 overloads are not present
but Int64 are, compiler will call Int64 overload when UInt64 values/variables
are passed, giving no warning about that. This can lead to hard-to-find bugs,
where you are getting wrong results because unsigned integers are treated as
signed.
So, given the abovementioned, it has been decided to remove not only UInt64,
but also Int64 overloads in problematic environments. But note that there are
always some prefixed variants that can be used with Int64 and UInt64 (named
so they do no clash).
Following functions are affected:
DivCeil
DivFloor
IsPow2
IntLog2
DivCeilPow2
DivFloorPow2
DivCeilPow2NoCheck
DivCeilPow2NC
DivFloorPow2NoCheck
DivFloorPow2NC
Min (any variant accepting Int64 or UInt64)
Max (any variant accepting Int64 or UInt64)
MinValue
MaxValue
CompareValue (any variant accepting Int64 or UInt64)
CompareValueOp (any variant accepting Int64 or UInt64)
IfThen
InRange
EnsureRange
}
const
DistinctOverloadUInt64 = {$IF Declared(NativeUInt64E)}True{$ELSE}False{$IFEND};
DistinctOverloadUInt64N = {$IF Declared(NativeUInt64E)}1{$ELSE}0{$IFEND};
{$IF Declared(NativeUInt64E)}
DistinctOverloadUInt64E = True;
{$IFEND}
//------------------------------------------------------------------------------
{
In modern compilers, the type UnicodeString is a distinct embedded (base)
type, but for old compilers, it is declared only as an alias for WideString.
There, distinct overloads for this type cannot be provided since they would
be completely the same as overloads for WideString.
That being said, you do not need to worry about whether this is so or not,
proper overload will be called in any way, it is here only to provide the
information.
Affected functions:
sIfThen
IfThen
NOTE - there is a non-overloaded function called IfThenUnicodeString, if
you want to be completely sure what is called.
}
const
DistinctOverloadUnicodeString = {$IF Declared(UnicodeIsWideE)}False{$ELSE}True{$IFEND};
DistinctOverloadUnicodeStringN = {$IF Declared(UnicodeIsWideE)}1{$ELSE}1{$IFEND};
{$IF not Declared(UnicodeIsWideE)}
DistinctOverloadUnicodeStringE = True;
{$IFEND}
//------------------------------------------------------------------------------
{
For some bizzare reason, old Delphi (namely D7) cannot distinguish between
untyped pointers and dynamic array types when overloading. Here, this affects
type UCS4String, because it is declared as a dynamic array of UCS4Char.
As a result, the overloads accepting this string type are removed in Delphi 7
and older (I have decided to remove these instead of overloads for pointers,
as those are used more often). Following constants can be used to discern
whether overloads for UCS4String are present or not during compilation.
Affected functions:
IfThen
NOTE - you can always use function IfThenUCS4String if you do not want to
deal with these details.
}
const
DistinctOverloadUCS4String = {$IFDEF AM_DistinctUCS4Str}True{$ELSE}False{$ENDIF};
DistinctOverloadUCS4StringN = {$IFDEF AM_DistinctUCS4Str}1{$ELSE}0{$ENDIF};
{$IFDEF AM_DistinctUCS4Str}
DistinctOverloadUCS4StringE = True;
{$ENDIF}
//------------------------------------------------------------------------------
{
In old Delphi, the type UTF8String is not distinguishable from AnsiString,
therefore in those compilers (older than D2005) the UTF8String overloads are
removed and AnsiString overloads are called instead (since these compilers do
not support code pages, and there is no conversion done, it should be ok).
Note that you do not need to change your code based on this particular
detail. If you call any function with UTF8String it will just be directed
to AnsiString overload (which, as mentioned above, should be ok).
Affected functions:
sIfThen
IfThen
NOTE - use function IfThenUTF8String if you want to be sure.
}
const
DistinctOverloadUTF8String = {$IFDEF AM_DistinctUTF8Str}True{$ELSE}False{$ENDIF};
DistinctOverloadUTF8StringN = {$IFDEF AM_DistinctUTF8Str}1{$ELSE}0{$ENDIF};
{$IFDEF AM_DistinctUTF8Str}
DistinctOverloadUTF8StringE = True;
{$ENDIF}
{===============================================================================
Library-specific exceptions
===============================================================================}
type
EAMException = class({$IFDEF UseAuxExceptions}EAEGeneralException{$ELSE}Exception{$ENDIF});
EAMInvalidOperation = class(EAMException);
EAMInvalidValue = class(EAMException);
EAMRangeError = class(EAMException);
EAMOverflowError = class(EAMException);
{===============================================================================
Public constants
===============================================================================}
{
Lowest and highest possible values of selected integer types. They can all be
obtained using stndard functions Low() and High(), but if anyone wants them
as constants, there they are...
}
const
MinInt8 = Int8($80); // -128
MaxInt8 = Int8($7F); // 127
MinShortInt = MinInt8;
MaxShortInt = MaxInt8;
MinShort = MinInt8;
MaxShort = MaxInt8;
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
MinUInt8 = UInt8(0);
MaxUInt8 = UInt8($FF); // 255
MinByte = MinUInt8;
MaxByte = MaxUInt8;
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
MinInt16 = Int16($8000); // -32768
MaxInt16 = Int16($7FFF); // 32767
MinSmallInt = MinInt16;
MaxSmallInt = MaxInt16;
MinSmall = MinInt16;
MaxSmall = MaxInt16;
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
MinUInt16 = UInt16(0);
MaxUInt16 = UInt16($FFFF); // 65535
MinWord = MinUInt16;
MaxWord = MaxUInt16;
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
MinInt32 = Int32($80000000); // -2147483648
MaxInt32 = Int32($7FFFFFFF); // 2147483647
{$IF SizeOf(LongInt) = 4}
MinLongInt = MinInt32;
MaxLongInt = MaxInt32;
MinLong = MinInt32;
MaxLong = MaxInt32;
{$IFEND}
{$IF SizeOf(Integer) = 4}
MinInteger = MinInt32;
MaxInteger = MaxInt32;
MinInt = MinInt32;
MaxInt = MaxInt32;
{$IFEND}
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
MinUInt32 = UInt32(0);
MaxUInt32 = UInt32($FFFFFFFF); // 4294967295
MinDWord = MinUInt32;
MaxDWord = MaxUInt32;
{$IF SizeOf(LongWord) = 4}
MinLongWord = MinUInt32;
MaxLongWord = MaxUInt32;
{$IFEND}
{$IF SizeOf(Cardinal) = 4}
MinCardinal = MinUInt32;
MaxCardinal = MaxUInt32;
{$IFEND}
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
MinInt64 = Int64($8000000000000000); // -9223372036854775808
MaxInt64 = Int64($7FFFFFFFFFFFFFFF); // 9223372036854775807
MinQuadInt = MinInt64;
MaxQuadInt = MaxInt64;
{$IF SizeOf(LongInt) = 8}
MinLongInt = MinInt64;
MaxLongInt = MaxInt64;
MinLong = MinInt64;
MaxLong = MaxInt64;
{$IFEND}
{$IF SizeOf(Integer) = 8}
MinInteger = MinInt64;
MaxInteger = MaxInt64;
MinInt = MinInt64;
MaxInt = MaxInt64;
{$IFEND}
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
MinUInt64 = UInt64(0);
MaxUInt64 = UInt64($FFFFFFFFFFFFFFFF); // 18446744073709551615
MinQuadWord = MinUInt64;
MaxQuadWord = MaxUInt64;
MinQWord = MinUInt64;
MaxQWord = MaxUInt64;
{$IF SizeOf(LongWord) = 8}
MinLongWord = MinUInt64;
MaxLongWord = MaxUInt64;
{$IFEND}
{$IF SizeOf(Cardinal) = 8}
MinCardinal = MinUInt64;
MaxCardinal = MaxUInt64;
{$IFEND}
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
MinPtrInt = {$IF SizeOf(PtrInt) = 8}MinInt64{$ELSE}MinInt32{$IFEND};
MaxPtrInt = {$IF SizeOf(PtrInt) = 8}MaxInt64{$ELSE}MaxInt32{$IFEND};
MinPtrUInt = {$IF SizeOf(PtrUInt) = 8}MinUInt64{$ELSE}MinUInt32{$IFEND};
MaxPtrUInt = {$IF SizeOf(PtrUInt) = 8}MaxUInt64{$ELSE}MaxUInt32{$IFEND};
//==============================================================================
{
Special values for half-precision (16bit) floating point number types.
Since those types are not supported by compiler and mostly not even by
hardware, they are declared only as structured types of the right size.
This means, among others, that they cannot be directly used in arithmetics
or comparisons, and their assignments are not automatically checked for
invalid encodings and SNaN.
}
const
Float16Min: Float16 = ($01,$00); // 5.96046e-8
Float16Max: Float16 = ($FF,$7B); // 65504
Float16MinNormal: Float16 = ($00,$04); // 6.10351562500000e-5 (lowest possible normalized value)
Float16MaxDenormal: Float16 = ($FF,$03); // 6.09755516052246e-5 (highest possible denormalized value)
Float16QNaN: Float16 = ($FF,$7F); // quiet NaN
Float16SNaN: Float16 = ($FF,$7D); // signaled NaN
Float16NaN: Float16 = ($FF,$7F); // quiet NaN
Float16Infinity: Float16 = ($00,$7C); // positive infinity
Float16Zero: Float16 = ($00,$00); // (+)0
Float16One: Float16 = ($00,$3C); // +1.0
Float16Indefinite: Float16 = ($00,$FE); // indefinite quiet NaN
MinFloat16: Float16 = ($01,$00); // Float16Min
MaxFloat16: Float16 = ($FF,$7B); // Float16Max
HalfMin: Half = ($01,$00); // 5.96046e-8
HalfMax: Half = ($FF,$7B); // 65504
HalfMinNormal: Half = ($00,$04); // 6.10351562500000e-5
HalfMaxDenormal: Half = ($FF,$03); // 6.09755516052246e-5
HalfQNaN: Half = ($FF,$7F); // quiet NaN
HalfSNaN: Half = ($FF,$7D); // signaled NaN
HalfNaN: Half = ($FF,$7F); // quiet NaN
HalfInfinity: Half = ($00,$7C); // positive infinity
HalfZero: Half = ($00,$00); // (+)0
HalfOne: Half = ($00,$3C); // +1.0
HalfIndefinite: Half = ($00,$FE); // indefinite quiet NaN
MinHalf: Half = ($01,$00); // HalfMin
MaxHalf: Half = ($FF,$7B); // HalfMax
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
{
Special values for single-precision (32bit) floating point number types.
Note on the implementation...
It is implemented the way it is (ie. as a disgusting hack misusing the fact
that typed constants are stored in memory) because I know of no other way
how to put arbitrary bit pattern into float constant (or, in this case,
static variable). The only other way I am aware of is declaring the symbols
as functions and returning proper values, but call overhead is no-go for me
here (yeah inlining and such, but still, it does not always work and so on).
So, to be completely clear, the special values are declared as global
variables overlayed on typed constants. The compilers are smart enough
to recognize it and (when writeable constants option is off, which here it
explicitly is) treat the variables in code as constants (ie. they cannot be
assigned to).
}
const
iFloat32Min: UInt32 = $00000001; // 1.40129846432482e-45
iFloat32Max: UInt32 = $7F7FFFFF; // 3.40282346638529e+38
iFloat32MinNormal: UInt32 = $00800000; // 1.17549435082229e-38
iFloat32MaxDenormal: UInt32 = $007FFFFF; // 1.17549421069244e-38
iFloat32QNaN: UInt32 = $7FFFFFFF; // quiet NaN
iFloat32SNaN: UInt32 = $7FBFFFFF; // signaled NaN
iFloat32NaN: UInt32 = $7FFFFFFF; // quiet NaN
iFloat32Infinity: UInt32 = $7F800000; // positive infinity
iFloat32Indefinite: UInt32 = $FFC00000; // indefinite quiet NaN
var
Float32Min: Float32 absolute iFloat32Min;
Float32Max: Float32 absolute iFloat32Max;
Float32MinNormal: Float32 absolute iFloat32MinNormal;
Float32MaxDenormal: Float32 absolute iFloat32MaxDenormal;
Float32QNaN: Float32 absolute iFloat32QNaN;
Float32SNaN: Float32 absolute iFloat32SNaN;
Float32NaN: Float32 absolute iFloat32NaN;
Float32Infinity: Float32 absolute iFloat32Infinity;
Float32Indefinite: Float32 absolute iFloat32Indefinite;
SingleMin: Single absolute iFloat32Min;
SingleMax: Single absolute iFloat32Max;
SingleMinNormal: Single absolute iFloat32MinNormal;
SingleMaxDenormal: Single absolute iFloat32MaxDenormal;
SingleQNaN: Single absolute iFloat32QNaN;
SingleSNaN: Single absolute iFloat32SNaN;
SingleNaN: Single absolute iFloat32NaN;
SingleInfinity: Single absolute iFloat32Infinity;
SingleIndefinite: Single absolute iFloat32Indefinite;
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
{
Special values for double-precision (64bit) floating point number types.
}
const
iFloat64Min: UInt64 = UInt64($0000000000000001); // 4.94065645841247e-324
iFloat64Max: UInt64 = UInt64($7FEFFFFFFFFFFFFF); // 1.79769313486232e+308
iFloat64MinNormal: UInt64 = UInt64($0010000000000000); // 2.2250738585072014e-308
iFloat64MaxDenormal: UInt64 = UInt64($000FFFFFFFFFFFFF); // 2.2250738585072009e-308
iFloat64QNaN: UInt64 = UInt64($7FFFFFFFFFFFFFFF); // quiet NaN
iFloat64SNaN: UInt64 = UInt64($7FF7FFFFFFFFFFFF); // signaled NaN
iFloat64NaN: UInt64 = UInt64($7FFFFFFFFFFFFFFF); // quiet NaN
iFloat64Infinity: UInt64 = UInt64($7FF0000000000000); // positive infinity
iFloat64Indefinite: UInt64 = UInt64($FFF8000000000000); // indefinite quiet NaN
var
Float64Min: Float64 absolute iFloat64Min;
Float64Max: Float64 absolute iFloat64Max;
Float64MinNormal: Float64 absolute iFloat64MinNormal;
Float64MaxDenormal: Float64 absolute iFloat64MaxDenormal;
Float64QNaN: Float64 absolute iFloat64QNaN;
Float64SNaN: Float64 absolute iFloat64SNaN;
Float64NaN: Float64 absolute iFloat64NaN;
Float64Infinity: Float64 absolute iFloat64Infinity;
Float64Indefinite: Float64 absolute iFloat64Indefinite;
DoubleMin: Double absolute iFloat64Min;
DoubleMax: Double absolute iFloat64Max;
DoubleMinNormal: Double absolute iFloat64MinNormal;
DoubleMaxDenormal: Double absolute iFloat64MaxDenormal;
DoubleQNaN: Double absolute iFloat64QNaN;
DoubleSNaN: Double absolute iFloat64SNaN;
DoubleNaN: Double absolute iFloat64NaN;
DoubleInfinity: Double absolute iFloat64Infinity;
DoubleIndefinite: Double absolute iFloat64Indefinite;
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
{
Special values for double-extended-precision (80bit) floating point number
types.
}
type
TAMFloat80Overlay = packed record
Mantissa: UInt64;
SignExponent: UInt16;
end;
const
iFloat80Min: TAMFloat80Overlay = (Mantissa: UInt64($0000000000000001); SignExponent: $0000); // 3.64519953188247460253e-4951
iFloat80Max: TAMFloat80Overlay = (Mantissa: UInt64($FFFFFFFFFFFFFFFF); SignExponent: $7FFE); // 1.18973149535723176502e+4932
iFloat80MinNormal: TAMFloat80Overlay = (Mantissa: UInt64($8000000000000000); SignExponent: $0001); // 3.36210314311209350626e-4932
iFloat80MaxDenormal: TAMFloat80Overlay = (Mantissa: UInt64($7FFFFFFFFFFFFFFF); SignExponent: $0000); // 3.36210314311209350590E-4932
iFloat80QNaN: TAMFloat80Overlay = (Mantissa: UInt64($FFFFFFFFFFFFFFFF); SignExponent: $7FFF); // quiet NaN
iFloat80SNaN: TAMFloat80Overlay = (Mantissa: UInt64($BFFFFFFFFFFFFFFF); SignExponent: $7FFF); // signaled NaN
iFloat80NaN: TAMFloat80Overlay = (Mantissa: UInt64($FFFFFFFFFFFFFFFF); SignExponent: $7FFF); // quiet NaN
iFloat80Infinity: TAMFloat80Overlay = (Mantissa: UInt64($8000000000000000); SignExponent: $7FFF); // positive infinity
iFloat80Indefinite: TAMFloat80Overlay = (Mantissa: UInt64($C000000000000000); SignExponent: $FFFF); // indefinite quiet NaN
{
Some super-special values for 80bit floats.
They are not supported by modern hardware and usually produce an exception
when used (except for pseudo-denormals, they are silently converted to
correct denormals or normalized values where possible).
pseudo-denormals ... denormals with integer bit (bit 63) in mantissa set to 1
unnormals ... seemingly normalized numbers, but with zero integer bit
pseudo-NaN ... values encoded as proper NaN, zero integer bit
pseudo-Infinity ... encoded as proper infinity, zero integer bit
}
iFloat80MinPseudoDenormal: TAMFloat80Overlay = (Mantissa: UInt64($8000000000000000); SignExponent: $0000); // 3.36210314311209350626e-4932 (lowest possible pseudo-denormal)
iFloat80MaxPseudoDenormal: TAMFloat80Overlay = (Mantissa: UInt64($FFFFFFFFFFFFFFFF); SignExponent: $0000); // 6.72420628622418701216e-4932 (highest possible pseudo-denormal)
iFloat80MinUnnormal: TAMFloat80Overlay = (Mantissa: UInt64($0000000000000000); SignExponent: $0001); // lowest possible unnormal
iFloat80MaxUnnormal: TAMFloat80Overlay = (Mantissa: UInt64($7FFFFFFFFFFFFFFF); SignExponent: $7FFE); // highest possible unnormal
iFloat80PseudoQNaN: TAMFloat80Overlay = (Mantissa: UInt64($7FFFFFFFFFFFFFFF); SignExponent: $7FFF); // quiet pseudo-NaN
iFloat80PseudoSNaN: TAMFloat80Overlay = (Mantissa: UInt64($3FFFFFFFFFFFFFFF); SignExponent: $7FFF); // signaled pseudo-NaN
iFloat80PseudoNaN: TAMFloat80Overlay = (Mantissa: UInt64($7FFFFFFFFFFFFFFF); SignExponent: $7FFF); // quiet pseudo-NaN
iFloat80PseudoInfinity: TAMFloat80Overlay = (Mantissa: UInt64($0000000000000000); SignExponent: $7FFF); // pseudo-infinity
var
Float80Min: Float80 absolute iFloat80Min;
Float80Max: Float80 absolute iFloat80Max;
Float80MinNormal: Float80 absolute iFloat80MinNormal;
Float80MaxDenormal: Float80 absolute iFloat80MaxDenormal;
Float80QNaN: Float80 absolute iFloat80QNaN;
Float80SNaN: Float80 absolute iFloat80SNaN;
Float80NaN: Float80 absolute iFloat80NaN;
Float80Infinity: Float80 absolute iFloat80Infinity;
Float80Indefinite: Float80 absolute iFloat80Indefinite;
Float80MinPseudoDenormal: Float80 absolute iFloat80MinPseudoDenormal;
Float80MaxPseudoDenormal: Float80 absolute iFloat80MaxPseudoDenormal;
Float80MinUnnormal: Float80 absolute iFloat80MinUnnormal;
Float80MaxUnnormal: Float80 absolute iFloat80MaxUnnormal;
Float80PseudoQNaN: Float80 absolute iFloat80PseudoQNaN;
Float80PseudoSNaN: Float80 absolute iFloat80PseudoSNaN;
Float80PseudoNaN: Float80 absolute iFloat80PseudoNaN;
Float80PseudoInfinity: Float80 absolute iFloat80PseudoInfinity;
{$IF SizeOf(Extended) = 10}
ExtendedMin: Extended absolute iFloat80Min;
ExtendedMax: Extended absolute iFloat80Max;
ExtendedMinNormal: Extended absolute iFloat80MinNormal;
ExtendedMaxDenormal: Extended absolute iFloat80MaxDenormal;
ExtendedQNaN: Extended absolute iFloat80QNaN;
ExtendedSNaN: Extended absolute iFloat80SNaN;
ExtendedNaN: Extended absolute iFloat80NaN;
ExtendedInfinity: Extended absolute iFloat80Infinity;
ExtendedIndefinite: Extended absolute iFloat80Indefinite;
ExtendedMinPseudoDenormal: Extended absolute iFloat80MinPseudoDenormal;
ExtendedMaxPseudoDenormal: Extended absolute iFloat80MaxPseudoDenormal;
ExtendedMinUnnormal: Extended absolute iFloat80MinUnnormal;
ExtendedMaxUnnormal: Extended absolute iFloat80MaxUnnormal;
ExtendedPseudoQNaN: Extended absolute iFloat80PseudoQNaN;
ExtendedPseudoSNaN: Extended absolute iFloat80PseudoSNaN;
ExtendedPseudoNaN: Extended absolute iFloat80PseudoNaN;
ExtendedPseudoInfinity: Extended absolute iFloat80PseudoInfinity;
{$ELSE}
ExtendedMin: Extended absolute iFloat64Min;
ExtendedMax: Extended absolute iFloat64Max;
ExtendedMinNormal: Extended absolute iFloat64MinNormal;
ExtendedMaxDenormal: Extended absolute iFloat64MaxDenormal;
ExtendedQNaN: Extended absolute iFloat64QNaN;
ExtendedSNaN: Extended absolute iFloat64SNaN;
ExtendedNaN: Extended absolute iFloat64NaN;
ExtendedInfinity: Extended absolute iFloat64Infinity;
ExtendedIndefinite: Extended absolute iFloat64Indefinite;
{$IFEND}
{===============================================================================
Public auxiliary constants
===============================================================================}
const
{
Highest and lowest integral value that can be stored in 64bit floating point
number (Double) without losing any information (the numbers have the same
magnitude, so negated positive limit can be used as low value, but for the
sake of clarity, both are provided).
}
AM_INT_DBL_HI = 9007199254740992; // $0020000000000000
AM_INT_DBL_LO = -9007199254740992; // $FFE0000000000000
// "nicer" alias (to get lower limit, just negate it)
Flt64MaxInt = AM_INT_DBL_HI;
{
Highest and lowest integral values that can be stored in Extended floating
point type, whatever its declaration might be, without losing infromation.
}
AM_INT_EXT_HI = {$IF SizeOf(Extended) = 10}High(Int64){$ELSE}AM_INT_DBL_HI{$IFEND};
AM_INT_EXT_LO = {$IF SizeOf(Extended) = 10}Low(Int64){$ELSE}AM_INT_DBL_LO{$IFEND};
AM_UINT_EXT_HI = {$IF SizeOf(Extended) = 10}MaxUInt64{$ELSE}AM_INT_DBL_HI{$IFEND};
{===============================================================================
Public auxiliary funtions - declaration
===============================================================================}
{
Use following two functions to transfer signed 64bit integer value to and
from floating point number. All compilers supporting type Int64 can do it
implicitly (or using Trunc), this functions are here to do controlled
conversion.
In Int64ToFloat, if the type Extended is declared only as an alias for
Double (Win64), the limits for transfer (AM_INT_DBL_LO,AM_INT_DBL_HI) are
in effect. The number must be within those limits otherwise an exception of
class EAMInvalidOperation is raised.
For FloatToInt64, the floating point number must not have non-zero fraction,
must be greater or equal to -2^63 and at the same time smaller than 2^63.
Also, when type extended is aliased to double, the number must lie within
limits for loss-less conversion to integer (must be within interval
[AM_INT_DBL_LO,AM_INT_DBL_HI]). If any mentioned rule is not observed, then
an exception of class EAMInvalidOperation is raised.
}
Function Int64ToFloat(const N: Int64): Extended;
Function FloatToInt64(const N: Extended): Int64;
{
Following functions transfer unsigned 64bit integer value to and from
floating point number. Newer compilers can do it, but older ones (those
without full support for type UInt64) might not be capable of doing it.
Note that both functions are doing the same checks as corresponding functions
for signed 64bit integers (of course here tweaked for unsigned).
}
Function UInt64ToFloat(const N: UInt64): Extended;
Function FloatToUInt64(const N: Extended): UInt64;
{===============================================================================
--------------------------------------------------------------------------------
Combined division and modulo
--------------------------------------------------------------------------------
===============================================================================}
{
Performs integer division and modulo as one operation, so there is no need to
call them separately when both quotient and remainder are required.
}
procedure iDivMod(const Dividend,Divisor: Int8; out Quotient,Remainder: Int8); overload;{$IFNDEF PurePascal} register; assembler;{$ENDIF}
procedure iDivMod(const Dividend,Divisor: Int16; out Quotient,Remainder: Int16); overload;{$IFNDEF PurePascal} register; assembler;{$ENDIF}
procedure iDivMod(const Dividend,Divisor: Int32; out Quotient,Remainder: Int32); overload;{$IFNDEF PurePascal} register; assembler;{$ENDIF}
procedure iDivMod(const Dividend,Divisor: Int64; out Quotient,Remainder: Int64); overload;{$IFNDEF PurePascal} register; assembler;{$ENDIF}
//------------------------------------------------------------------------------
procedure uDivMod(const Dividend,Divisor: UInt8; out Quotient,Remainder: UInt8); overload;{$IFNDEF PurePascal} register; assembler;{$ENDIF}
procedure uDivMod(const Dividend,Divisor: UInt16; out Quotient,Remainder: UInt16); overload;{$IFNDEF PurePascal} register; assembler;{$ENDIF}
procedure uDivMod(const Dividend,Divisor: UInt32; out Quotient,Remainder: UInt32); overload;{$IFNDEF PurePascal} register; assembler;{$ENDIF}
procedure uDivMod(const Dividend,Divisor: UInt64; out Quotient,Remainder: UInt64); overload;{$IFNDEF PurePascal} register; assembler;{$ENDIF}
//------------------------------------------------------------------------------
procedure DivMod(const Dividend,Divisor: Int8; out Quotient,Remainder: Int8); overload;{$IFDEF CanInline} inline;{$ENDIF}
procedure DivMod(const Dividend,Divisor: Int16; out Quotient,Remainder: Int16); overload;{$IFDEF CanInline} inline;{$ENDIF}
procedure DivMod(const Dividend,Divisor: Int32; out Quotient,Remainder: Int32); overload;{$IFDEF CanInline} inline;{$ENDIF}
procedure DivMod(const Dividend,Divisor: Int64; out Quotient,Remainder: Int64); overload;{$IFDEF CanInline} inline;{$ENDIF}
procedure DivMod(const Dividend,Divisor: UInt8; out Quotient,Remainder: UInt8); overload;{$IFDEF CanInline} inline;{$ENDIF}
procedure DivMod(const Dividend,Divisor: UInt16; out Quotient,Remainder: UInt16); overload;{$IFDEF CanInline} inline;{$ENDIF}
procedure DivMod(const Dividend,Divisor: UInt32; out Quotient,Remainder: UInt32); overload;{$IFDEF CanInline} inline;{$ENDIF}
procedure DivMod(const Dividend,Divisor: UInt64; out Quotient,Remainder: UInt64); overload;{$IFDEF CanInline} inline;{$ENDIF}
{===============================================================================
--------------------------------------------------------------------------------
Combined division and ceiling
--------------------------------------------------------------------------------
===============================================================================}
{
Performs division and Ceil as one optimized operation (the calculation does
not use floating point unit/numbers, only integers, which ensures that no
information is lost due to precision problems in large float numbers).
}
Function iDivCeil(const Dividend,Divisor: Int8): Int8; overload;
Function iDivCeil(const Dividend,Divisor: Int16): Int16; overload;
Function iDivCeil(const Dividend,Divisor: Int32): Int32; overload;
Function iDivCeil(const Dividend,Divisor: Int64): Int64; overload;
//------------------------------------------------------------------------------
Function uDivCeil(const Dividend,Divisor: UInt8): UInt8; overload;
Function uDivCeil(const Dividend,Divisor: UInt16): UInt16; overload;
Function uDivCeil(const Dividend,Divisor: UInt32): UInt32; overload;
Function uDivCeil(const Dividend,Divisor: UInt64): UInt64; overload;
//------------------------------------------------------------------------------
Function DivCeil(const Dividend,Divisor: Int8): Int8; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function DivCeil(const Dividend,Divisor: Int16): Int16; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function DivCeil(const Dividend,Divisor: Int32): Int32; overload;{$IFDEF CanInline} inline;{$ENDIF}
{$IF Declared(DistinctOverloadUInt64E)}
Function DivCeil(const Dividend,Divisor: Int64): Int64; overload;{$IFDEF CanInline} inline;{$ENDIF}
{$IFEND}
Function DivCeil(const Dividend,Divisor: UInt8): UInt8; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function DivCeil(const Dividend,Divisor: UInt16): UInt16; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function DivCeil(const Dividend,Divisor: UInt32): UInt32; overload;{$IFDEF CanInline} inline;{$ENDIF}
{$IF Declared(DistinctOverloadUInt64E)}
Function DivCeil(const Dividend,Divisor: UInt64): UInt64; overload;{$IFDEF CanInline} inline;{$ENDIF}
{$IFEND}
{===============================================================================
--------------------------------------------------------------------------------
Combined division and floor
--------------------------------------------------------------------------------
===============================================================================}
{
Performs division and Floor as one optimized operation (the calculation does
not utilize floating point unit/numbers).
}
Function iDivFloor(const Dividend,Divisor: Int8): Int8; overload;
Function iDivFloor(const Dividend,Divisor: Int16): Int16; overload;
Function iDivFloor(const Dividend,Divisor: Int32): Int32; overload;
Function iDivFloor(const Dividend,Divisor: Int64): Int64; overload;
//------------------------------------------------------------------------------
Function uDivFloor(const Dividend,Divisor: UInt8): UInt8; overload;
Function uDivFloor(const Dividend,Divisor: UInt16): UInt16; overload;
Function uDivFloor(const Dividend,Divisor: UInt32): UInt32; overload;
Function uDivFloor(const Dividend,Divisor: UInt64): UInt64; overload;
//------------------------------------------------------------------------------
Function DivFloor(const Dividend,Divisor: Int8): Int8; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function DivFloor(const Dividend,Divisor: Int16): Int16; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function DivFloor(const Dividend,Divisor: Int32): Int32; overload;{$IFDEF CanInline} inline;{$ENDIF}
{$IF Declared(DistinctOverloadUInt64E)}
Function DivFloor(const Dividend,Divisor: Int64): Int64; overload;{$IFDEF CanInline} inline;{$ENDIF}
{$IFEND}
Function DivFloor(const Dividend,Divisor: UInt8): UInt8; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function DivFloor(const Dividend,Divisor: UInt16): UInt16; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function DivFloor(const Dividend,Divisor: UInt32): UInt32; overload;{$IFDEF CanInline} inline;{$ENDIF}
{$IF Declared(DistinctOverloadUInt64E)}
Function DivFloor(const Dividend,Divisor: UInt64): UInt64; overload;{$IFDEF CanInline} inline;{$ENDIF}
{$IFEND}
{===============================================================================
--------------------------------------------------------------------------------
64bit ceil and floor
--------------------------------------------------------------------------------
===============================================================================}
{
Standard Ceil and Floor functions are returning only Integers - that is,
32bit numbers. Following functions are here for situations where 64bit wide
integers are required.
Ceil64 and Floor64 are returning Int64, CeilU64 and FloorU64 are returning
UInt64.
Note that, if the N is beyond limits for UInt64, the CeilU64 and FloorU64
will raise an EAMInvalidOperation exception (in Ceil64 and Floor64, this is
manager by the compiler and the exception would be of class EInvalidOP).
}
Function Ceil64(const N: Extended): Int64;
Function Floor64(const N: Extended): Int64;
Function CeilU64(const N: Extended): UInt64;
Function FloorU64(const N: Extended): UInt64;
{===============================================================================
--------------------------------------------------------------------------------
Is positive integer power of 2
--------------------------------------------------------------------------------
===============================================================================}
{
Returns true when given number is a positive integer power of 2 (2^E, where E
is a positive integer), false otherwise.
Note that zero and negative numbers cannot be positive integer power of any
base, therefore in those cases false is returned.
}
Function iIsPow2(const N: Int8): Boolean; overload;
Function iIsPow2(const N: Int16): Boolean; overload;
Function iIsPow2(const N: Int32): Boolean; overload;
Function iIsPow2(const N: Int64): Boolean; overload;
//------------------------------------------------------------------------------
Function uIsPow2(const N: UInt8): Boolean; overload;
Function uIsPow2(const N: UInt16): Boolean; overload;
Function uIsPow2(const N: UInt32): Boolean; overload;
Function uIsPow2(const N: UInt64): Boolean; overload;
//------------------------------------------------------------------------------
Function IsPow2(const N: Int8): Boolean; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function IsPow2(const N: Int16): Boolean; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function IsPow2(const N: Int32): Boolean; overload;{$IFDEF CanInline} inline;{$ENDIF}
{$IF Declared(DistinctOverloadUInt64E)}
Function IsPow2(const N: Int64): Boolean; overload;{$IFDEF CanInline} inline;{$ENDIF}
{$IFEND}
Function IsPow2(const N: UInt8): Boolean; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function IsPow2(const N: UInt16): Boolean; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function IsPow2(const N: UInt32): Boolean; overload;{$IFDEF CanInline} inline;{$ENDIF}
{$IF Declared(DistinctOverloadUInt64E)}
Function IsPow2(const N: UInt64): Boolean; overload;{$IFDEF CanInline} inline;{$ENDIF}
{$IFEND}
{===============================================================================
--------------------------------------------------------------------------------
Integer logarithm base 2
--------------------------------------------------------------------------------
===============================================================================}
{
If the given number is a positive integer power of 2, then IntLog2 will
return the exponent (effectively Log2(N)).
If the number is zero, negative (for signed integers), or is generally not an
integer power of 2, then it will return -1.
}
Function iIntLog2(const N: Int8): Int32; overload;{$IFNDEF PurePascal} register; assembler;{$ENDIF}
Function iIntLog2(const N: Int16): Int32; overload;{$IFNDEF PurePascal} register; assembler;{$ENDIF}
Function iIntLog2(const N: Int32): Int32; overload;{$IFNDEF PurePascal} register; assembler;{$ENDIF}
Function iIntLog2(const N: Int64): Int32; overload;{$IFNDEF PurePascal} register; assembler;{$ENDIF}
//------------------------------------------------------------------------------
Function uIntLog2(const N: UInt8): Int32; overload;{$IFNDEF PurePascal} register; assembler;{$ENDIF}
Function uIntLog2(const N: UInt16): Int32; overload;{$IFNDEF PurePascal} register; assembler;{$ENDIF}
Function uIntLog2(const N: UInt32): Int32; overload;{$IFNDEF PurePascal} register; assembler;{$ENDIF}
Function uIntLog2(const N: UInt64): Int32; overload;{$IFNDEF PurePascal} register; assembler;{$ENDIF}
//------------------------------------------------------------------------------
Function IntLog2(const N: Int8): Int32; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function IntLog2(const N: Int16): Int32; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function IntLog2(const N: Int32): Int32; overload;{$IFDEF CanInline} inline;{$ENDIF}
{$IF Declared(DistinctOverloadUInt64E)}
Function IntLog2(const N: Int64): Int32; overload;{$IFDEF CanInline} inline;{$ENDIF}
{$IFEND}
Function IntLog2(const N: UInt8): Int32; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function IntLog2(const N: UInt16): Int32; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function IntLog2(const N: UInt32): Int32; overload;{$IFDEF CanInline} inline;{$ENDIF}
{$IF Declared(DistinctOverloadUInt64E)}
Function IntLog2(const N: UInt64): Int32; overload;{$IFDEF CanInline} inline;{$ENDIF}
{$IFEND}
{===============================================================================
--------------------------------------------------------------------------------
Try combined division and modulo by integer power of 2
--------------------------------------------------------------------------------
===============================================================================}
{
If divisor is a positive integer power of 2, it will perform optimized
integer division and modulo in one operation, and return true.
Otherwise it will return false and both output parameters (quotient and
remainder) are undefined.
}
Function iTryDivModPow2(const Dividend,Divisor: Int8; out Quotient,Remainder: Int8): Boolean; overload;{$IFNDEF PurePascal} register; assembler;{$ENDIF}
Function iTryDivModPow2(const Dividend,Divisor: Int16; out Quotient,Remainder: Int16): Boolean; overload;{$IFNDEF PurePascal} register; assembler;{$ENDIF}
Function iTryDivModPow2(const Dividend,Divisor: Int32; out Quotient,Remainder: Int32): Boolean; overload;{$IFNDEF PurePascal} register; assembler;{$ENDIF}
Function iTryDivModPow2(const Dividend,Divisor: Int64; out Quotient,Remainder: Int64): Boolean; overload;{$IFNDEF PurePascal} register; assembler;{$ENDIF}
//------------------------------------------------------------------------------
Function uTryDivModPow2(const Dividend,Divisor: UInt8; out Quotient,Remainder: UInt8): Boolean; overload;{$IFNDEF PurePascal} register; assembler;{$ENDIF}
Function uTryDivModPow2(const Dividend,Divisor: UInt16; out Quotient,Remainder: UInt16): Boolean; overload;{$IFNDEF PurePascal} register; assembler;{$ENDIF}
Function uTryDivModPow2(const Dividend,Divisor: UInt32; out Quotient,Remainder: UInt32): Boolean; overload;{$IFNDEF PurePascal} register; assembler;{$ENDIF}
Function uTryDivModPow2(const Dividend,Divisor: UInt64; out Quotient,Remainder: UInt64): Boolean; overload;{$IFNDEF PurePascal} register; assembler;{$ENDIF}
//------------------------------------------------------------------------------
Function TryDivModPow2(const Dividend,Divisor: Int8; out Quotient,Remainder: Int8): Boolean; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function TryDivModPow2(const Dividend,Divisor: Int16; out Quotient,Remainder: Int16): Boolean; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function TryDivModPow2(const Dividend,Divisor: Int32; out Quotient,Remainder: Int32): Boolean; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function TryDivModPow2(const Dividend,Divisor: Int64; out Quotient,Remainder: Int64): Boolean; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function TryDivModPow2(const Dividend,Divisor: UInt8; out Quotient,Remainder: UInt8): Boolean; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function TryDivModPow2(const Dividend,Divisor: UInt16; out Quotient,Remainder: UInt16): Boolean; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function TryDivModPow2(const Dividend,Divisor: UInt32; out Quotient,Remainder: UInt32): Boolean; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function TryDivModPow2(const Dividend,Divisor: UInt64; out Quotient,Remainder: UInt64): Boolean; overload;{$IFDEF CanInline} inline;{$ENDIF}