Wednesday, 15 June 2011

Why does dividing two time.durations in Go result in another time.duration? -


I do not understand what's the time to divide a time. Date it means.

For example, this is super cute:

  d, _: = time.ParseDuration ("4s") fmt.Println (d / 4)  

print 1s . Which ace is, because (undoubtedly) 4 seconds divided by 4 is 1 second.

It becomes a bit misleading, though we find that every one in 4 should have a duration. So though:

  d1: = time.Duration (4) fmt.println (d / d1)  

also print 1s , we know that d1 is actually 4ns and I completely disagree that dividing 4 seconds by 4 nanoseconds 1 is not behind.

I get confused because the duration divided by the period should be without dimension (I think, right?), Whereas there should be units of time in a period divided by a non-dimensional number.

And I know that type = unit, but I'm obviously having some misunderstanding, or very possibly a set of things. Any help to clean it will be most appreciated!

The above examples are a play ground. . And just for reference, I am trying to calculate the average time between events. I can fall back to using floats for a second, but I am trying to stay in time. Text itemprop = "text">

is because the time.Duration Is int64 . See the documentation

You divide 4000000000 (4S) by 4 (4) and you get 1000000000 (1s). You would like to see the operations where they type the value not typed the integer duration , it looks like a physical value, but for division it is just a number.


No comments:

Post a Comment