Skip site navigation (1) Skip section navigation (2)

Re: Arbitrary precision modulo operation

From: "Dann Corbit" <DCorbit(at)connx(dot)com>
To: "Dann Corbit" <DCorbit(at)connx(dot)com>,"Bruno Wolff III" <bruno(at)wolff(dot)to>, "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "Paul Tillotson" <pntil(at)shentel(dot)net>,<pgsql-general(at)postgresql(dot)org>
Subject: Re: Arbitrary precision modulo operation
Date: 2004-04-28 22:06:25
Message-ID: D90A5A6C612A39408103E6ECDD77B8299CAA3E@voyager.corporate.connx.com (view raw or flat)
Thread:
Lists: pgsql-general
/*
** Hopefully, I am not annoying anyone with all of this.
** This is a brief demonstration of how Newton's division algorithm
works:
*/
#include <stdio.h>
double          divide(double x, double y)
{
    unsigned __int64 est;
    double          y1 = 1.0 / y;
    double          y2;
    puts("\nForming reciprocal:");
    est = y1 * 10000;
    y1 = est / 10000.0;         /* make an estimate good to 4 decimal
places... */
    printf("x=%.7f, y=%.7f, y1=%.7f\n", x, y, y1);
    y1 *= (2 - y * y1); /* should be 8 places */
    printf("x=%.14f, y=%.14f, y1=%.14f\n", x, y, y1);
    y1 *= (2 - y * y1); /* In theory ~16 digits */
    printf("x=%.20f, y=%.20f, y1=%.20f\n", x, y, y1);
    y1 *= (2 - y * y1); /* One more is really needed here... */
    printf("x=%.20f, y=%.20f, y1=%.20f\n", x, y, y1);
    puts("\ndividing:");
    printf("result of division is:%f\n", x * y1);
    return 0;
}

int             main(void)
{
    divide(1.0, 2.0);
    divide(1.0, 17.0);
    divide(3.0, 19.0);
    divide(19.0, 3.0);
    return 0;
}

Responses

pgsql-general by date

Next:From: Paul TillotsonDate: 2004-04-28 23:13:16
Subject: Re: Postgre and Web Request
Previous:From: Chris BrowneDate: 2004-04-28 21:58:24
Subject: Re: Postgre and Web Request

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group