There have been multiple accounts created with the sole purpose of posting advertisement posts or replies containing unsolicited advertising.

Accounts which solely post advertisements, or persistently post them may be terminated.

programmer_humor

This magazine is from a federated server and may be incomplete. Browse more on the original instance.

jjjalljs , in 0.30000000000000004

Can someone ELI5 why 0.1 + 0.2 fails, but 1+2 doesn’t? There’s probably a reason you don’t represent the decimal portion like you do integers, but I’m tired and not very mathy on a good day.

ShortFuse ,

I just recently worked on fixed point 8.8 and basically the way fractional values work, you take an integer and say that integer is then divided by another one. So you represent the number in question with two numbers not one. 0.3 can be presented in a number of ways, like 30 % 10, or 6 % 20.

The problem is the way 0.1 is represented and 0.2 represented don’t jive when you add them, so the compiler makes a fractional representation of 0.3 based on how 0.1 and 0.2 were expressed that just comes out weird.

That’s also why 0.3 + 0.3 is fine. When you wrote 0.3, the compiler/runtime already knew how to express 0.3 without rounding errors.

zlatko ,

Sure -> I’m not smart enough to explain it like you’re five, but maybe 12 or so would work?


The problem

The problem here is that you’re not adding 1 + 2, or 0.1 + 0.2. You’re converting those to binary (because computers talk binary), then you’re adding binary numbers, and converting the result back. And the error happens at this conversion step. Let’s take it slow, one thing at a time.


decimal vs binary

See, if you are looking at decimal numbers, it’s kinda like this:

357 => 7 * 1 + 5 * 10 + 3 * 100. That sequence, from right to left, would be 1, 10, 100, … as you go from right to left, you keep multiplying that by 10.

Binary is similar, except it’s not 1, 10, 100, 1000 but rather 1, 2, 4, 8, 16 -> multiply by 2 instead of 10. So for example:

00101101 => right to left => 1 * 1 + 0 * 2 + 1 * 4 + 1 * 8 + 0 * 16 + 1 * 32 + 0 * 64 + 0 * 128 => 45

The numbers 0, 1, 2, 3…9 we call digits (since we can represent each of them with one digit). And the binary “numbers” 0 and 1 we call bits.

You can look up more at simple wikipedia links above probably.


bits and bytes

We usually “align” these so that we fill with zeroes on the left until some sane width, which we don’t do in decimal.

132 is 132, right? But what if someone told you to write number 132 with 5 digits? We can just add zeroes. So call, “padding”.

00132 - > it’s the same as 132.

In computers, we often “align” things to 8 bits - or 8 places. Let’s say you have 5 - > 1001 in binary. To align it to 8 bits, we would add zeroes on the left, and write:

00001001 -> 1001 -> decimal 5.

Instead of, say, 100110, you would padd it to 8 bits, you can add two zeroes to left: 00100110.

Think of it as a thousands separator - we would not write down a million dollars like this: $1000000. We would more frequently write it down like this: $1,000,000, right? (Europe and America do things differently with thousands- and fractions- separators, so 1,000.00 vs 1.000,00. Don’t ask me why.)

So we group groups of three numbers usually, to have it easier to read large numbers.

E.g. 8487173209478 is hard to read, but 8 487 173 209 478 is simpler to see, it’s eight and a half trillion, right?

With binary, we group things into 8 bits - we call that “byte”. So we would often write this:

01000101010001001010101010001101

like this:

01000101 01000100 10101010 10001101

I will try to be using either 4 or 8 bits from now on, for binary.


which system are we in?

As a tangential side note, we sometimes add “b” or “d” in front of numbers, that way we know if it’s decimal or binary. E.g. is 100 binary or decimal?

b100 vs d100 makes it easier. Although, we almost never use the d, but we do mark other systems that we use: b for binary, o for octal (system with 8 digits), h for hexadecimal (16 digits).

Anyway.


Conversion

To convert numbers to binary, we’d take chunks out of it, write down the bit. Example:

13 -> ?

What we want to do is take chunks out of that 13 that we can write down in binary until nothing’s left.

We go from the biggest binary value and substract it, then go to next and next until we get that 13 down to zero. Binary values are 1, 2, 4, 8, 16, 32, … (and we write them down as b0001, b0010, b0100, b1000, … with more zeroes on the left.)

  • the biggest of those that fit into 13 seems to be 8, or 1000. So let’s start there. Our binary numbers so far: 1000 And we have 13 - 8 = 5 left to deal with.
  • The biggest binary to fit into 5 is 4 (b0100). Our binary so far: b1000 + b0100 And our decimal leftover: 5 - 4 = 1.
  • The biggest binary to fit into 1 is 1 (b0001). So binary: b1000 + b0100 + b0001 And decimal: 1 - 1 = 0.

So in the endl, we have to add these binary numbers:

` 1000 0100

+0001
b1101
`

So decimal 13 we write as 1101 in binary.


Fractions

So far, so good, right? Let’s go to fractions now. It’s very similar, but we split parts before and after the dot.

E.g. 43.976 =>

  • the part before the dot (whole numbers part) -> 1 * 3 + 10 * 4 = > 13
  • the part after it (fractional part) -> 0.1 * 9 + 0.01 * 7 + 0.001 * 6
    Or, we could write it as: 9 / 10 + 7 / 100 + 6 / 1000.

Just note that we started already with 10 on the fractional part, not with 1 (so it’s 1/10, 1/100, 1/1000…)

The decimal part is similar, except instead of multiplying by 10, you divide by 10. It would be similar with binary: 1/2, 1/4, 1/8. Let’s try something:

b0101.0110 ->

  • whole number part: 1 * 1 + 2 * 0 + 4 * 1 + 8 * 0 (5)
  • fractional part -> 0 / 2 + 1 / 4 + 1 / 8 + 0 / 16 -> 0.375.

So b0101.0110 (in binary) would be 5.375 in decimal.


Converting with fractions

Now, let’s convert 2.5 into binary, shall we?

First we take the whole part: 2. The biggest binary that fits is 2 (b0010). Now the fractional part, 0.5. What’s the biggest fraction we can write down? What are all of them?

If you remember, it’s 1/2, 1/4, 1/8, 1/16… or in other words, 0.5, 0.25, 0.125, 0.0625…

So 0.5 would be binary 1/2, or b0.1000

And finally, 2.5 in decimal => b0010.1000

Let’s try another one:

13.625

  • Whole number part is 13 -> we already have it above, it’s b1101.
  • Fractional part: 0.625. The bigest fraction that fits is 0.5, or 1/2, or b0.1. We have then 0.625 - 0.5 = 0.125 left. The next fraction that fits is 1/8 (0.125), written as b0.0010.

Together with b0.1000 above, it’s b0.1010 So the final number is:

b1101.1010

Get it? Try a few more:

4.125, 9.0625, 13.75.

Now, all these conversions so far, align very nicely. But what when they do not?


Finaly, our problem.

1 + 2 = 3. In binary, let’s padd it to 4 bits: 1 -> the biggest binary that fits is b0010. 2 -> the biggest thing that fits is b0010.

b0001 + b0010 = b0011.

If we convert the result back: b0011 -> to decimal, we get 3.

Okay? Good.


Now let’s try 0.1 + 0.2.

  • decimal 0.1 => 1 / 10.

How do we get it in binary? Let’s find the biggest fraction that fits: 1/16, or 0.0625, or b0.0001 What’s left is 0.1 - 0.0625 = 0.0375. Next binary that fits: 1/32 or 0.03125 or b0.00001. We’re left with 0.00625. Next binary that fits is 1/256
… etc etc until we get to:

decimal 0.1 = b0.0001100110

We can do the same with 0.2 -> b0.0011001100.

Now, let’s add those two:

` b0.0001 1001 10

+b0.0011 0011 00
b0.0100 1100 10
`

Right? So far so good. Now, if we go back to decimal, it should come out to 0.3.

So let’s try it: 0/2+1/4+0/8+0/16+1/32+1/64+0/128+0/256+1/512+0/1024 => 0.298828125

WHAAAT?

Hazzia ,

I am disgusted on a such a level that a part of me so deep in my soul I didn’t know it existed is shaking right now. I mean, I’m familiar with computer functional technicalities altering expected results so I don’t know why this is my reaction, but it is and I hate it.

JackbyDev ,

We use a system for representing decimal numbers that trades off precision for speed and less storage space. Integer numbers don’t need to use that system.

Jpwanabe , in NaN Cat wallpaper [artist unknown]

Would love a higher rez then this so I can use it as a wall paper.

h_a_r_u_k_i , in Easy peasy
@h_a_r_u_k_i@programming.dev avatar

From my personal experience, AWS is extremely powerful (especially on security and networking). If you cross the learning curve, and know automation or Infrastructure as Code (e.g. Terraform) then it’s fast and easy to build almost any architecture.

But yes, it’s overkill for a simple website or a simple setup (if one is not familiar with AWS).

HubertManne , in Always commit

commit history was how I determined when to do the nightly and big weekend backups for a place I admined at one point. It was so annoying that we had one developer that liked to stay up way late and one that like to get up way the fuck early. Thank god they were all colocated at that point in time. If they had different timezones I would have just had to say eff it and let them have some poorer preformance.

TechieDamien , in NaN Cat wallpaper [artist unknown]

I can confirm that the cat is indeed not a number!

kambusha , in How the IT guys see the users

I do feel kinda bad for people. There’s very few jobs left where you don’t interact with a computer in some form or another, and the reality is that it’s not for everyone. Of course most people can benefit from using these “tools” but since they’re always upgrading, there keeps being something new to learn.

Personally, I love technology and playing around with new tech. However, if I’m great at sales or a lawyer or something, that’s where I add value, not in knowing how a computer works. So I can see how people get frustrated with it.

In the end it boils down to, pretty much everyone needs IT, but IT doesn’t need everyone. Think about it, when was the last time you worked at a company where an employee didn’t have a computer or need a computer for some task that they do?

Reddit_Is_Trash ,

Most technology problems would be solved by people having basic problem solving skills. I don’t feel bad for people who don’t “understand” technology while at the same time not putting in the slightest amount of effort to understand. Some people get thrown off by 2FA, and every single 2FA I’ve ever done has had easily followed instructions. People just don’t put in the effort.

NightAuthor ,

On the flip side are IT people who are apparently unable to RTFM. They try 15,000 solutions that logically make sense, exhaust logical options and start doing random shit that’s got almost no chance of working, but never stop to just check the docs.

LufyCZ ,

Yea coz that’s boring and for nerds

NightAuthor ,

Personally, I usually try something before going to docs. Sometimes I exhaust all ideas I have before going to the docs. But I never just do random shit until I’ve tried everything that makes sense, read the docs, and asked around the internet (maybe try random stuff while waiting for replies online)

LufyCZ ,

I was mostly kidding, though it depends on the problem itself - if I need an explanation for a function argument, no point testing shit if the docs answer it in 15 seconds. If it’s something more solution-y, I might do some testing before consulting the papers

pinkdrunkenelephants ,

Everyone who uses a computer has a responsibility to understand the basics of how it works because computer usage is so ubiquitous to daily life, and that’s true regardless of your field.

Dass93 ,

I have worked(as pedagog and construction) with people that doesn’t give a sit about IT. But are forced to it, and it’s just to document they’re work to bosses ex. So they just do what is needed and if there is a problem it’s not they’re respons to get it working, this must be the guy/lady that forced them to it, BUT they have zero sense to solve it problems.

CyberDragonCore , in NaN Cat wallpaper [artist unknown]
@CyberDragonCore@programming.dev avatar

cute.

corrupts_absolutely , in How the IT guys see the users

the meme itself is from the times when both aliens and cavemen were ever present on earth

Getallen ,

Mexico presenting aliens while politicians are the cavemen

Swiggles , in incoming

Now do html mail!

FooBarrington ,

There is actually an approach which makes this reasonably easy: mjml.io

Swiggles ,

That’s actually cool. I have to remember it next time I have to deal with html mail.

FooBarrington ,

I’ll pray for you that it doesn’t come to that!

greembow , in Imagine

Imagine: Ubuntu Pro. Oh wait. they sold out already.

Amends1782 ,

Kinda a shit take. Canonical is very generous with licensing. They give you 5 free personal licenses per account AND they license per physical host which is practically unheard of now. Like everything is per VM or container or CPUs or sockets etc now. One pro license on an ESXi host could have hundreds of VMs and Canonical is OK with that.

Source: I work with and use ubuntu pro. Canonical’s alright in my book. More than I can say for the RHEL team

greembow ,

I agree with you! Canonical’s licensing is the best in the business. I like and use Ubuntu pro at work and use it with my homelab. I just don’t love the ads in the terminal.

lambalicious , in Markdown everywhere

Eh, while Markdown is nice I think Dokuwiki’s syntax is infinitively better for any kind of text that ends up involving programming code. It also has a header syntax that makes sense, albeit rather cumbersome. And it also makes a proper distinction between italics and underline which are two different, standard typographical effects and not the same thing as Markdown seems to believe; and between ordered and unordered lists (let alone nested lists).

Just about the only bad thing is I haven’t been able to find an editor that supports it. Probably because, to my knowledge, no self-standing / independent renderer exists for it (the parser and renderer seem to be tightly integrated into the content manager).

timbuck2themoon ,

It’s funny- I use dokuwiki but my only gripe is I wish it was just standard markdown.

TigrisMorte , in My poor RAM...

It isn't to save RAM the you should use the website over the app for.

xusontha OP , (edited )
QuazarOmega ,

I think they’re referring to the fact that often installed apps will be able to mine more of your data

Zeragamba ,
@Zeragamba@lemmy.ca avatar

that sounds like just plain old paranoia and fear mongering

QuazarOmega ,

I wish it were… But well, I guess I’ve been exposed to far too many privacy news articles, so I’m now paranoid too (with good reason)

fu ,

@Zeragamba @QuazarOmega just because something is paranoia doesn't mean it isn't true. Whenever I turn on the DuckDuckGo "VPN" to stop tracking by third party apps, I'm amazed at how many request are happening from apps I hardly use and many I don't expect (though I should know that something can still be open source Free Software and that the open code contains surveillance capitalsm tracking in order to fund the project)

chickenf622 , in OC: Me since Bun 1.0.0

I’m looking at it with optimism for a new build tool. I just need Sass/CSS compilation and I’ll give it a whirl.

starman OP ,
@starman@programming.dev avatar

It’s on the roadmap

demesisx , in Which side are you? Javascript or Typescript
@demesisx@infosec.pub avatar

I’m idealistically/philosophically committed to a Purescript Halogen front end with a Haskell Servant backend, biatch. Maybe someday I’ll get WASM in there. One thing I will not do is use TS or JS.

Si_sierra , in Planning is for the weak

Their planning is for the week

  • All
  • Subscribed
  • Moderated
  • Favorites
  • [email protected]
  • random
  • lifeLocal
  • goranko
  • All magazines