Skip to content

Commit 6f287a1

Browse files
committed
RFC #66: Get rid of fractions.
1 parent e0321e0 commit 6f287a1

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

text/0066-simulation-time.md

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,18 @@ It is immutable and has a constructor accepting at most one named argument, givi
4040
A value of zero will raise `ZeroDivisionError`.
4141

4242
To convert it back to a number, the following properties are available:
43-
- `.seconds -> fractions.Fraction`
44-
- `.milliseconds -> fractions.Fraction`
45-
- `.microseconds -> fractions.Fraction`
46-
- `.nanoseconds -> fractions.Fraction`
47-
- `.picoseconds -> fractions.Fraction`
43+
- `.seconds -> float`
44+
- `.milliseconds -> float`
45+
- `.microseconds -> float`
46+
- `.nanoseconds -> float`
47+
- `.picoseconds -> float`
4848
- `.femtoseconds -> int`
4949

5050
To calculate the reciprocal frequency, the following properties are available:
51-
- `.hertz -> fractions.Fraction`
52-
- `.kilohertz -> fractions.Fraction`
53-
- `.megahertz -> fractions.Fraction`
54-
- `.gigahertz -> fractions.Fraction`
51+
- `.hertz -> float`
52+
- `.kilohertz -> float`
53+
- `.megahertz -> float`
54+
- `.gigahertz -> float`
5555
- Accessing these properties when the period is zero will raise `ZeroDivisionError`.
5656

5757
The following operators are defined:
@@ -71,7 +71,7 @@ The following operators are defined:
7171
- `.__mul__(other: numbers.Real) -> Period`
7272
- `.__rmul__(other: numbers.Real) -> Period`
7373
- `.__truediv__(other: numbers.Real) -> Period`
74-
- `.__truediv__(other: Period) -> fractions.Fraction`
74+
- `.__truediv__(other: Period) -> float`
7575
- `.__floordiv__(other: Period) -> int`
7676
- `.__mod__(other: Period) -> Period`
7777
- Operators on `Period`s are performed on the underlying femtosecond values.
@@ -108,12 +108,6 @@ Consequently, `Platform.default_clk_frequency()` is also deprecated and replaced
108108

109109
- Accepting a `numbers.Real` when we're converting from a number lets us pass in any standard suitable number type.
110110

111-
- When converting to a number, `fractions.Fraction` is a standard `numbers.Real` type that is guaranteed to represent any possible value exactly, and is convertible to `int` or `float`.
112-
- Returning `int` would force a potentially undesirable truncation/rounding upon the user.
113-
- Returning `float` would lose precision when the number of femtoseconds are larger than the significand.
114-
- `decimal.Decimal` is decimal floating point and thus has the same issue as `float`.
115-
- `.femtoseconds` returns `int` because that's a perfect representation and returning a fraction with a denominator of 1 adds no value.
116-
117111
- The supported set of operators are the ones that have meaningful and useful semantics:
118112
- Comparing, adding and subtracting time periods makes sense.
119113
- Multiplying a time period with or dividing it by a real number scales the time period.
@@ -127,6 +121,11 @@ Consequently, `Platform.default_clk_frequency()` is also deprecated and replaced
127121
- Instead of named constructor arguments, we could use a classmethod for each SI prefix.
128122
This was proposed in an earlier revision of this RFC.
129123

124+
- Instead of returning `float`, we could return `fractions.Fraction` to ensure no precision loss when the number of femtoseconds is larger than the `float` significand.
125+
This was proposed in an earlier revision of this RFC.
126+
- Rounding to integer femtoseconds is already lossy and a further precision loss from converting to a `float` is negligible in most real world use cases.
127+
For any applications requiring an exact conversion of a `Period`, the `.femtoseconds` property is always exact.
128+
130129
## Prior art
131130
[prior-art]: #prior-art
132131

0 commit comments

Comments
 (0)