|
Hey, at least whoever wrote the number-to-words function did a good job though. It correctly handled a number in the trillions.
|
# ? Feb 13, 2022 21:10 |
|
|
# ? May 27, 2024 00:25 |
|
I'm from a country that uses whichever trillion scale you don't use and say the number-to-words function is garbage!
|
# ? Feb 14, 2022 00:10 |
|
TypeScript code:
|
# ? Feb 21, 2022 10:24 |
|
Bonfire Lit posted:
This malice, not stupidity,
|
# ? Feb 21, 2022 13:52 |
|
Bonfire Lit posted:
I dont know TypeScript what the gently caress is happening here
|
# ? Feb 21, 2022 13:53 |
|
D34THROW posted:I dont know TypeScript what the gently caress is happening here I don't know either. Seems to be some sort of validation function that can return NaN if a regex checks, otherwise return true. I guess the reason why is posted here is having a function that can return only two values true and NaN, and not using a boolean for that. It would made more sense to me to return null instead of NaN, or simply false. null being defined in database realms has "I dunno, man".
|
# ? Feb 21, 2022 14:04 |
|
It's just about the worst named function I've ever seen. What it's supposed to do depends heavily on someRegExp which I'm assuming is a constant. If it was something that checked whether something is a number I suppose it could be something to test whether a string can be parsed to a number, although who the hell knows why you'd return NaN if it doesn't.
|
# ? Feb 21, 2022 14:19 |
|
enki42 posted:It's just about the worst named function I've ever seen. What it's supposed to do depends heavily on someRegExp which I'm assuming is a constant. If it was something that checked whether something is a number I suppose it could be something to test whether a string can be parsed to a number, although who the hell knows why you'd return NaN if it doesn't. Because then it's not a number op couldn't be simpler
|
# ? Feb 21, 2022 14:22 |
|
I don't know how you write the signature for that return value in Typescript and not realize that you're doing something very, very wrong.
|
# ? Feb 21, 2022 14:25 |
|
It’s the sort of thing I’d write if I were quitting tomorrow and hated my coworkers.
|
# ? Feb 21, 2022 14:28 |
D34THROW posted:I dont know TypeScript what the gently caress is happening here it's bad enough that the language hands you NaNs occasionally, writing a function that does it intentionally is a war crime
|
|
# ? Feb 21, 2022 15:27 |
|
Bonfire Lit posted:
1. NaN coerces to false in boolean context. 2. This function is being called as a short circuit OR operation. 3. The input is a string representation in of a rational (fraction) that needs to be converted (evaled) into a floating-point value. 4. The purpose is to catch an integer divide by zero before evaling the string, to avoid a divide by zero exception and instead provide a reasonable (if imprecise) floating-point response.
|
# ? Feb 21, 2022 18:01 |
|
I imagine if you are writing that sort of function you're probably also playing fast and loose with JS == operator wherever that returned NaN shows up
|
# ? Feb 21, 2022 18:13 |
ExcessBLarg! posted:I'm not familiar with TypeScript either so the only way this makes sense to me is if these assumptions are true and it's being used in this context: NaN does coerce to false, but JS/TS don't freak out when you divide by zero, they return infinity, a special number that is sort of but not exactly like mathematical infinity, which is a reasonable if imprecise response to dividing by zero. feeding NaN into something that expects a number, however, will cause an error. e: which, idk, maybe you'd rather get an error than send infinity out into the world in this case, hard to say Jazerus fucked around with this message at 18:23 on Feb 21, 2022 |
|
# ? Feb 21, 2022 18:20 |
|
I'm not familiar with Typescript either, but I'm pretty sure the type signature means it's a union type so it returns either a number or a boolean. It's fine in that regard, apart from being horrible in all regards. I'm guessing it's written to check if it's a number and the caller does a check on != NaN, for some strange reason that probably involves lots of broth and many cooks.
|
# ? Feb 21, 2022 19:19 |
|
Ola posted:…check if it's a number and the caller does a check on != NaN, … Hahaha I bet it does exactly this lol
|
# ? Feb 21, 2022 19:41 |
|
Today I learned NaN is not a valid literal type in TypeScript, further confirming the excellent taste of its maintainers.
|
# ? Feb 21, 2022 20:09 |
|
NaN is in fact a Number
|
# ? Feb 21, 2022 20:47 |
|
Jazerus posted:it's bad enough that the language hands you NaNs occasionally, writing a function that does it intentionally is a war crime You'll be glad to hear then that the return value of that function is never used except in boolean context (i.e., if (checkValue(foo)) { do something })
|
# ? Feb 21, 2022 20:57 |
|
Bonfire Lit posted:You'll be glad to hear then that the return value of that function is never used except in boolean context (i.e., if (checkValue(foo)) { do something }) So kind of what I guess, only the other way around. Why, for the love of all that is holy, not if (someRegexp.test(input)) { do something } ?
|
# ? Feb 21, 2022 21:21 |
|
Beats me! I've elected not to check source control because I suspect if I do I'll just get salty at whoever wrote that and whoever reviewed it afterwards.
|
# ? Feb 21, 2022 21:29 |
Bonfire Lit posted:You'll be glad to hear then that the return value of that function is never used except in boolean context for now
|
|
# ? Feb 21, 2022 21:35 |
|
ExcessBLarg! posted:4. The purpose is to catch an integer divide by zero before evaling the string, to avoid a divide by zero exception and instead provide a reasonable (if imprecise) floating-point response.
|
# ? Feb 21, 2022 22:00 |
|
Bonfire Lit posted:Beats me! I've elected not to check source control because I suspect if I do I'll just get salty at whoever wrote that and whoever reviewed it afterwards. So this person is also in the habit of eval()-ing strings, you say?
|
# ? Feb 21, 2022 22:08 |
|
Always fun when you solve a problem on AWS by making a copy of the function that is not working, set it up the same, the code is the same, the permissions are the same and it works when the previous one you copied it from and should be identical throws errors with no message.
|
# ? Feb 21, 2022 23:10 |
|
Foxfire_ posted:Surprise! Javascript/typescript doesn't have integers Says you.
|
# ? Feb 22, 2022 00:56 |
|
Bonfire Lit posted:Beats me! I've elected not to check source control because I suspect if I do I'll just get salty at whoever wrote that and whoever reviewed it afterwards. You can just say it was you
|
# ? Feb 22, 2022 01:59 |
|
I did this on a javascript console. NaN?true:false; it returns false, so NaN evaluates to false, so thats why that function works. while NaN is not a boolean, evaluated in a boolean context it works like a false. this is C spirit working from inside javascript, convenient if tricky
|
# ? Feb 22, 2022 10:22 |
|
Tei posted:this is C spirit working from inside javascript, convenient if tricky
|
# ? Feb 22, 2022 10:25 |
|
Tei posted:I did this on a javascript console. It isn't in a boolean context though, it's in a union type context where it can be either a number or a boolean. Union types are cool and good in functional languages, but Typescript isn't one of those. NaN is extra super falsy in Javascript so you really wouldn't want to use it for anything. code:
|
# ? Feb 22, 2022 10:39 |
|
That's just NaN behaviour in ieee 754.
|
# ? Feb 22, 2022 11:00 |
|
How the hell is a NaN not strictly equal to NaN
|
# ? Feb 22, 2022 14:02 |
|
D34THROW posted:How the hell is a NaN not strictly equal to NaN How could it be? It holds a meaning outside its bit set.
|
# ? Feb 22, 2022 14:11 |
|
Ola posted:
:-O what the gently caress. I mean... null in databases is probably similar, but what the gently caress
|
# ? Feb 22, 2022 14:14 |
|
Tei posted::-O This is standard behavior for floats. Anything else would be against the spec and extremely wrong. What were you expecting?
|
# ? Feb 22, 2022 14:18 |
|
D34THROW posted:How the hell is a NaN not strictly equal to NaN First time, eh?
|
# ? Feb 22, 2022 14:22 |
|
Tei posted::-O It's NaN-defined behaviour.
|
# ? Feb 22, 2022 14:22 |
NaN by definition represents an unknowable value, so you have to assume that two NaN values are different. Usually SQL NULL represents the absence of a value, while NaN represents that a value is present but unknowable.
|
|
# ? Feb 22, 2022 14:32 |
|
leper khan posted:This is standard behavior for floats. Anything else would be against the spec and extremely wrong. What were you expecting? https://www.youtube.com/watch?v=6ZpaWOLjWx0 For it to explode comically, like in a old movie, when computers where still called "electronic brains".
|
# ? Feb 22, 2022 14:39 |
|
|
# ? May 27, 2024 00:25 |
|
Signaling NaNs are indeed also a thing, but not in JS.
|
# ? Feb 22, 2022 14:42 |