MCPcopy
hub / github.com/shopspring/decimal / Floor

Method Floor

decimal.go:1712–1726  ·  view source on GitHub ↗

Floor returns the nearest integer value less than or equal to d.

()

Source from the content-addressed store, hash-verified

1710
1711// Floor returns the nearest integer value less than or equal to d.
1712func (d Decimal) Floor() Decimal {
1713 d.ensureInitialized()
1714
1715 if d.exp >= 0 {
1716 return d
1717 }
1718
1719 exp := big.NewInt(10)
1720
1721 // NOTE(vadim): must negate after casting to prevent int32 overflow
1722 exp.Exp(exp, big.NewInt(-int64(d.exp)), nil)
1723
1724 z := new(big.Int).Div(d.value, exp)
1725 return Decimal{value: z, exp: 0}
1726}
1727
1728// Ceil returns the nearest integer value greater than or equal to d.
1729func (d Decimal) Ceil() Decimal {

Callers 5

Benchmark_FloorFastFunction · 0.80
Benchmark_FloorRegularFunction · 0.80
TestDecimal_FloorFunction · 0.80

Calls 2

ensureInitializedMethod · 0.95
DivMethod · 0.80

Tested by 5

Benchmark_FloorFastFunction · 0.64
Benchmark_FloorRegularFunction · 0.64
TestDecimal_FloorFunction · 0.64