Skip to content

Commit eccbd5f

Browse files
authored
Checks for zeroness (#332)
* Checks for zeroness * Remove iszero equality checks * Add tests for iszero
1 parent cc1be0e commit eccbd5f

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

src/rewrite.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ function Base.:/(z::Zero, x::Any)
7979
end
8080
end
8181

82+
Base.iszero(::Zero) = true
83+
Base.isone(::Zero) = false
84+
8285
# These methods are used to provide an efficient implementation for the common
8386
# case like `x^2 * sum(f for i in 1:0)`, which lowers to
8487
# `_MA.operate!!(*, x^2, _MA.Zero())`. We don't need the method with reversed

test/rewrite.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import MutableArithmetics as MA
1919
@test -z isa MA.Zero
2020
@test +z isa MA.Zero
2121
@test *(z) isa MA.Zero
22+
@test iszero(z)
23+
@test !isone(z)
2224
end
2325

2426
# Test that the macro call `m` throws an error exception during pre-compilation

0 commit comments

Comments
 (0)