Do you have a good reason to use QXXPTOD instead of _LBCPYNV? Personally, I prefer the latter.

Here's a program of mine that converts from double to packed -- I imagine you can easily change it to convert the other way (but if you can't figure it out, let me know)

PGM
DCL VAR(&LILIAN) TYPE(*CHAR) LEN(4)
DCL VAR(&FLOAT) TYPE(*CHAR) LEN(8)
DCL VAR(&GREGOR) TYPE(*CHAR) LEN(23)
DCL VAR(&SECONDS) TYPE(*DEC) LEN(15 0)
DCL VAR(&CHARSEC) TYPE(*CHAR) LEN(15)

DCL VAR(&IATTRIB) TYPE(*CHAR) LEN(7)
DCL VAR(&OATTRIB) TYPE(*CHAR) LEN(7)

/* Get Current Local Time */

CALLPRC PRC(CEELOCT) PARM(&LILIAN +
&FLOAT +
&GREGOR +
*OMIT )

/* To convert the floating point to packed, we need +
to tell the _LBCPYNV builtin what the formats of +
the input and output parameters are. This is +
done via an "attributes" data structure. There +
will be one for the input and one for the output.+
+
In consists of the following fields: +
+
Pos Len Description +
--- --- ------------------------------------ +
1 1 Data type (x'01'=float, x'03=packed) +
2 2 Field length (and decpos) +
for float, this must be 4 or 8 +
for packed, pos 2=decpos, +
pos 3=total digits +
4 4 Reserved (should be binary zeroes) +
*/

CHGVAR VAR(%SST(&IATTRIB 1 1)) VALUE(X'01')
CHGVAR VAR(%BIN(&IATTRIB 2 2)) VALUE(8)
CHGVAR VAR(%BIN(&IATTRIB 4 4)) VALUE(0)

CHGVAR VAR(%SST(&OATTRIB 1 1)) VALUE(X'03')
CHGVAR VAR(%SST(&OATTRIB 2 1)) VALUE(X'00')
CHGVAR VAR(%SST(&OATTRIB 3 1)) VALUE(X'0F')
CHGVAR VAR(%BIN(&OATTRIB 4 4)) VALUE(0)

/* Call the _LBCPYNV MI builtin to convert from float +
to packed. */

CALLPRC PRC('_LBCPYNV') PARM(&SECONDS +
&OATTRIB +
&FLOAT +
&IATTRIB )


/* Create a message that tells what the results were: */

CHGVAR VAR(&CHARSEC) VALUE(&SECONDS)

SNDUSRMSG MSG('The time' *BCAT &GREGOR *BCAT +
'is' *BCAT &CHARSEC *BCAT 'seconds +
from 14 Oct 1582.')
ENDPGM

More info about this MI builtin can be found in the IBM i Information Center:
http://tinyurl.com/lbcpynv


On 2/14/2013 6:59 AM, paul.roy@xxxxxxx wrote:
Hello,

I would like to use C math functions in a CL program... but most of those
functions use doubles.. which are not supported in ILE CL...
so my idea was to use QXXPTOD do convert to a internal value passed to the
math function and then convert the result back to packed

this is just an example of what I would like to work in CL

pgm
DCL VAR(&A) TYPE(*DEC) LEN(15 5) value(300)
DCL VAR(&B) TYPE(*DEC) LEN(15 5) VALUE(400)
DCL VAR(&C) TYPE(*DEC) LEN(15 5) value(0)
dcl &dblA *char 8
dcl &dblB *char 8
dcl &dblC *char 8
DCL VAR(&DIG) TYPE(*INT) VALUE(15)
DCL VAR(&DEC) TYPE(*INT) VALUE(5)
/* convert Packed decimal to Double */
CALLPRC PRC(QXXPTOD) PARM((&A *BYREF) (&DIG *Byval) ( &DEC
*byval)) RTNVAL(&DBLA)
CALLPRC PRC(QXXPTOD) PARM((&B *BYREF) (&DIG *Byval) ( &DEC
*byval)) RTNVAL(&DBLB)
/* call a C library Math function */
CALLPRC PRC('hypot') PARM((&DBLA *BYVAL) (&DBLB *BYVAL))
RTNVAL(&DBLC)
/*convert Double to Packed decimal */
CALLPRC PRC(QXXDTOP) PARM((&C *byref) (&DIG *Byval) ( &DEC
*byval) (&DBLC *byval))
endpgm

I know there are other ways and other languages but I am just trying to
understand why this is not working in ILE CL.


thanks

Paul



This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2019 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].