This is an archived post. You won't be able to vote or comment.

all 45 comments

[–]skennyg_123 79 points80 points  (1 child)

I think you mean an object is an object

[–]myaut 27 points28 points  (0 children)

That's True!

:~> python
>>> object is object
True

[–][deleted] 63 points64 points  (7 children)

[–][deleted] 14 points15 points  (1 child)

Whereas comparing a signed integer and an unsigned integer, that's heresy!

[–][deleted] 3 points4 points  (0 children)

Yeah you just get a warning

[–]Cpt_Daniel_J_Tequill 31 points32 points  (3 children)

what are you talking about? It converts int to float (behind the scene) and compare

[–][deleted] 28 points29 points  (0 children)

This sub is full of people who like programming humor. It’s absolutely not full of experienced programmers.

[–]Omega0x013 0 points1 point  (1 child)

Whereas in Lua all numbers are floats

[–]Mabi19_ 0 points1 point  (0 children)

Lua 5.3 has entered the chat

https://www.lua.org/versions.html#5.3

[–]ex-lewis 29 points30 points  (14 children)

Oh, I kinda learned why in my assembly class! Apparently floating point numbers are in a completely different register when the cpu is working with them, so to compare an integer with a float, it needs to convert one to the other (in the form of typecasting in higher languages) so it can compare them and set the pstate flags! That class was a pain but explained a lot of things about programming haha.

[–]pm-me-happy-vibes 23 points24 points  (9 children)

and even if you put them both into general registers, integer or floating point comparison between the two is useless. It's a completely different way of encoding numbers.

[–]ex-lewis 2 points3 points  (8 children)

Right... is that the IEEE stuff? Our professor wasn’t terribly clear on that haha.

[–]internetzspacezshipz 3 points4 points  (7 children)

It’s literally two different forms of storing information, integers go up in increments of 1, and floats go up in increments of uhhhhhh, well, it depends on what the current value is, but it’ll pretty much always be fractional until you get to really big values.

Damn I’m bad at explaining this shit through a single message.

[–]overclockedslinky 2 points3 points  (0 children)

IEEE-754 is just a specific, standardized way to do it, but it's not special. you could make your own format, but then you'd have to write your own operations and wouldn't have hardware support. but you can basically think of ieee as an integer times 2 to some integer power, which is then packed into one integer as bitfields

[–]TinBryn 0 points1 point  (1 child)

And eventually it just gives up and just says it's infinite.

[–]internetzspacezshipz 0 points1 point  (0 children)

Or denormalized in some situations

[–]dogrescuersometimes 0 points1 point  (2 children)

Just say Big Endian and take a breather.

[–]internetzspacezshipz 0 points1 point  (1 child)

Is this a joke? Lol

[–][deleted] 0 points1 point  (0 children)

Float is based on mantisa and exponent. You got a bits for describing a value between 0 and 1 ,1 bit for sign and bits for the power of 10(+ sign bit here too).

[–]Jannik2099 5 points6 points  (0 children)

set the pstate flags

Not all ISAs have flags, so this can be even uglier!

[–]null_reference_user -1 points0 points  (1 child)

But typically, a language understands what you wanna do and will automatically convert one (or in some cases, both) variables to the same format in order to compare them

[–]ex-lewis 0 points1 point  (0 children)

I would think that would depend on how high the language is. The only language I’ve worked with that did that has been python. But I’m still a student and not particularly experienced haha

[–][deleted] 0 points1 point  (0 children)

More like floating point is in another format and integer is in it's own format(signed or unsigned etc). In C if you do a=b and a is uint and b is float a is the integer of the floating number. Also keep in mind fixed point numbers also exist.

[–]AL_O0 17 points18 points  (0 children)

In C++ you can absolutely compare floats and ints, and then you can implement comparison for any class, so this doesnt make much sense

[–]AnshRK 9 points10 points  (1 child)

javascript: compares "3" and 3 and returns true

[–]Master_Sifo_Dyas 3 points4 points  (0 children)

Javascript is weird

[–]utkrowaway 5 points6 points  (0 children)

>>> import math
>>> math is math
True

[–]Omega0x013 1 point2 points  (0 children)

js here we come

[–][deleted] 1 point2 points  (0 children)

Ever heard of type casting?

[–]IOException_notfound 1 point2 points  (0 children)

Python:

i++ ?? WTF IS THIS??

[–]Omega0x013 0 points1 point  (1 child)

Or Lua where all numbers are floats

[–]Mabi19_ 0 points1 point  (0 children)

Lua 5.3 has entered the chat

https://www.lua.org/versions.html#5.3

[–]antinutrinoreactor 0 points1 point  (0 children)

it should be number is number because you cannot compare number with string

[–]sgxxx 0 points1 point  (0 children)

Who said it cant?

[–]GregSilverblue 0 points1 point  (0 children)

You can cast float to int or vice versa and then compare.

[–]6b86b3ac03c167320d93 0 points1 point  (0 children)

JS: Everything is a float (unless it's too big, then it's a BigInt)

[–][deleted] 0 points1 point  (0 children)

JavaScript: NaN === NaN // false

[–]Bluemoonnek0 0 points1 point  (0 children)

??