Math functions not returning empty string on non-numeric input

Get help with using AutoHotkey and its commands and hotkeys
hobboy
Posts: 41
Joined: 05 Jan 2016, 09:59

Math functions not returning empty string on non-numeric input

12 Nov 2016, 21:32

The maths documentation states that these functions generally return empty strings if the input is non-numeric. However I've found this doesn't seem to be the case:

Code: Select all

#NoEnv
#Warn
#SingleInstance Force

str := "asdf"
FileAppend % "str=" str "`n",*
FileAppend % "Abs=" Abs(str) "`n",*
FileAppend % "Ceil=" Ceil(str) "`n",*
FileAppend % "Exp=" Exp(str) "`n",*
FileAppend % "Floor=" Floor(str) "`n",*
FileAppend % "Log=" Log(str) "`n",*
FileAppend % "Ln=" Ln(str) "`n",*
FileAppend % "Mod=" Mod(str,str) "`n",*
FileAppend % "Round=" Round(str) "`n",*
FileAppend % "Sqrt=" Sqrt(str) "`n",*

FileAppend % "Sin=" Sin(str) "`n",*
FileAppend % "Cos=" Cos(str) "`n",*
FileAppend % "Tan=" Tan(str) "`n",*
FileAppend % "ASin=" ASin(str) "`n",*
FileAppend % "ACos=" ACos(str) "`n",*
FileAppend % "ATan=" ATan(str) "`n",*
gives the output

Code: Select all

str=asdf
Abs=
Ceil=0
Exp=1.000000
Floor=0
Log=-1.#INF00
Ln=-1.#INF00
Mod=
Round=0
Sqrt=0.000000
Sin=0.000000
Cos=1.000000
Tan=0.000000
ASin=0.000000
ACos=1.570796
ATan=0.000000
It looks like a string generally gets treated as zero and returns a value based on that. Should the note at the top of the documentation be changed?
lexikos
Posts: 6483
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: Math functions not returning empty string on non-numeric input

14 Nov 2016, 04:04

With v2.0-a076 (and some earlier), all results are blank.

I thought maybe that was erroneously copied over from the v2 documentation, but no, it's been there from the beginning. (Originally it was on the Functions page.)

I've confirmed your results on v1.0.48.05 as well, so it seems the documentation has always been wrong. Since it's been that way for so long, it's probably better to fix the documentation for v1 than to change the behaviour. There are scripts which rely on the current behaviour.

Return to “Ask For Help”

Who is online

Users browsing this forum: DannyhelMont, Google [Bot] and 139 guests