[Ns-developers] NS3 Time objects
mathieu lacage
Mathieu.Lacage at sophia.inria.fr
Wed Nov 1 12:35:17 PST 2006
On Wed, 2006-11-01 at 14:04 +0000, Gustavo Carneiro wrote:
> You propose to add a couple of intermediate result types, TimeSquare
> and TimeInvert, in addition to the Time and Scalar types. I like this
> approach very much with a single reservation. Here's some good things
> I found about it:
I do not propose to do this. I am merely considering the possibility
that this might work. I should point out that there are inherent limits
to this idea. i.e. if you try to write an expression which could
generate a TimeCube, you are screwed. Yes, you could write TimeCube but
then what about TimeFour ? Sure, we can try to minimize the probability
that we get the problem. But this is not very satisfactory.
By the way, yes, we could probably use a template with an integer
parameter to modelize this: Time<N> would refer to Time^N but, really, I
am scared.
> 1- The types TimeSquare and TimeInvert exist inside NS-3, and could
> even be used by the programmer, but are very rarely exposed to the
> programmer, so they work behind the scenes and do their job well (next
> point), but are almost invisible to the end user;
>
> 2- The existence of TimeSquare not only solves the "moral dilemma"
> of what to call the result of Time*Time, but also it has implications
> beyond this point, because in theory you would need a 128-bit type in
> order to store the result of multiplying two 64-bit types. Likewise,
> TimeInvert allows you to store an "inverted time" without any loss of
> precision: you can simply store in the instance the original uint64_t
> value plus a double scale factor. If, on the other hand, you tried to
> do the same exclusively with a Time class you would lose precision
> when dividing 1.0 by a uint64_t value and representing the result as
> another uint64_t.
Indeed. However, this is all rather complex. I really think that it
would be vastly simpler to simply define Time operator * (Time, Time).
And all we need to do to make the Scalar thing work is implement the
Time class with a higher precision than 64 bits. What I find interesting
is that both solutions will export the exact same API to the user. But
one of them seems much more complex to implement.
> What I don't like about the proposal is just that "class Scalar"
> might as well be an alias for double; at least I don't see anything
> that Scalar does that double doesn't already do, and if so introducing
> a new ns3::Scalar type will only obfuscate code and not achieve any
> practical result. But please correct me if I'm wrong.
I think that Scalar could be implemented with something else.
Mathieu
--
More information about the Ns-developers
mailing list