Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to convert float to string in TAL

249 views
Skip to first unread message

Afiz S

unread,
Mar 26, 2014, 2:38:32 AM3/26/14
to
Hi All,

Is there any GPC to convert fix to string. NUMOUT/NUMIN is used to convert INT to string and STRING to INT.

Thanks,
Afiz

Keith Dick

unread,
Mar 26, 2014, 6:11:59 AM3/26/14
to
The FORMATCONVERTX and FORMATDATAX procedures are the only ones I can remember that can be used by TAL programs for floating point conversion. If you are writing in C, C++, FORTRAN, or Java, there are language-defined ways for floating point conversion. In C it is in scanf or printf format strings (and their relatives like sprintf, etc.). In C++, you can use the C functions or the automatic conversion to or from strings. In FORTRAN it is a FORMAT statement's field conversion specifications. I don't know Java well enough to know how the conversion works without looking at the Java documentation, but floating point is supported. NonStop COBOL does not have support for floating point.

Afiz S

unread,
Mar 26, 2014, 7:41:22 AM3/26/14
to
Thanks Keith,

I will try to use both the GPC in TAL program.

Robert Hutchings

unread,
Mar 26, 2014, 6:17:28 PM3/26/14
to
Check the various TAL manuals. There are numerous $xxxx built-in functions (like $MAX, $IFIX, etc) that can upcast/downcast variables.

Afiz S

unread,
Mar 27, 2014, 6:46:05 AM3/27/14
to
On Thursday, March 27, 2014 3:47:28 AM UTC+5:30, Robert Hutchings wrote:
> Check the various TAL manuals. There are numerous $xxxx built-in functions (like $MAX, $IFIX, etc) that can upcast/downcast variables.

Robert,

$XXXX built-in-functions are rounding of the fixed to int, but I wanted to have complete floating number in my program.

Robert Hutchings

unread,
Mar 27, 2014, 9:43:12 AM3/27/14
to
Hi Afiz...

OK, I will see what I can find out from the TAL (and other) manuals.

Robert Hutchings

unread,
Mar 27, 2014, 10:11:02 AM3/27/14
to
Would this work....?


FIXED(3) f := 77.777F;

INT i := $FIXI(f);

STRING .s := i '<<' 1;

Keith Dick

unread,
Mar 27, 2014, 12:46:48 PM3/27/14
to
In his original post, Afiz said he wanted to convert between string and float, like NUMIN and NUMOUT convert between string and int. None of these address that.

The only procedures I know of that do what he is asking about are FORMATCONVERTX and FORMATDATAX. They are kind of complex general-purpose formatting procedures and so are not as simple to use as a NUMIN and NUMOUT equivalent for floating point would be, but I think they are the only procedures directly usable from TAL for doing such conversion of floating point values. C, C++, FORTRAN, and Java have language-defined ways for floating point input/output that are much easier to use.

You can easily call between TAL and C, but to use the C I/O functions, even sprintf() and sscanf() that work to and from strings, I believe the main program has to be C or the TAL program has to be using the CRE, so I didn't suggest writing C functions to do the conversion and calling them from the TAL. If the TAL program already is using the CRE, maybe calling a C function to do the conversion would be a good answer. If the TAL program is not already using the CRE, either converting it to use the CRE or converting it to work with a C main() can be a fair amount of work, depending on how much the TAL program uses features that have to be converted, so doing the float/string conversions via a C function probably isn't a good answer in that case.

Robert Hutchings

unread,
Mar 27, 2014, 1:05:34 PM3/27/14
to
Yes, I think calling a C program that does the conversion would be a "cleaner" way to do this.

Afiz...look at the TAL or C or Guardian Programmer Guide...there should be info on how to call a C function from TAL.

Look at printf, fprintf, etc, for info on how to print/convert a floating-point value to a string or char value.

Robert Hutchings

unread,
Mar 27, 2014, 1:36:14 PM3/27/14
to
TAL Code C Code
#include <stdioh> nolist
INT status := 0;
INT .EXT array[0:4]; _tal void TALMAIN ( void );
INT PROC cfunc (a) short CFUNC (short *num)
LANGUAGE C; {
INT .EXT a; printf("num B4=%d\n",*num);
EXTERNAL; num[0] = 10;
printf("num AF=%d\n",*num);
PROC talmain; return 1;
BEGIN }
array[2] := 2;
status := main () /* C MAIN routine */
cfunc (array); {
END; TALMAIN ();
}

Keith Dick

unread,
Mar 27, 2014, 2:37:54 PM3/27/14
to
If I recall correctly, the TAL Programming Guide probably has the best coverage of how to call C from TAL.

However, as I said, unless the TAL program is already set up to use the CRE, the task of converting it to use CRE probably is more work than it is worth just to avoid the little bit of complexity in using FORMATCONVERTX/FORMATDATAX.

Warren M

unread,
Apr 6, 2014, 9:52:54 AM4/6/14
to
On Wednesday, March 26, 2014 2:38:32 AM UTC-4, Afiz S wrote:
> Hi All, Is there any GPC to convert fix to string. NUMOUT/NUMIN is used to convert INT to string and STRING to INT. Thanks, Afiz

$ASCIITOFIXED and $FIXEDTOASCII builtins will do this.

Description can be found in the pTAL Conversion Guide.
http://h30163.www3.hp.com/NTL/view/?id=090015ea8009c29b&p=280-2bf/090015ea8009c29b/TPCONTNT.pdf&toc=y

In spite of the title, both are available in TAL (D40 or later). They replace the original TNS CAQ and CQA code statements.
0 new messages