Skip to content

Commit e0321e0

Browse files
committed
RFC #66: Change way of construction
1 parent eac6b9f commit e0321e0

File tree

1 file changed

+24
-15
lines changed

1 file changed

+24
-15
lines changed

text/0066-simulation-time.md

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,22 @@ Also, to quote @whitequark: Time is not a number.
2222
[guide-level-explanation]: #guide-level-explanation
2323

2424
A new type `Period` is introduced.
25-
It is immutable, has no public constructor and is instead constructed through the following classmethods:
26-
- `.s(duration: numbers.Real)`
27-
- `.ms(duration: numbers.Real)`
28-
- `.us(duration: numbers.Real)`
29-
- `.ns(duration: numbers.Real)`
30-
- `.ps(duration: numbers.Real)`
31-
- `.fs(duration: numbers.Real)`
32-
- `.Hz(frequency: numbers.Real)`
33-
- `.kHz(frequency: numbers.Real)`
34-
- `.MHz(frequency: numbers.Real)`
35-
- `.GHz(frequency: numbers.Real)`
36-
- The argument will be scaled according to the SI prefix on the method and the `duration` or reciprocal of `frequency` then used to calculate the closest integer femtosecond representation.
25+
It is immutable and has a constructor accepting at most one named argument, giving the following valid forms of construction:
26+
- `Period()`
27+
- Constructs a zero period.
28+
- `Period(seconds: numbers.Real)`
29+
- `Period(milliseconds: numbers.Real)`
30+
- `Period(microseconds: numbers.Real)`
31+
- `Period(nanoseconds: numbers.Real)`
32+
- `Period(picoseconds: numbers.Real)`
33+
- `Period(femtoseconds: numbers.Real)`
34+
- The argument will be scaled according to its SI prefix and used to calculate the closest integer femtosecond representation.
35+
- `Period(hertz: numbers.Real)`
36+
- `Period(kilohertz: numbers.Real)`
37+
- `Period(megahertz: numbers.Real)`
38+
- `Period(gigahertz: numbers.Real)`
39+
- The argument will be scaled according to its SI prefix and its reciprocal used to calculate the closest integer femtosecond representation.
40+
A value of zero will raise `ZeroDivisionError`.
3741

3842
To convert it back to a number, the following properties are available:
3943
- `.seconds -> fractions.Fraction`
@@ -120,6 +124,9 @@ Consequently, `Platform.default_clk_frequency()` is also deprecated and replaced
120124

121125
- `.elapsed_time()` is only available from within a testbench/process, where it is well defined.
122126

127+
- Instead of named constructor arguments, we could use a classmethod for each SI prefix.
128+
This was proposed in an earlier revision of this RFC.
129+
123130
## Prior art
124131
[prior-art]: #prior-art
125132

@@ -130,10 +137,12 @@ None.
130137

131138
- With the scope of `Period` extended beyond simulation, where do we put it?
132139

133-
- The usual bikeshedding.
134-
- Case, e.g. `.MHz` vs `.mhz`.
140+
- Should we use shorter argument/property names like `MHz` instead of (or an alias in addition to) `megahertz`?
141+
142+
- Should we disallow passing a negative frequency or accessing a frequency property on a negative period?
135143

136-
- Should `Period` also have properties to return the reciprocal frequency?
144+
- We could allow passing multiple constructor arguments and add them together -- should we?
145+
- Probably not. Limited usefulness for durations and nonsensical for frequencies.
137146

138147
## Future possibilities
139148
[future-possibilities]: #future-possibilities

0 commit comments

Comments
 (0)