comparetotal gives incorrect results for NaN operands
I maintainer di solito rispondono entro 1 giorno
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 25/100
Direzione di ricerca
The predicate comparetotal is shared by the six decimal types, and test_total_ordering.cpp is the test that should gain the missing cases. Build the reproduction program from the issue and check the four NaN rows for each type. Pull request #1567 already targets this fix, so review it or its tests before starting new work. Done means all six types return false, false, true, true for the four cases, with the reflexivity case covered by a test.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Problem
comparetotal(x, y) is the totalOrder predicate of IEEE 754-2019 5.10. It is true when x is before y in the total order, or when the two have the same representation. For NaN operands it has three defects.
- A positive NaN is after each number, and a negative NaN is before each number.
comparetotal(qNaN, 1)returns true for all six types.comparetotal(1, -qNaN)returns true for the fast types. - A positive NaN is after a negative NaN of the other kind, but
comparetotal(sNaN, -qNaN)andcomparetotal(qNaN, -sNaN)return true for all six types. - The predicate is reflexive. For two NaNs with the same sign, kind and payload,
comparetotalreturns false.
Reproduction
#include <boost/decimal.hpp>
#include <iostream>
#include <limits>
using namespace boost::decimal;
template <typename T>
void check(const char* name)
{
const T one {1};
const T qnan {std::numeric_limits<T>::quiet_NaN()};
const T snan {std::numeric_limits<T>::signaling_NaN()};
std::cout << std::boolalpha << "| `" << name << "` | " << comparetotal(one, -qnan) << " | " << comparetotal(qnan, one)
<< " | " << comparetotal(qnan, qnan) << " | " << comparetotal(-snan, -snan) << " |\n";
}
int main()
{
check<decimal32_t>("decimal32_t");
check<decimal64_t>("decimal64_t");
check<decimal128_t>("decimal128_t");
check<decimal_fast32_t>("decimal_fast32_t");
check<decimal_fast64_t>("decimal_fast64_t");
check<decimal_fast128_t>("decimal_fast128_t");
}
Result on develop (215bbf025), GCC 16.2.1, x86-64 Linux, C++20.
| Type | (1, -qNaN) |
(qNaN, 1) |
(qNaN, qNaN) |
(-sNaN, -sNaN) |
|---|---|---|---|---|
decimal32_t |
false | true | false | false |
decimal64_t |
false | true | false | false |
decimal128_t |
false | true | false | false |
decimal_fast32_t |
true | true | false | false |
decimal_fast64_t |
true | true | false | false |
decimal_fast128_t |
true | true | false | false |
test_total_ordering.cpp expects false for a NaN compared with itself, and it does not check a NaN on the left side of a number.
Expected result
Each row gives false, false, true, true. Python decimal gives the same four results with x.compare_total(y) <= 0.
Proposed fix
Write the NaN part again in the order of 5.10 d.1 to d.3: first the sign, then signaling before quiet, then the payload. Negative NaNs have the opposite order. Change the documentation of the payload rule to "less than or equal".
Reference
- #1490 (Relook Fundamental Optimization of Comparisons)
- Lingua principale
- C++
- Stelle
- 67
- Fork
- 16
- Merge medio
- 1g 15h
- PR unite (30g)
- 12
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di boostorg/decimal
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 22/100
I maintainer di solito rispondono entro 1 giorno
-
The decimal types have no operator<=> with GCC and Clang if no earlier header includes <compare>Forse già presa @ibmibmibm l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 25/100
I maintainer di solito rispondono entro 1 giorno
-
A comparison of a decimal and an integer gives incorrect resultsForse già presa @ibmibmibm l’ha presa oggi. Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 22/100
I maintainer di solito rispondono entro 1 giorno
-
A comparison of two decimal types can use the type with fewer digitsForse già presa @ibmibmibm l’ha presa oggi. Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 20/100
I maintainer di solito rispondono entro 1 giorno
-
sinh, cosh, tanh, expm1 and exp2 give incorrect results, and 0 or infinity for some finite resultsForse già presa @ibmibmibm l’ha presa 7 giorni fa. Aperta
Difficoltà 5/5 Più di una settimana Idoneità per principianti 10/100
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di boostorg/decimal
Issue simili
-
agent:WSL code-review linux pri:medium refactoring
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
I maintainer di solito rispondono entro 1 giorno
-
kind/enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 1-3 ore Idoneità per principianti 82/100
psi29a/d2decomped#691 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
CachyOS/packageinstaller#144 ·
I maintainer di solito rispondono entro 1 giorno
-
(S1 - Need confirmation)
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
CleverRaven/Cataclysm-DDA#89715 ·
I maintainer di solito rispondono entro 1 giorno