Page 1 of 1

functions interpreting non-numeric strings as 0

Posted: 20 Aug 2018, 15:30
by jeeswg
- Certain functions appear to be interpreting non-numeric strings as 0

Code: Select all

q:: ;non-number interpreted as 0 (a blank string is the expected output)
MsgBox, % Round(3.5, "a") ;4
MsgBox, % InStr("tttt", "t", 0, "a") ;4
MsgBox, % StrReplace("tttt", "t", "r",, "a") ;tttt
return
- (I was working on some custom AHK functions in C++, and wanted to see how the built-in functions identified non-numeric strings in parameters that aren't the 1st parameter, but it appears that they don't currently do this!)
- (For some functions, interpreting a non-numeric string as 0 will give a blank string by coincidence.)

Re: functions interpreting non-numeric strings as 0

Posted: 20 Aug 2018, 16:00
by Flipeador
Also some AHKv2 functions do not throw exceptions. :shock: Although coming from v1 nothing surprises me.

Re: functions interpreting non-numeric strings as 0

Posted: 20 Aug 2018, 16:54
by Helgef
It is a bug, in your code, you are not using the functions as documented. The parameters are documented as numbers. Unless there is any documentation stating that parameters are verified, this is not a bug in the program, but rather a limitation of the implementation, or a design choice if you like. It is not limited to functions.

Hopefully this will cause exceptions in v2, a blank string in v1 would be more suitable.

Cheers.