You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> **This operator overload is conditionally compiled for Delphi 10.4 and later only.**
18
+
19
+
_Initialize_ is called automatically whenever a new _TFraction_ record is created. It sets the values of the _[Numerator](./TFraction-Numerator.md)_ and _[Denominator](./TFraction-Denominator.md)_ properties to `0` and `1` respectively, to correctly represent a zero fraction.
20
+
21
+
⚠️ When compiled with Delphi version prior to 10.4 the initial values of _[Numerator](./TFraction-Numerator.md)_ and _[Denominator](./TFraction-Denominator.md)_ properties are undefined.
Copy file name to clipboardExpand all lines: Fractions/0/API/TFraction-Power.md
+19-8Lines changed: 19 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -6,23 +6,34 @@
6
6
7
7
**Record:**[_TFraction_](./TFraction.md)
8
8
9
-
**Applies to:**~>0.1
9
+
**Applies to:** 0.1.x
10
10
11
11
```pascal
12
12
class function Power(const F: TFraction; Exponent: ShortInt): TFraction; static;
13
13
```
14
+
**Applies to:**~>0.2
15
+
16
+
```pascal
17
+
class function Power(const F: TFraction; Exponent: ShortInt): TFraction;
18
+
overload; static;
19
+
function Power(const Exponent: ShortInt): TFraction; overload;
20
+
```
14
21
15
22
## Description
16
23
17
-
Returns the given fraction _F_ raised to the power of integer _Exponent_.
24
+
Return a fraction raised to an integer power specified by the _Exponent_ parameter. The resulting fraction is simplified.
25
+
26
+
_Exponent_ can be positive, zero or negative except unless the fraction is zero when _Exponent_ must be non-negative.
27
+
28
+
When _Exponent_ is negative the reciprocal of _F_ is raised to the power of the absolute value of _Exponent_. This is because, for any number `n`, `n^-x = 1/(N^x)`.
18
29
19
-
_Exponent_ can be positive, zero or negative. When _Exponent_ is negative the reciprocal of _F_ is raised to the power of the absolute value of _Exponent_. This is because, for any number `n`, `n^-x = 1/(N^x)`.
30
+
The class method takes the fraction to be operated on, _F_, as its first parameter.
20
31
21
-
If _F_ is zero, _Exponent_ must be non-negative.
32
+
[~>0.2] The instance method operates on the fraction instance upon which it is called.
22
33
23
-
The resulting fraction is simplified.
34
+
### Examples
24
35
25
-
###Examples
36
+
#### Class method examples
26
37
27
38
Here's a simple function that squares the given fraction.
28
39
@@ -33,7 +44,7 @@ begin
33
44
end;
34
45
```
35
46
36
-
And here is some code that write out all the integer powers of 1/2 from -32 to +32:
47
+
[~>0.2] Here is some code that write out all the integer powers of 1/2 from -32 to +32:
Copy file name to clipboardExpand all lines: Fractions/0/API/TFraction.md
+9-2Lines changed: 9 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -21,6 +21,9 @@ Furthermore a _TFraction_ variable can be instantiated by assigning a variable o
21
21
* Another _TFraction_. Properties are simply copied.
22
22
* Any integer type. This creates a fractions with numerator equal to the integer and denominator 1.
23
23
* A _Single_, _Double_ or _Extended_ floating point type. The floating point value is converted to a fraction to an accuracy of 5 decimal places. The floating point value must be 0 or have an absolute value in the range 1.0e-19 to 1.0e+19.
24
+
*[~>0.2]**When compiled with Delphi 10.4 or later only:** simply declaring a _TFraction_ variable will instantiate it as if `0` had been assigned to it.
25
+
26
+
⚠️ Never use a _TFraction_ variable that has not been instantiated since its value is undefined.
24
27
25
28
### Properties
26
29
@@ -56,6 +59,7 @@ The operators are overloaded by the record
56
59
|[_Modulus_](./TFraction-Modulus.md)| Enables the modulus operator (`mod`) to be used to get the fractional remainder after dividing one _TFraction_ record by another. |
57
60
|[_Round_](./TFraction-Round.md)| Enables the `Round` operator to round a _TFraction_ record to the nearest whole number value. |
58
61
|[_Trunc_](./TFraction-Trunc.md)| Enables the `Trunc` operator to truncate a _TFraction_ record to the nearest whole number in the direction of zero. |
62
+
|_[Initialize](./TFraction-Initialize.md)[~>0.2]_| When compiled with Delphi 10.4 or later, automatically initialises _TFraction_ records with _[Numerator](./TFraction-Numerator.md)_ = `0` and _[Denominator](./TFraction-Denominator.md)_ = `1`. |
59
63
60
64
### Methods
61
65
@@ -71,11 +75,14 @@ _TFraction_ defines several methods. Some are static class methods that operate
71
75
72
76
| Method | Description |
73
77
|:-------|:------------|
78
+
|_[Abs](./TFraction-Abs.md)[~>0.2]_| Returns the absolute value of the fraction (overloaded with class method). |
74
79
|[_CompareTo_](./TFraction-CompareTo.md)| Compares the fraction to another and returns a value indicating which fraction is greatest or if they are equal. |
75
80
|[_Convert_](./TFraction-Convert.md)| Converts the fraction into an equivalent one in which the numerator and denominator are a given integer multiple of their original values. |
76
81
|[_HasCommonFactor_](./TFraction-HasCommonFactor.md)| Checks if a given integer is a common factor of the fraction. |
82
+
|_[Hash](./TFraction-Hash.md)[~>0.2]_| Computes a hash for the fraction. |
77
83
|[_IsProper_](./TFraction-IsProper.md)| Checks if the fraction is a proper fraction. |
78
84
|[_IsWholeNumber_](./TFraction-IsWholeNumber.md)| Checks if the fraction represents a whole number. |
85
+
|_[Power](./TFraction-Power.md)[~>0.2]_| Computes an integer power of a fraction (overloaded with class method). |
79
86
|[_Reciprocal_](./TFraction-Reciprocal.md)| Returns the reciprocal of the fraction. |
80
87
|[_RoundToMultiple_](./TFraction-RoundToMultiple.md)| Rounds the fraction to the nearest whole number multiple of another fraction. |
81
88
|[_Sign_](./TFraction-Sign.md)| Returns a value representing the sign of the fraction. |
@@ -86,9 +93,9 @@ _TFraction_ defines several methods. Some are static class methods that operate
86
93
87
94
| Method | Description |
88
95
|:-------|:------------|
89
-
|[_Abs_](./TFraction-Abs.md)| Returns the absolute value of a given fraction. |
96
+
|[_Abs_](./TFraction-Abs.md)| Returns the absolute value of a given fraction ([~>0.2] overloaded with instance method). |
90
97
|[_Compare_](./TFraction-Compare.md)| Compares two fractions and returns a value indicating which of the two is greater or if they equal. |
91
98
|[_LCD_](./TFraction-LCD.md)| Computes the least common denominator of two fractions. |
92
99
|[_Max_](./TFraction-Max.md)| Overloaded methods that find the largest of two or more fractions. |
93
100
|[_Min_](./TFraction-Min.md)| Overloaded methods that find the smallest of two or more fractions. |
94
-
|[_Power_](./TFraction-Power.md)| Computes an integer power of a fraction. |
101
+
|[_Power_](./TFraction-Power.md)| Computes an integer power of a fraction ([~>0.2] overloaded with instance method). |
Copy file name to clipboardExpand all lines: Fractions/0/Overview.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -14,7 +14,7 @@ Operator overloading is used extensively to enable normal arithmetic operations
14
14
15
15
## Compatibility
16
16
17
-
This unit is designed for compilation with 32 bit and 64 bit Windows Delphi compilers. It is designed to compile with compilers from Delphi 2009 onwards.
17
+
This unit is designed for compilation with 32 bit and 64 bit Windows Delphi compilers. It is designed to compile with compilers from Delphi XE onwards. It may compile with Delphi 2009 and Delphi 2010, but this is not tested and not guaranteed.
18
18
19
19
The code uses only Delphi RTL libraries and so should be able to compile for any platform supported by Delphi.
0 commit comments