MulFloat returns a Duration representing a time length of d*x.
(x float64)
| 821 | |
| 822 | // MulFloat returns a Duration representing a time length of d*x. |
| 823 | func (d Duration) MulFloat(x float64) Duration { |
| 824 | // Have a couple of special cases to avoid rounding errors with very large |
| 825 | // intervals. |
| 826 | // TODO(#26932): once we correctly error out on intervals out of range, this |
| 827 | // could be removed. |
| 828 | switch x { |
| 829 | case 1: |
| 830 | return d |
| 831 | case -1: |
| 832 | return MakeDuration(-d.nanos, -d.Days, -d.Months) |
| 833 | } |
| 834 | monthInt, monthFrac := math.Modf(float64(d.Months) * x) |
| 835 | dayInt, dayFrac := math.Modf((float64(d.Days) * x) + (monthFrac * DaysPerMonth)) |
| 836 | |
| 837 | return MakeDuration( |
| 838 | int64((float64(d.nanos)*x)+(dayFrac*float64(nanosInDay))), |
| 839 | int64(dayInt), |
| 840 | int64(monthInt), |
| 841 | ) |
| 842 | } |
| 843 | |
| 844 | // DivFloat returns a Duration representing a time length of d/x. |
| 845 | func (d Duration) DivFloat(x float64) Duration { |
no test coverage detected