/* qfloor - largest integer not greater than x
* qround - nearest integer to x
*/
/* #include "mconf.h" */
#include "qhead.h"
extern QELT qone[], qhalf[];
#if WORDSIZE == 32
static QELT bmask[] = {
0 xffffffff,
0 xfffffffe,
0 xfffffffc,
0 xfffffff8,
0 xfffffff0,
0 xffffffe0,
0 xffffffc0,
0 xffffff80,
0 xffffff00,
0 xfffffe00,
0 xfffffc00,
0 xfffff800,
0 xfffff000,
0 xffffe000,
0 xffffc000,
0 xffff8000,
0 xffff0000,
0 xfffe0000,
0 xfffc0000,
0 xfff80000,
0 xfff00000,
0 xffe00000,
0 xffc00000,
0 xff800000,
0 xff000000,
0 xfe000000,
0 xfc000000,
0 xf8000000,
0 xf0000000,
0 xe0000000,
0 xc0000000,
0 x80000000,
0 x00000000
};
#else
static QELT bmask[] = {
0 xffff,
0 xfffe,
0 xfffc,
0 xfff8,
0 xfff0,
0 xffe0,
0 xffc0,
0 xff80,
0 xff00,
0 xfe00,
0 xfc00,
0 xf800,
0 xf000,
0 xe000,
0 xc000,
0 x8000,
0 x0000,
};
#endif
int qfloor( x, y )
QELT x[], y[];
{
QELT t[NQ];
register QELT *p;
long e;
qmov( x, t );
if ( t[1 ] == 0 )
{
qclear( y );
return (0 );
}
e = (long )t[1 ] - (EXPONE-1 );
if ( e <= 0 )
{
if ( t[0 ] != 0 )
{
qmov( qone, y );
qneg( y );
}
else
{
qclear( y );
}
return (0 );
}
/* number of bits to clear out */
e = NBITS - e;
qmov( t, y );
p = (QELT *)&y[NQ-1 ];
while ( e >= WORDSIZE )
{
*p-- = 0 ;
e -= WORDSIZE;
}
/* clear the remaining bits */
*p &= bmask[e];
/* truncate negatives toward minus infinity */
if ( t[0 ] != 0 )
{
if ( qcmp( t, y ) != 0 )
qsub( qone, y, y );
}
return (0 );
}
int qround(x, y)
QELT *x, *y;
{
QELT z[NQ], f[NQ];
int r;
qfloor( x, z );
qsub( z, x, f );
r = qcmp( f, qhalf );
if ( r > 0 )
goto rndup;
if ( r == 0 )
{
/* round to even */
z[1 ] -= 1 ;
qfloor( z, f );
z[1 ] += 1 ;
f[1 ] += 1 ;
if ( qcmp(z,f) != 0 )
{
rndup: qadd( qone, z, z );
}
}
qmov( z, y );
return (0 );
}
Messung V0.5 in Prozent C=97 H=84 G=90
¤ Dauer der Verarbeitung: 0.10 Sekunden
(vorverarbeitet am 2026-06-23)
¤
*© Formatika GbR, Deutschland