[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference vaxaxp::vmsnotes

Title:VAX and Alpha VMS
Notice:This is a new VMSnotes, please read note 2.1
Moderator:VAXAXP::BERNARDO
Created:Wed Jan 22 1997
Last Modified:Fri Jun 06 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:703
Total number of notes:3722

343.0. "LIB$CVT_DX_DX negative D_FLOAT to QUADWORD rounding problem" by COMICS::EDWARDSN (Dulce et decorum est pro PDP program) Tue Mar 18 1997 05:01

O.k here's a little C hackette which I think demonstrates the problem,
I know that there were some problems with conversion of quadwords and 
rounding in VMS versions below 5.4 on VAX, but this is 7.1 VMS on AXP
compiled using DEC C 5.5-003 and it's not working too well.

It should be self-explanatory, but just in case you don't spot it 
straight away, for some reason, the negative rounding starts at 
some point between -0.25 and -0.26, in fact that seems to be true
all the way down. i.e. -1.26 become -2.0 and -1.25 is -1.0 etc.

I have a feeling that there will be certain banks rather interested
in the way in which overdrafts are going to be calculated on this 
basis.

Could it be time to escalate this one? I'll find out how burning it is.

Neil.

Here's the command file.

$ CREATE QTEST.C
#include <lib$routines.h>
#include <libdef.h>
#include <stdio.h>
#include <descrip.h>
#include <stdlib.h>

void gen_cvt ();
void other_way ();

void main (int argc, char *argv[])
{

    long    quad[2];
    double  dbl;
    double  atof();

    if (argc != 2)
    {
        printf ("usage: qtest <double>\n");
        exit (42);
    }
    quad[0] = 0;
    quad[1] = 0;

    dbl = atof (argv[1]);

    gen_cvt (dbl, quad);

    printf ("double = %f, quad[1]=%d, quad[0]=%d\n",dbl,quad[1],quad[0]);

    dbl = 99999.0;
    other_way (&dbl, quad);

    printf ("double = %f\n", dbl);
}
void other_way (double *dbl, char *p_quad)
{
    int     retval;
    unsigned short  returned_dst_len;
    struct dsc$descriptor_s src_desc;
    struct dsc$descriptor_s dst_desc;

    src_desc.dsc$a_pointer = (char *) dbl;
    src_desc.dsc$b_class = DSC$K_CLASS_S;
    src_desc.dsc$b_dtype = DSC$K_DTYPE_D;
    src_desc.dsc$w_length = sizeof (double);

    dst_desc.dsc$a_pointer = &p_quad[0];
    dst_desc.dsc$b_class = DSC$K_CLASS_S;
    dst_desc.dsc$b_dtype = DSC$K_DTYPE_Q;
    dst_desc.dsc$w_length = 2 * sizeof (long);

    retval = lib$cvt_dx_dx (&dst_desc, &src_desc, &returned_dst_len);
    printf ("%d\n", retval);
    if (!(retval &1))
    {
        printf ("error in lib$cvt_dx_dx (%d)\n", retval);
        exit (42);
    }
}

void gen_cvt (double dbl, char *p_quad)
{
    int     retval;
    unsigned short  returned_dst_len;
    struct dsc$descriptor_s src_desc;
    struct dsc$descriptor_s dst_desc;

    src_desc.dsc$a_pointer = (char *) &dbl;
    src_desc.dsc$b_class = DSC$K_CLASS_S;
    src_desc.dsc$b_dtype = DSC$K_DTYPE_D;
    src_desc.dsc$w_length = sizeof (double);

    dst_desc.dsc$a_pointer = &p_quad[0];
    dst_desc.dsc$b_class = DSC$K_CLASS_S;
    dst_desc.dsc$b_dtype = DSC$K_DTYPE_Q;
    dst_desc.dsc$w_length = 2 * sizeof (long);

    retval = lib$cvt_dx_dx (&src_desc, &dst_desc, &returned_dst_len);
    printf ("%d\n", retval);
    if (!(retval &1))
    {
        printf ("error in lib$cvt_dx_dx (%d)\n", retval);
        exit (42);
    }
}

$ CC/FLOAT=D QTEST
$ LINK QTEST
$ QTEST :== $"''f$environment("DEFAULT")'QTEST"
$ QTEST 1.0
$ QTEST 0.5
$ QTEST 0.4999
$ QTEST 0.0
$ QTEST -0.5
$ QTEST -0.499
$ QTEST -0.25
$ QTEST -0.26
$ QTEST -1.25
$ QTEST -1.26
T.RTitleUserPersonal
Name
DateLines
343.1COMEUP::SIMMONDSloose canonTue Mar 18 1997 20:225
    Re: .0
    Better IPMT it.. there seems to be a problem with the BLISS generated
    code for the cvtrdq Builtin.
    
    John.
343.1COMEUP::SIMMONDSloose canonWed Mar 19 1997 02:345
    Re: .0
    Better IPMT it.. there seems to be a misteak in the rounding method
    (from a glance at the source)
    
    John.
343.2for the IPMT..COMEUP::SIMMONDSloose canonThu Mar 20 1997 01:466
    Re: .0,.1
    
    In case it helps, the bogus method appears in the listing file for the
    OpenVMS Alpha Version V6.2 LIBRTL module LIB$CVTDXDX, lines 2733..2794
    
    John.
343.3Here or EVMS-RAVEN QAR?COMEUP::SIMMONDSloose canonSat Mar 22 1997 22:034
    Is it of any use to put a suggestion to the Maintainer here ?  (I have
    a couple of ways of fixing this bug to put..)
    
    John.
343.4ZIMBRA::BERNARDODave Bernardo, VMS EngineeringSat Mar 22 1997 22:533
    
    QAR it.
    
343.5SSPADE::GRECOMon Mar 24 1997 14:324
    I've received the QAR and I'm looking into in now.
    
    Frank
    LIBRTL
343.6not mine..COMEUP::SIMMONDSloose canonMon Mar 24 1997 21:050
343.7QAR: EVMS-Raven#00933COMEUP::SIMMONDSloose canonTue Mar 25 1997 01:470
343.8spr_vms_v5SSPADE::GRECOTue Mar 25 1997 09:154
    A QAR was entered in the spr_vms_v5 database #06133 with the
    same problem.  Thanks for your help.
    
    Frank