Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integers in the type domain #55571

Closed
wants to merge 64 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
a36791a
import from src/ from my package TypeDomainNaturalNumbers.jl
nsajko Aug 19, 2024
da72b8b
rename module `TypeDomainNaturalNumbers` to `TypeDomainIntegers`
nsajko Aug 19, 2024
22991b8
add copyright notice
nsajko Aug 19, 2024
48ed9e5
include the new file into `Base`
nsajko Aug 19, 2024
e71bf9b
make the new types subtype `Integer`
nsajko Aug 19, 2024
2bf4b17
delete `NegativeInteger` constructor to prevent ambiguity
nsajko Aug 21, 2024
3b93756
delete `with_refined_type`, just use the type assertion directly
nsajko Aug 19, 2024
ee728a5
don't add ambiguous methods to `Base`
nsajko Aug 19, 2024
97c0d82
refactor: introduce `interoperable`
nsajko Aug 19, 2024
3f5a1a7
base the interoperability with other numbers on `Int8`
nsajko Aug 19, 2024
59af5d8
support conversion from/to other primitive types
nsajko Aug 19, 2024
81b9621
`interoperable`: return `Bool` when possible
nsajko Aug 19, 2024
e7b09c5
import the tests from my Gitlab, adjust
nsajko Aug 19, 2024
e4ba24f
fix dispatch to conversion to `Bool`
nsajko Aug 20, 2024
a05a7ec
export the `apply_` functions from `BaseHelpers`
nsajko Aug 20, 2024
302fa38
delete `apply_` fallbacks
nsajko Aug 20, 2024
33db6a5
implement `apply_` for equality
nsajko Aug 20, 2024
d216418
implement promotion
nsajko Aug 20, 2024
728e59e
instead of forcing a narrow type, widen on overflow
nsajko Aug 21, 2024
15698f4
`BaseHelpers`: simplify, `tdi_to_int` now may return `Bool`
nsajko Aug 21, 2024
d3f8933
`BaseHelpers`: `interoperable` -> `tdi_to_int`
nsajko Aug 21, 2024
a0b0c9a
`BaseHelpers`: bugfix for equality: import `iszero`
nsajko Aug 23, 2024
3c29e5b
`BaseHelpers`: `a - b` -> `a + -b`
nsajko Aug 21, 2024
ade3b06
define binary operations using `BaseHelpers`
nsajko Aug 23, 2024
6f463f4
implement `abs`
nsajko Aug 21, 2024
8a3b13f
implement promotion between `TypeDomainInteger` subtypes
nsajko Aug 21, 2024
f213c52
implement conversion to `AbstractFloat`
nsajko Aug 22, 2024
9fcf4a2
delete `tdnn_to_x`, it's unused
nsajko Aug 22, 2024
6858b76
implement `tdnn_from_int(::Bool)`, `tdi_from_int(::Bool)`
nsajko Aug 22, 2024
49809ff
implement `<:AbstractFloat` constructors taking `RoundingMode`
nsajko Aug 22, 2024
8799b83
implement `signbit`
nsajko Aug 22, 2024
7dd4350
implement `sign`
nsajko Aug 22, 2024
47b6abc
specialize `inv`
nsajko Aug 23, 2024
9835209
implement `widen`
nsajko Aug 23, 2024
de6b57b
specialize `show`
nsajko Aug 23, 2024
58dd019
use `TypeDomainIntegers` from `Base`
nsajko Aug 22, 2024
730a5aa
implement `isqrt`
nsajko Aug 22, 2024
af5bc27
implement `factorial`
nsajko Aug 22, 2024
29a3435
`to_power_type(@nospecialize x::TypeDomainInteger) = x`
nsajko Aug 22, 2024
0a99dc0
use `TypeDomainIntegers` from `Base.Math`
nsajko Aug 22, 2024
6545620
math: implement `sqrt` `cbrt`, `fourthroot`
nsajko Aug 22, 2024
8c1920a
math: `hypot(x::TypeDomainInteger) = abs(x)`
nsajko Aug 22, 2024
de04594
math: specialize `deg2rad`, `rad2deg`
nsajko Aug 22, 2024
b2e9757
math: specialize logarithms
nsajko Aug 22, 2024
5670b8d
math: specialize `exp2`, `exp10`, `expm1`
nsajko Aug 22, 2024
c4f0c51
math: specialize some hyperbolic functions
nsajko Aug 22, 2024
1bceeb6
math: specialize `sind`, `asind`, `cosd`, `acosd`, `secd`, `asecd`
nsajko Aug 22, 2024
59bff74
math: specialize `sinpi`, `cospi`, `tanpi`
nsajko Aug 22, 2024
95d9cea
math: specialize `sinc`, `cosc`
nsajko Aug 23, 2024
301b575
complex: specialize `imag(::Real)`
nsajko Aug 22, 2024
21dd6b9
complex: specialize `cispi`
nsajko Aug 23, 2024
8d02b19
rational: make `denominator(::Integer)` return type domain one
nsajko Aug 23, 2024
b8abb9e
gmp: conversion from `BigInt`
nsajko Aug 22, 2024
4ab3521
mpfr: conversion from `BigFloat`
nsajko Aug 22, 2024
51c2863
irrationals: `zero`, `one`, `sign`
nsajko Aug 22, 2024
fb97552
`MathConstants`: return type domain integers when that makes sense
nsajko Aug 22, 2024
1a62a82
specialize: angle exp sin tan cos asin atan acos
nsajko Aug 22, 2024
c6b1a50
gmp, mpfr, irrationals: define binary operations using `BaseHelpers`
nsajko Aug 23, 2024
8f16391
update tests: relax `===` to `==`
nsajko Aug 23, 2024
7de1320
test issue #37977
nsajko Aug 23, 2024
8900ea3
complex: nospecialize for `cispi`
nsajko Aug 23, 2024
2116f13
InteractiveUtils: fix/disable doc test
nsajko Aug 23, 2024
eaa25f9
uncomment some tests
nsajko Aug 23, 2024
55c423b
delete redundant `isequal` and `==` methods
nsajko Aug 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
irrationals: zero, one, sign
nsajko committed Aug 23, 2024
commit 51c2863a0156b5b5b894538d2aa96be52be26e1f
17 changes: 12 additions & 5 deletions base/irrationals.jl
Original file line number Diff line number Diff line change
@@ -151,13 +151,20 @@ hash(x::Irrational, h::UInt) = 3*objectid(x) - h

widen(::Type{T}) where {T<:Irrational} = T

zero(::AbstractIrrational) = false
zero(::Type{<:AbstractIrrational}) = false
zero(::AbstractIrrational) = zero(TypeDomainInteger)
zero(::Type{<:AbstractIrrational}) = zero(TypeDomainInteger)

one(::AbstractIrrational) = true
one(::Type{<:AbstractIrrational}) = true
one(::AbstractIrrational) = one(TypeDomainInteger)
one(::Type{<:AbstractIrrational}) = one(TypeDomainInteger)

sign(x::AbstractIrrational) = ifelse(x < zero(x), -1.0, 1.0)
function sign(x::AbstractIrrational)
o = one(TypeDomainInteger)
if signbit(x)
-o
else
o
end
end

-(x::AbstractIrrational) = -Float64(x)
for op in Symbol[:+, :-, :*, :/, :^]