Skip to content

Commit 3df0d40

Browse files
arnavk23Peter Barnes
authored andcommitted
doc: (fixes #1238) Improve Time section documentation with example and SetResolution explanation
1 parent 443dd51 commit 3df0d40

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

doc/manual/source/events.rst

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,64 @@ by a scalar (numeric value)). Times can be written to/read from IO streams.
370370
In the case of writing it is easy to choose the output unit, different
371371
from the resolution unit.
372372

373+
Here are examples of common usage:
374+
375+
.. sourcecode:: cpp
376+
377+
Time t1 = MilliSeconds(1500); // 1.5 s = 1500 ms
378+
Time t2 = MicroSeconds(500); // 500 microseconds
379+
Time t3 = t1 + t2; // arithmetic
380+
Time t4 = t3 * 2; // multiplication
381+
382+
if (t4 > Seconds(3))
383+
{
384+
std::cout << "t4 is greater than 3 seconds\n";
385+
}
386+
387+
double ms = t4.GetMilliSeconds(); // convert to double in ms
388+
389+
std::cout << t4.As(Time::MS) << "\n"; // stream with specific unit
390+
391+
.. note::
392+
393+
When using floating-point values with constructors like ``Seconds(1.5)``,
394+
users should be aware that values smaller than the current resolution
395+
will be rounded. For example, if the resolution is set to nanoseconds,
396+
values like ``Seconds(1e-10)`` will be rounded to zero.
397+
Consider inspecting ``Time::SetResolution()`` and using methods like
398+
``GetNanoSeconds()`` to understand how sub-resolution values behave in practice.
399+
400+
When calling ``Time::SetResolution()``, there is a trade-off between
401+
the precision of time measurements and the maximum simulation time
402+
span that can be represented. Finer resolutions (like femtoseconds)
403+
allow for more precise timing but reduce the maximum representable
404+
duration.
405+
406+
.. list-table::
407+
:header-rows: 1
408+
:widths: 25 25 50
409+
410+
* - Resolution Unit
411+
- Smallest Step
412+
- Approximate Max Time Span
413+
* - Seconds
414+
- 1 s
415+
- ~2.9 × 10¹¹ years
416+
* - Milliseconds
417+
- 1 ms
418+
- ~2.9 × 10⁸ years
419+
* - Microseconds
420+
- 1 µs
421+
- ~2.9 × 10⁵ years
422+
* - Nanoseconds
423+
- 1 ns
424+
- ~292 years
425+
* - Picoseconds
426+
- 1 ps
427+
- ~107 days
428+
* - Femtoseconds
429+
- 1 fs
430+
- ~2.6 hours
373431

374432
Scheduler
375433
*********

0 commit comments

Comments
 (0)