<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Oct 16, 2017 at 3:58 AM, Victor Stinner <span dir="ltr"><<a href="mailto:victor.stinner@gmail.com" target="_blank">victor.stinner@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi,<br>
<span class="gmail-"><br>
> What if we had a class, say time.time_base. The user could specify the base<br>
> units (such as "s", "ns", 1e-7, etc) and the data type ('float', 'int',<br>
</span>> 'decimal', etc.) when the class is initialized. (...)<br>
<br>
It's easy to invent various funny new types for arbitrary precision.<br>
<br>
But I prefer reusing the standard Python int type since it's very well<br>
known and very easy to manipulate. There is not need to modify the<br>
whole stdlib to support a new type. Moreover, we don't have to<br>
"implement a new type".<br>
<span class="gmail-"></span><br></blockquote></div></div><div class="gmail_extra"><br></div><div class="gmail_extra">I guess I wasn't clear. <br></div><div class="gmail_extra"><br></div><div class="gmail_extra">I am not suggesting implementing a new numeric data type. People wouldn't use the class directly like they would an int or float, they would simply use it to define the the precision and numeric type (float, int, decimal). Then they would have access to the entire "time" API as methods. So for example you could do something like:</div><div class="gmail_extra"><br></div><div class="gmail_extra"> >>> import time</div><div class="gmail_extra"> >>><br></div><div class="gmail_extra"> >>> ns_time_int = time.time_base(units='ns', type=int)<br><div class="gmail_extra"> >>> ms_time_dec = time.time_base(units=1e-6, type='Decimal')<div class="gmail_extra"> >>> s_time_float= time.time_base(units=1, type=float) # This is identical to the existing "time" functions<br></div></div><div class="gmail_extra"> >>><br></div></div><div class="gmail_extra"> >>> ns_time_int.clock()</div><div class="gmail_extra"> 4978480000<div class="gmail_extra"> >>> ms_time_dec.clock()</div><div class="gmail_extra"> Decimal('5174165.999999999')<br></div><div class="gmail_extra"><div class="gmail_extra"> >>> s_time_float.clock()</div><div class="gmail_extra"> 5.276855<br></div></div></div><div class="gmail_extra"> >>></div><div class="gmail_extra"> >>> ns_time_int.perf_counter()</div><div class="gmail_extra"> 243163378188085<br><div class="gmail_extra"> >>> ms_time_dec.perf_counter()</div><div class="gmail_extra"> Decimal('243171477786.264')</div><div class="gmail_extra"> >>> s_time_float.perf_counter()</div><div class="gmail_extra"> 243186.530955074</div></div><br><div class="gmail_extra"><span class="gmail-sig-paren"></span></div></div>