Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
ddephor44465yOh, fun with number systems...
I remember scripts failing on 01.01.2008 because someone used some numeric constants with 0-prefix for years in the date calculation.
That was fun. -
@irene Because that's how decimal works and nobody in their right mind thinks that you can't put zeroes in front of a number
-
joas18915y0-prefixed octal literal have been deprecated in JavaScript. The syntax error only occurs in strict mode for backwards compability.
-
@irene Not only do decimal numbers work that way, all numbers in positional numeral systems with a zero work exactly like that
-
@12bitfloat What languages are affected by this? I agree that a leading zero shouldn't be changing the number base. It is very common to prefix numbers with leading zeros.
-
@irene That's how this sorta number system is defined. 00042 is a completely valid number, exactly like 0.42000 is a valid number
-
@irene Yes. Are you honestly in defense of this retarded ass design flaw? 0c42 is more concise and more consistent
-
@irene What about trailing zeroes for decimals like 0.42000. Surely they're not valid either?
-
joas18915yDid I understand this conversation right?
@12bitfloat thinks that 042 shouldn't be an octal representation in any language but resolve to an integer instead (042 == 42) and octal should be prefixed with other characters than numbers, like 0c42.
@irene thinks that 042 shouldn't be a valid number in any base because same integer shouldn't have multiple representations (042 != 42).
If I understood correctly, I must agree with @irene. -
@joas Not that it shouldn't be. It *is* a valid number. And it shouldn't be interpreted as octal but simply as decimal. Sometimes you want to zeropad numbers e.g. in matrix calculations so it lines up nicely. That's how I discovered this in the first place because my math functions returned the wrong results. 042 is a valid decimal number and there's absolutely no reason you shouldn't be able to use it as an integer literal
-
I think the bigger lament here is not the leading zero. It is really that a leading zero can introduce a bug by silently changing the base of a number. Annoying as fuck when trying to debug.
-
Project Euler should know better then:
https://projecteuler.net/problem=11
Has leading zeros on this problem. I wonder how many people have tried to solve this problem and didn't realize the leading zeros were turning numbers into octal.
Out of curiosity, does anyone actually use octal numbers for anything? I don't think I ever used octal for anything but PLC programming 20 years ago. And that was very limited as well. Some PLCs used octal addresses for things.
Related Rants
Fuck whoever invented octal literals with just a zero prefix. 042 should never not equal 42. How hard is it to have 0x42 for hex, 0b11 for binary and 0c42 for octal
rant
fuck
php
radix
javascript