CosmWasm / cosmwasm

Framework for building smart contracts in Wasm for the Cosmos SDK
https://www.cosmwasm.com/
Apache License 2.0
1.06k stars 329 forks source link

`contains` does not work with `Decimal` ranges #1140

Closed maurolacy closed 2 years ago

maurolacy commented 2 years ago

contains idiom for checking ranges is broken for Decimal.

$ evcxr
Welcome to evcxr. For help, type :help
>> :dep cosmwasm-std = { version = "1.0.0-beta" }
>> use cosmwasm_std::Decimal;
>> let p = Decimal::from_ratio(5u8, 10u8);
>> p.to_string()
"0.5"
>> Decimal::zero() <= p && p <= Decimal::one()
true
>> [Decimal::zero(), Decimal::one()].contains(&p)
false
>> 

Not sure this will be / can be easily fixed, but good to know it doesn't work, in any case.

webmaster128 commented 2 years ago

But [Decimal::zero(), Decimal::one()] is a array or slice, not a range. https://doc.rust-lang.org/1.55.0/std/primitive.slice.html#method.contains

Or am I missing something?

maurolacy commented 2 years ago

You're right! I'm writing the "range" wrong... thanks, closing in shame.

contains() was there, so... :-)