Skip to content

Commit

Permalink
address review
Browse files Browse the repository at this point in the history
  • Loading branch information
oscardssmith committed Jan 13, 2025
1 parent 3402a7e commit a0af124
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
6 changes: 2 additions & 4 deletions base/math.jl
Original file line number Diff line number Diff line change
Expand Up @@ -831,13 +831,11 @@ min(x::T, y::T) where {T<:AbstractFloat} = isnan(x) || ~isnan(y) && _isless(x, y
max(x::T, y::T) where {T<:AbstractFloat} = isnan(x) || ~isnan(y) && _isless(y, x) ? x : y
minmax(x::T, y::T) where {T<:AbstractFloat} = min(x, y), max(x, y)

_isless(x::Float16, y::Float16) = signbit(widen(x) - widen(y))

function min(x::T, y::T) where {T<:Union{Float16,Float32,Float64}}
function min(x::T, y::T) where {T<:IEEEFloat}
return min_float(x, y)
end

function max(x::T, y::T) where {T<:Union{Float16,Float32,Float64}}
function max(x::T, y::T) where {T<:IEEEFloat}
return max_float(x, y)
end

Expand Down
8 changes: 4 additions & 4 deletions src/runtime_intrinsics.c
Original file line number Diff line number Diff line change
Expand Up @@ -1404,15 +1404,15 @@ bi_fintrinsic(sub,sub_float)
bi_fintrinsic(mul,mul_float)
bi_fintrinsic(div,div_float)

float min_float(float x, float y)
float min_float(float x, float y) JL_NOTSAFEPOINT
{
float diff = x - y;
float argmin = signbit(diff) ? x : y;
int is_nan = isnan(x) || isnan(y);
return is_nan ? diff : argmin;
}

double min_double(double x, double y)
double min_double(double x, double y) JL_NOTSAFEPOINT
{
double diff = x - y;
double argmin = signbit(diff) ? x : y;
Expand All @@ -1423,15 +1423,15 @@ double min_double(double x, double y)
#define _min(a, b) sizeof(a) == sizeof(float) ? min_float(a, b) : min_double(a, b)
bi_fintrinsic(_min, min_float)

float max_float(float x, float y)
float max_float(float x, float y) JL_NOTSAFEPOINT
{
float diff = x - y;
float argmin = signbit(diff) ? y : x;
int is_nan = isnan(x) || isnan(y);
return is_nan ? diff : argmin;
}

double max_double(double x, double y)
double max_double(double x, double y) JL_NOTSAFEPOINT
{
double diff = x - y;
double argmin = signbit(diff) ? x : y;
Expand Down

0 comments on commit a0af124

Please sign in to comment.