MCPcopy Create free account
hub / github.com/cockroachdb/cockroachdb-parser / MulFloat

Method MulFloat

pkg/util/duration/duration.go:823–842  ·  view source on GitHub ↗

MulFloat returns a Duration representing a time length of d*x.

(x float64)

Source from the content-addressed store, hash-verified

821
822// MulFloat returns a Duration representing a time length of d*x.
823func (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.
845func (d Duration) DivFloat(x float64) Duration {

Callers 1

sqlStdToDurationFunction · 0.80

Calls 1

MakeDurationFunction · 0.85

Tested by

no test coverage detected