Skip to content

Can not divide number by data series #86

Open
@olekscode

Description

@olekscode

All arithmetic operations can be perform in four ways: scalar-scalar, series-scalar, scalar-series, and series-series.

Except for the division. It is implemented in a way that expects a number:

/ aNumber 
	"Primitive. This primitive (for /) divides the receiver by the argument
	and returns the result if the division is exact. Fail if the result is not a
	whole integer. Fail if the argument is 0 or is not a SmallInteger. Optional.
	No Lookup. See Object documentation whatIsAPrimitive."

	<primitive: 10>
	aNumber isZero ifTrue: [^(ZeroDivide dividend: self) signal].
	^(aNumber isMemberOf: SmallInteger)
		ifTrue: [(Fraction numerator: self denominator: aNumber) reduced]
		ifFalse: [super / aNumber]

As a result, these are valid:

2 * series.
3 + series.
4 - series.

But this raises an exception that series does not understand isZero:

1 / series.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions