Thursday 26 August 2021

An undocumented function in Priority - ATOR

There have been times, especially when I am programming interfaces that read external files and turn them into Priority data, that I wish that there was an Ascii2Real function, presumably ATOR, in the same way that there is an Ascii2Integer function (ATOI) and an Integer2Ascii function (ITOA). We have RTOA but no ATOR.

I've overcome this in the past by writing a subroutine that receives a string holding a real number (:QUANT) and returns a real number (:RQUANT).

SUB 879; :RQUANT = :TT = 0E9; SELECT STRPIECE (:QUANT, '.', 1, 1) INTO :TMP FROM DUMMY; :RQUANT = ATOI (:TMP) + 0.00000; SELECT STRPIECE (:QUANT ,'.', 2, 1) INTO :TMP FROM DUMMY; GOTO 102 WHERE :TMP = ''; /* This is the decimal part of the number. Figure out what the divisor has to be by the length of the number: e.g. num=3, div=1; num=30104, div = 5 */ :TT = 0.00000 + ATOI (:TMP); :DIV = 1; :I = 0; :LEN = STRLEN (:TMP); LABEL 101; :DIV = :DIV * 10; :I = :I + 1; LOOP 101 WHERE :I < :LEN; :RQUANT = :RQUANT + (:TT / :DIV); LABEL 102; RETURN;
Whilst this code works, I would prefer a predefined function in Priority. Today I was looking at a very old program that I did not write and saw the use of the ATOR function! As I know that this old program has correct syntax - and is used at least ten times a day - I felt fairly safe in replacing my subroutine with a simple function call, :RQUANT = ATOR (:QUANT). I also checked the syntax in WINDBI; lo and behold, this function turns a string like '3.1234' into a real number with six digits of accuracy, 3.123400.

Why would this useful function be undocumented, especially as it has existed in Priority since 2006? I won't even try to guess.

No comments:

Post a Comment