FixType()

Propose new features and changes
User avatar
Coiler
Posts: 114
Joined: 29 Nov 2020, 09:06

FixType()

Post by Coiler » 17 Mar 2021, 13:26

A built-in method or variable prefix to filter numerical strings into numerical values? Probably something like..

Code: Select all

FixType(val) => ( IsNumber(val) ? 1 * val : val )
Does something like this already exist? Some way to force values to decide what type they are?

I know this isn't normally necessary (which is amazing), but it would be nice to have when it comes up. In my case, I am storing file-parsed values for repeated use, so I wanted to prepare them for battle as much as possible.

User avatar
kczx3
Posts: 1640
Joined: 06 Oct 2015, 21:39

Re: FixType()

Post by kczx3 » 17 Mar 2021, 20:06

Can you not just wrap the variable in a call to Integer()?

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: FixType()

Post by swagfag » 18 Mar 2021, 06:00

Integer() would truncate floats. ud have to check if it IsInteger() and then cast to Integer(). then ud have to do the same with Float(), but doing that would be slightly slower than the multiplication i guess
Number.Call aka Number() could be a good contender for implementing what u want natively(casting numeric strings into pure numbers). it could perhaps also be made to handle the numeric strings for +/-inf, nan, -nan(ind) and denormalized numbers.
all in good time...

User avatar
Coiler
Posts: 114
Joined: 29 Nov 2020, 09:06

Re: FixType()

Post by Coiler » 19 Mar 2021, 10:59

Yeah, I was looking for something that could be used right after reading a value of unknown type from a text file, like in the case of a INI file. Based on the documentation, I assumed IsNumber() probably internally calls IsInteger() and/or IsFloat(), but that's just a guess. If I wanted to be as efficient as possible, I would internally register all of my INI values, including their types, which would tell me exactly how to load them or process them after. But since AHK doesn't discriminate against other types (in all of the situations I've tested), I'm doing it the lazy way and just loading them in as generic values, then taking a best guess with IsNumber().

The entire system was already working with pure strings, which I thought was pretty impressive. Most languages would throw a fit if you tried to multiply two strings.

But I figured one line of code at the beginning might save internal processing throughout the program. And there's always a chance that AHK may become more strict in how it deals with strings and numbers down the road. Especially with the road its currently traveling on.

User avatar
kczx3
Posts: 1640
Joined: 06 Oct 2015, 21:39

Re: FixType()

Post by kczx3 » 19 Mar 2021, 18:37

I’d say a slim to none chance

Post Reply

Return to “Wish List”