-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Add ispositive
, etc.
#53677
base: master
Are you sure you want to change the base?
Add ispositive
, etc.
#53677
Changes from 32 commits
d0323ac
9b47c02
b774f97
5f76224
0cddd58
84ac2f8
b1b86a5
f09a032
a2bbe5e
ff0704f
a2aee14
9276fb4
c63b3ce
7c03d55
bb1201a
049133a
645ceb6
2e5941f
4540780
bfd28c5
1b71527
e09fec9
86c7224
7a1e53f
24dd8be
f303313
d8d1baa
099680e
5ed79da
bd2dd5f
54dd7c7
a66321a
761ed61
b6c1d88
d6b9be6
9ebc0a7
dfa057e
e922bf5
02dec43
7db7a2b
fc3a0de
c372cb2
9e26047
bfbb69c
85b3e56
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -295,7 +295,9 @@ export | |
isinf, | ||
isinteger, | ||
isnan, | ||
isnegative, | ||
isodd, | ||
ispositive, | ||
ispow2, | ||
isqrt, | ||
isreal, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -136,6 +136,52 @@ true | |
""" | ||
signbit(x::Real) = x < 0 | ||
|
||
""" | ||
ispositive(x) | ||
|
||
Test whether `x > 0`. See also [`isnegative`](@ref). | ||
|
||
!!! compat "Julia 1.12" | ||
This function requires at least Julia 1.12. | ||
|
||
# Examples | ||
```jldoctest | ||
julia> ispositive(-4.0) | ||
false | ||
|
||
julia> ispositive(99) | ||
true | ||
|
||
julia> ispositive(0.0) | ||
false | ||
``` | ||
""" | ||
ispositive(x) = x > zero(x) # generic fallback | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👎 Why is there an EDIT: it's for stuff like dates and unitful There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure there should be a method for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is because of #35067 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In any case it should not belong to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I don't see the connection. That issue doesn't seem to discuss that part of the design. It barely discusses design at all. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That issue discussed reasons of having the general interface. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with @nsajko. It's always possible to add more generic functionality later, but it's impossible to go backwards. The most generic There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, I get it, thanks. |
||
ispositive(x::Real) = x > 0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I probably missed it in the discussions above, but what would be the difference between There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not related to the discussions. I just realized
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess the lowest real type on the In other words, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was more wondering why having the two different methods to start with, sounds like we should a single good definition, since There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree that having a I still like comparison with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I don't think the dual numbers are ordered though? So I guess we don't want |
||
|
||
""" | ||
isnegative(x) | ||
|
||
Test whether `x < 0`. See also [`ispositive`](@ref). | ||
|
||
!!! compat "Julia 1.12" | ||
This function requires at least Julia 1.12. | ||
|
||
# Examples | ||
```jldoctest | ||
julia> isnegative(-4.0) | ||
true | ||
|
||
julia> isnegative(99) | ||
false | ||
|
||
julia> isnegative(-0.0) | ||
false | ||
``` | ||
""" | ||
isnegative(x) = x < zero(x) # generic fallback | ||
isnegative(x::Real) = x < 0 | ||
|
||
""" | ||
sign(x) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't imagine that this ever in the future of forever makes any difference. But I think this is arguably cleaner.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's simpler and clear to see that it's the identity function for booleans, but I guess the definition of
isone
is right there. You can also probably just let the compiler optimize the fallback.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The compiler doesn't do that at present.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the compiler is being a bit silly here
it doesn't realise could simply return the input argument.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, that's #21712