JuliaPhysics / JuliaPhysics/Unitful.jl

Comparison between quantities with different underlying number type

Open
#633 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
Julia
Stars
675
Forks
124
Avg merge
3h 38m
Merged PRs (30d)
1

Description

I think I may have found a bug somewhere in the defs of `==` and `<`. If the underlying number types on LHS and RHS differ, then `==` and `<` don't behave consistently.

Example:
```julia
julia> 1//10 < 0.1
true
julia> (1//10)s <= 0.1s
false
julia> (1//10)s >= 0.1s
false
```
The first comparison is correct, as `0.1::Float64 === 0.1000000000000000055511151231257827021181583404541015625`. Obviously, at least one of the other two inequalities is wrong.

The problem seems to be that `<` promotes to `Float64`, but `==` doesn't, so `<` will conclude the two values are equal, wheres `==` will conclude that they're not.
```julia
julia> @code_lowered ==( (1//10)s, 0.1s )
```
image

```julia
julia> @code_lowered Unitful._lt( (1//10)s, 0.1s )
```
image

Contributor guide

No contributing guide indexed for this repository

Research direction

Reproduce the comparisons in the issue, then inspect the definitions of ==, <, and Unitful._lt using Julia's lowered-code view. Trace how quantities with differing underlying number types are promoted and compare the existing equality and ordering paths. Done means the comparison operators agree for the reported rational and Float64 quantities, with regression coverage for these examples.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.