ChanServ changed the topic of #rust-embedded to: Welcome to the Rust Embedded IRC channel! Bridged to #rust-embedded:matrix.org and logged at https://libera.irclog.whitequark.org/rust-embedded, code of conduct at https://www.rust-lang.org/conduct.html
JamesMunns[m] has quit [Quit: Idle timeout reached: 172800s]
rolodondo34[m] has quit [Quit: Idle timeout reached: 172800s]
starblue has quit [Ping timeout: 255 seconds]
starblue has joined #rust-embedded
M9names[m] has quit [Quit: Idle timeout reached: 172800s]
Guest7282 has left #rust-embedded [Error from remote client]
Guest7282 has joined #rust-embedded
dirbaio[m] has quit [Quit: Idle timeout reached: 172800s]
korken89[m] has quit [Quit: Idle timeout reached: 172800s]
<d3zd3z[m]> <adamgreig[m]> "yea, that's typical" <- That does end up working great, and solves the problem of how to get to it from the interrupt handler as well.
systemcall has joined #rust-embedded
firefrommoonligh has quit [Quit: Idle timeout reached: 172800s]
mabez[m] has quit [Quit: Idle timeout reached: 172800s]
systemcall has quit [Quit: Leaving]
marmrt[m] has quit [Quit: Idle timeout reached: 172800s]
sourcebox[m] has quit [Quit: Idle timeout reached: 172800s]
thejpster[m] has quit [Quit: Idle timeout reached: 172800s]
barafael[m] has joined #rust-embedded
<barafael[m]> how do I format a float so that it is always 4 places? .003, 1.45, 9.99, 12.4, 99.9, 100 , 242 , 999 `
<barafael[m]> * how do I format a float so that it is always 4 places? .003, 1.45, 9.99, 12.4, 99.9, 100 , 242 , 999 \
<barafael[m]> * how do I format a float so that it is always 4 places? .003, 1.45, 9.99, 12.4, 99.9, 100 , 242 , 999 `
<barafael[m]> * how do I format a float so that it is always 4 places? .003, 1.45, 9.99, 12.4, 99.9, 100 , 242 , 999 \
<barafael[m]> * how do I format a float so that it is always 4 places? .003, 1.45, 9.99, 12.4, 99.9, 100 , 242 , 999
inara has quit [Quit: Leaving]
inara has joined #rust-embedded
NickStevens[m] has joined #rust-embedded
<NickStevens[m]> <barafael[m]> "how do I format a float so..." <- Assuming you mean 4 decimal places you can use `{.04}` to format to 4 places and fill any missing digits with 0's.
adamgreig[m] has quit [Quit: Idle timeout reached: 172800s]
crabbedhaloablut has quit []
crabbedhaloablut has joined #rust-embedded
<barafael[m]> Nick Stevens: No, I mean 4 places. If the number is less than 1, then the leading 0 can be skipped. If it's less than 10, then `X.YZ`. If it's less than one hundred, then `XY.Z`. If it's less than a thousand, then `XYZ `. Else, `>max`. This algorithm does not work at the boundaries due to rounding I assume
<barafael[m]> Whatever I come up with proptest protests. I assume I'm missing something stupid? I only have space for four digits on the screen is all...
dirbaio[m] has joined #rust-embedded
<dirbaio[m]> that's 3 places, not 4? πŸ€”
<barafael[m]> Ok, I mean including the dot
<dirbaio[m]> anyway if you need that much control perhaps you need to do it custom
<dirbaio[m]> calc `(n*1000 + 0.5) as u32`, if that's less than `1000` then do the `.xyz` syntax... (full message at <https://catircservices.org/_matrix/media/v3/download/catircservices.org/VLFvwNaJpdqGyHfSQUnpzpjN>)
<dirbaio[m]> as a bonus it allows using only integer formatting, not float formatting, so hopefully it'll make the code smaller
<barafael[m]> Neat! That would be valid for all values of n I guess, so cool. Thanks!
<NickStevens[m]> This seems like a really good use for a fixed-point type. In other words store your actual value as an integer multiplied by 1000. So 341.222 would be stored in a u32 as 341222. Then when you go to display always put your decimal point 3 places from the right.
<NickStevens[m]> If there's not enough digits to fill the 3 places then you fill with 0's
<NickStevens[m]> This also has the advantage that you can check that your value fits within your fixed point assumptions easily by checking if `x <= 999999` and displaying `0f` or something like that to indicate an overflow
<NickStevens[m]> * an overflow (0f kind of looks like OF on a 7-segment display)
<dirbaio[m]> > Then when you go to display always put your decimal point 3 places from the right.
<dirbaio[m]> you have to round too, though. for example you want to display `345678` as `346.`
<dirbaio[m]> so it's not as simple as "convert the integer to string, then keep top 3 digits"
<NickStevens[m]> Depending on the data you're already losing precision - why not just take a floor instead of a true rounding?
<NickStevens[m]> * losing precision by limiting to 4 characters - why
<dirbaio[m]> because it increase max error from 0.5 to 1.0, and it makes the error be systematically in one direction vs randomly up/down
<dirbaio[m]> if you can, rounding is always better
<NickStevens[m]> dirbaio[m]: Citation needed πŸ˜‰
<NickStevens[m]> It really depends on what the data being displayed is and what level of precision is needed
<barafael[m]> "Rounding is always better"
<barafael[m]> - dirbaio
<dirbaio[m]> if you can round (ie if you don't have some super mega weird requirement that forces flooring), then you should round, yes
<NickStevens[m]> Except that rounding requires additional conditional checks and increases the amount of logic needed for this simple display. You are saying "you should always round", I am saying "it's okay to relax that requirement so long as you know the tradeoffs". These are both our opinions, there is no imperative "rounding is better" fact in this scenario.
<NickStevens[m]> So let's ask barafael more about the requirements of their application and then we'll know what tradeoffs are we can make
<NickStevens[m]> s/are//
<dirbaio[m]> "I can't round because I have no CPU cycles left for it" is a quite super mega weird requirement
<NickStevens[m]> I'm not understanding why you're digging in your heels so hard on this. Help me understand.
<dirbaio[m]> πŸ˜‚
<dirbaio[m]> if you're displaying some quantity to the user with limited digits, it's very reasonable to aim for minimum error possible
<dirbaio[m]> that requires rounding
<dirbaio[m]> virtually all libraries or languages that format floats for human consumption defaults to rounding
<dirbaio[m]> so when I wanted to help answer barafael's question I just assumed rounding was wanted
<dirbaio[m]> the format! code above in this chat was already doing rounding
<barafael[m]> Rounding is indeed wanted
<dirbaio[m]> and it's the common sense thing to do
<dirbaio[m]> I don't think it's worth starting an internet argument over this lol
<barafael[m]> And rounding is what caused me issues, because a number less than ten may still be rounded to ten
<NickStevens[m]> dirbaio[m]: This is an argument
<NickStevens[m]> dirbaio[m]: This is not
<NickStevens[m]> I was asking you to explain yourself with facts, not feelings. I have written code that uses the truncation method specifically because I was on an 8-bit micro and those cycles actually did matter.
<dirbaio[m]> i'm going to stop engaging, sorry. I don't think this argument is worth our time
<NickStevens[m]> So saying there's no reason to ever do this is wrong
<dirbaio[m]> I said IF YOU CAN ROUND
<dirbaio[m]> of course there are edge case situations where you can't
<dirbaio[m]> but these are rare
<barafael[m]> In my case, they fortunately don't - it's rare.
<NickStevens[m]> Why do you think this is an argument?
<NickStevens[m]> I really want to understand your point and I'm engaging with you
<dirbaio[m]> <dirbaio[m]> "if you can, rounding is always..." <- see, *if you can*
<dirbaio[m]> :)
<dirbaio[m]> so we agree!
<NickStevens[m]> Like I literally asked you to help me understand and you laughed
<dirbaio[m]> if you can't round, don't!
<dirbaio[m]> but you almost always can
<dirbaio[m]> and if you can, you should
<NickStevens[m]> But you should know what kind of rounding you're doing!
<dirbaio[m]> 🫠
<NickStevens[m]> Floor, true round, and ceiling are ALL rounding
<barafael[m]> In other news, I fixed my display woes (was on this channel a few weeks back) by switching to spi. Was a breeze to do in software, but I'll have to do a new board I guess. The shoe horned variant works though
<barafael[m]> I still don't understand what was going wrong with the i2c variant. Oh well...
<barafael[m]> Thanks for both of your help!
<NickStevens[m]> Thanks for sticking with us barafael! There's a lot of weirdness where human numbers and computer numbers meet, for sure
<NickStevens[m]> πŸ€¦β€β™‚οΈThe term is half-round not true-round, that's my bad
<dirbaio[m]> also often called just "rounding" :P
PeterHansen[m] has joined #rust-embedded
<PeterHansen[m]> For what it's worth, I happen to have exactly this situation (fixed point, formatting, choice of rounding), and in this particular case I chose not to waste my time rounding since it truly doesn't matter:... (full message at <https://catircservices.org/_matrix/media/v3/download/catircservices.org/GDicXcuTwuDTQwlNfficQtkn>)
<dirbaio[m]> then this function name is wrong? https://en.cppreference.com/w/c/numeric/math/round
<PeterHansen[m]> This is showing more digits than any one really cares about, but since it's a fairly sensitive device it will show changes rapidly. The exact value has no importance to anyone viewing it, but the fact it changes does, so I'm showing the 2 digits but truncating.
<PeterHansen[m]> And I did happen to use the nice little "fixed" crate with the I9F7 type in this case, to simplify life.
<NickStevens[m]> No, that is a common shortening of "half round" which is a very natural way for humans to round things. So it's often the default. But it's not the only way.
<dirbaio[m]> I know
<dirbaio[m]> but it's the most common way, hence it's the reasonable default when you want to display something with a limited number of digits
<NickStevens[m]> Then please stop jumping down my throat for suggesting that half-round isn't the only kind of round.