MCPcopy
hub / github.com/TomWright/dasel / Divide

Method Divide

model/value_math.go:167–213  ·  view source on GitHub ↗

Divide returns the result of dividing the value by another value.

(other *Value)

Source from the content-addressed store, hash-verified

165
166// Divide returns the result of dividing the value by another value.
167func (v *Value) Divide(other *Value) (*Value, error) {
168 if v.IsInt() && other.IsInt() {
169 a, err := v.IntValue()
170 if err != nil {
171 return nil, err
172 }
173 b, err := other.IntValue()
174 if err != nil {
175 return nil, err
176 }
177 return NewValue(a / b), nil
178 }
179 if v.IsFloat() && other.IsFloat() {
180 a, err := v.FloatValue()
181 if err != nil {
182 return nil, err
183 }
184 b, err := other.FloatValue()
185 if err != nil {
186 return nil, err
187 }
188 return NewValue(a / b), nil
189 }
190 if v.IsInt() && other.IsFloat() {
191 a, err := v.IntValue()
192 if err != nil {
193 return nil, err
194 }
195 b, err := other.FloatValue()
196 if err != nil {
197 return nil, err
198 }
199 return NewValue(float64(a) / b), nil
200 }
201 if v.IsFloat() && other.IsInt() {
202 a, err := v.FloatValue()
203 if err != nil {
204 return nil, err
205 }
206 b, err := other.IntValue()
207 if err != nil {
208 return nil, err
209 }
210 return NewValue(a / float64(b)), nil
211 }
212 return nil, fmt.Errorf("could not divide: %w", ErrIncompatibleTypes{A: v, B: other})
213}
214
215// Modulo returns the remainder of the division of two values.
216func (v *Value) Modulo(other *Value) (*Value, error) {

Callers 2

TestValue_DivideFunction · 0.80
initFunction · 0.80

Calls 5

IsIntMethod · 0.95
IntValueMethod · 0.95
IsFloatMethod · 0.95
FloatValueMethod · 0.95
NewValueFunction · 0.85

Tested by 1

TestValue_DivideFunction · 0.64