[BACK]Return to math.c CVS log [TXT][DIR] Up to [local] / OpenXM_contrib2 / asir2000 / builtin

Annotation of OpenXM_contrib2/asir2000/builtin/math.c, Revision 1.2

1.2     ! noro        1: /*
        !             2:  * Copyright (c) 1994-2000 FUJITSU LABORATORIES LIMITED
        !             3:  * All rights reserved.
        !             4:  *
        !             5:  * FUJITSU LABORATORIES LIMITED ("FLL") hereby grants you a limited,
        !             6:  * non-exclusive and royalty-free license to use, copy, modify and
        !             7:  * redistribute, solely for non-commercial and non-profit purposes, the
        !             8:  * computer program, "Risa/Asir" ("SOFTWARE"), subject to the terms and
        !             9:  * conditions of this Agreement. For the avoidance of doubt, you acquire
        !            10:  * only a limited right to use the SOFTWARE hereunder, and FLL or any
        !            11:  * third party developer retains all rights, including but not limited to
        !            12:  * copyrights, in and to the SOFTWARE.
        !            13:  *
        !            14:  * (1) FLL does not grant you a license in any way for commercial
        !            15:  * purposes. You may use the SOFTWARE only for non-commercial and
        !            16:  * non-profit purposes only, such as academic, research and internal
        !            17:  * business use.
        !            18:  * (2) The SOFTWARE is protected by the Copyright Law of Japan and
        !            19:  * international copyright treaties. If you make copies of the SOFTWARE,
        !            20:  * with or without modification, as permitted hereunder, you shall affix
        !            21:  * to all such copies of the SOFTWARE the above copyright notice.
        !            22:  * (3) An explicit reference to this SOFTWARE and its copyright owner
        !            23:  * shall be made on your publication or presentation in any form of the
        !            24:  * results obtained by use of the SOFTWARE.
        !            25:  * (4) In the event that you modify the SOFTWARE, you shall notify FLL by
        !            26:  * e-mail at risa-admin@flab.fujitsu.co.jp of the detailed specification
        !            27:  * for such modification or the source code of the modified part of the
        !            28:  * SOFTWARE.
        !            29:  *
        !            30:  * THE SOFTWARE IS PROVIDED AS IS WITHOUT ANY WARRANTY OF ANY KIND. FLL
        !            31:  * MAKES ABSOLUTELY NO WARRANTIES, EXPRESSED, IMPLIED OR STATUTORY, AND
        !            32:  * EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS
        !            33:  * FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT OF THIRD PARTIES'
        !            34:  * RIGHTS. NO FLL DEALER, AGENT, EMPLOYEES IS AUTHORIZED TO MAKE ANY
        !            35:  * MODIFICATIONS, EXTENSIONS, OR ADDITIONS TO THIS WARRANTY.
        !            36:  * UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, TORT, CONTRACT,
        !            37:  * OR OTHERWISE, SHALL FLL BE LIABLE TO YOU OR ANY OTHER PERSON FOR ANY
        !            38:  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, PUNITIVE OR CONSEQUENTIAL
        !            39:  * DAMAGES OF ANY CHARACTER, INCLUDING, WITHOUT LIMITATION, DAMAGES
        !            40:  * ARISING OUT OF OR RELATING TO THE SOFTWARE OR THIS AGREEMENT, DAMAGES
        !            41:  * FOR LOSS OF GOODWILL, WORK STOPPAGE, OR LOSS OF DATA, OR FOR ANY
        !            42:  * DAMAGES, EVEN IF FLL SHALL HAVE BEEN INFORMED OF THE POSSIBILITY OF
        !            43:  * SUCH DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY. EVEN IF A PART
        !            44:  * OF THE SOFTWARE HAS BEEN DEVELOPED BY A THIRD PARTY, THE THIRD PARTY
        !            45:  * DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE,
        !            46:  * PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE.
        !            47:  *
        !            48:  * $OpenXM: OpenXM_contrib2/asir2000/builtin/math.c,v 1.1.1.1 1999/12/03 07:39:07 noro Exp $
        !            49: */
1.1       noro       50: #include "ca.h"
                     51: #include <math.h>
                     52: #include "parse.h"
                     53:
                     54: void Pdsqrt(),Pdsin(),Pdcos(),Pdtan(),Pdasin(),Pdacos(),Pdatan(),Pdlog(),Pdexp();
                     55: void Pabs(),Pdfloor(),Pdceil(),Pdrint();
                     56:
                     57: struct ftab math_tab[] = {
                     58:        {"dsqrt",Pdsqrt,1},
                     59:        {"dabs",Pabs,1},
                     60:        {"dsin",Pdsin,1},
                     61:        {"dcos",Pdcos,1},
                     62:        {"dtan",Pdtan,1},
                     63:        {"dlog",Pdlog,1},
                     64:        {"dexp",Pdexp,1},
                     65:        {"dasin",Pdasin,1},
                     66:        {"dacos",Pdacos,1},
                     67:        {"datan",Pdatan,1},
                     68:        {"dfloor",Pdfloor,1},
                     69:        {"dceil",Pdceil,1},
                     70:        {"drint",Pdrint,1},
                     71:        {0,0,0},
                     72: };
                     73:
                     74: void Pabs(arg,rp)
                     75: NODE arg;
                     76: Real *rp;
                     77: {
                     78:        double s;
                     79:
                     80:        s = fabs(ToReal(ARG0(arg)));
                     81:        MKReal(s,*rp);
                     82: }
                     83:
                     84: void Pdsqrt(arg,rp)
                     85: NODE arg;
                     86: Real *rp;
                     87: {
                     88:        double s;
                     89:
                     90:        s = sqrt(ToReal(ARG0(arg)));
                     91:        MKReal(s,*rp);
                     92: }
                     93:
                     94: void Pdsin(arg,rp)
                     95: NODE arg;
                     96: Real *rp;
                     97: {
                     98:        double s;
                     99:
                    100:        s = sin(ToReal(ARG0(arg)));
                    101:        MKReal(s,*rp);
                    102: }
                    103:
                    104: void Pdcos(arg,rp)
                    105: NODE arg;
                    106: Real *rp;
                    107: {
                    108:        double s;
                    109:
                    110:        s = cos(ToReal(ARG0(arg)));
                    111:        MKReal(s,*rp);
                    112: }
                    113:
                    114: void Pdtan(arg,rp)
                    115: NODE arg;
                    116: Real *rp;
                    117: {
                    118:        double s;
                    119:
                    120:        s = tan(ToReal(ARG0(arg)));
                    121:        MKReal(s,*rp);
                    122: }
                    123:
                    124: void Pdasin(arg,rp)
                    125: NODE arg;
                    126: Real *rp;
                    127: {
                    128:        double s;
                    129:
                    130:        s = asin(ToReal(ARG0(arg)));
                    131:        MKReal(s,*rp);
                    132: }
                    133:
                    134: void Pdacos(arg,rp)
                    135: NODE arg;
                    136: Real *rp;
                    137: {
                    138:        double s;
                    139:
                    140:        s = acos(ToReal(ARG0(arg)));
                    141:        MKReal(s,*rp);
                    142: }
                    143:
                    144: void Pdatan(arg,rp)
                    145: NODE arg;
                    146: Real *rp;
                    147: {
                    148:        double s;
                    149:
                    150:        s = atan(ToReal(ARG0(arg)));
                    151:        MKReal(s,*rp);
                    152: }
                    153:
                    154: void Pdlog(arg,rp)
                    155: NODE arg;
                    156: Real *rp;
                    157: {
                    158:        double s;
                    159:
                    160:        s = log(ToReal(ARG0(arg)));
                    161:        MKReal(s,*rp);
                    162: }
                    163:
                    164: void Pdexp(arg,rp)
                    165: NODE arg;
                    166: Real *rp;
                    167: {
                    168:        double s;
                    169:
                    170:        s = exp(ToReal(ARG0(arg)));
                    171:        MKReal(s,*rp);
                    172: }
                    173:
                    174: void Pdfloor(arg,rp)
                    175: NODE arg;
                    176: Q *rp;
                    177: {
                    178:        L a;
                    179:        unsigned int au,al;
                    180:        int sgn;
                    181:        Q q;
                    182:        double d;
                    183:
                    184:        if ( !ARG0(arg) ) {
                    185:                *rp = 0;
                    186:                return;
                    187:        }
                    188:        d = floor(ToReal(ARG0(arg)));
                    189:        if ( d < -9.223372036854775808e18 || d >= 9.223372036854775808e18 )
                    190:                error("dfloor : OverFlow");
                    191:        a = (L)d;
                    192:        if ( a < 0 ) {
                    193:                sgn = -1;
                    194:                a = -a;
                    195:        } else
                    196:                sgn = 1;
                    197: #if defined(i386) || defined(__alpha) || defined(VISUAL)
                    198:        au = ((unsigned int *)&a)[1];
                    199:        al = ((unsigned int *)&a)[0];
                    200: #else
                    201:        al = ((unsigned int *)&a)[1];
                    202:        au = ((unsigned int *)&a)[0];
                    203: #endif
                    204:        if ( au ) {
                    205:                NEWQ(q); SGN(q) = sgn; NM(q)=NALLOC(2); DN(q)=0;
                    206:                PL(NM(q))=2; BD(NM(q))[0]=al; BD(NM(q))[1] = au;
                    207:        } else {
                    208:                UTOQ(al,q); SGN(q) = sgn;
                    209:        }
                    210:        *rp = q;
                    211: }
                    212:
                    213: void Pdceil(arg,rp)
                    214: NODE arg;
                    215: Q *rp;
                    216: {
                    217:        L a;
                    218:        unsigned int au,al;
                    219:        int sgn;
                    220:        Q q;
                    221:        double d;
                    222:
                    223:        if ( !ARG0(arg) ) {
                    224:                *rp = 0;
                    225:                return;
                    226:        }
                    227:        d = ceil(ToReal(ARG0(arg)));
                    228:        if ( d < -9.223372036854775808e18 || d >= 9.223372036854775808e18 )
                    229:                error("dceil : OverFlow");
                    230:        a = (L)d;
                    231:        if ( a < 0 ) {
                    232:                sgn = -1;
                    233:                a = -a;
                    234:        } else
                    235:                sgn = 1;
                    236: #if defined(i386) || defined(__alpha) || defined(VISUAL)
                    237:        au = ((unsigned int *)&a)[1];
                    238:        al = ((unsigned int *)&a)[0];
                    239: #else
                    240:        al = ((unsigned int *)&a)[1];
                    241:        au = ((unsigned int *)&a)[0];
                    242: #endif
                    243:        if ( au ) {
                    244:                NEWQ(q); SGN(q) = sgn; NM(q)=NALLOC(2); DN(q)=0;
                    245:                PL(NM(q))=2; BD(NM(q))[0]=al; BD(NM(q))[1] = au;
                    246:        } else {
                    247:                UTOQ(al,q); SGN(q) = sgn;
                    248:        }
                    249:        *rp = q;
                    250: }
                    251:
                    252: void Pdrint(arg,rp)
                    253: NODE arg;
                    254: Q *rp;
                    255: {
                    256:        L a;
                    257:        unsigned int au,al;
                    258:        int sgn;
                    259:        Q q;
                    260:        double d;
                    261:
                    262:        if ( !ARG0(arg) ) {
                    263:                *rp = 0;
                    264:                return;
                    265:        }
                    266: #if defined(VISUAL)
                    267:        d = ToReal(ARG0(arg));
                    268:        if ( d > 0 )
                    269:                d = floor(d+0.5);
                    270:        else
                    271:                d = ceil(d-0.5);
                    272: #else
                    273:        d = rint(ToReal(ARG0(arg)));
                    274: #endif
                    275:        if ( d < -9.223372036854775808e18 || d >= 9.223372036854775808e18 )
                    276:                error("drint : OverFlow");
                    277:        a = (L)d;
                    278:        if ( a < 0 ) {
                    279:                sgn = -1;
                    280:                a = -a;
                    281:        } else
                    282:                sgn = 1;
                    283: #if defined(i386) || defined(__alpha) || defined(VISUAL)
                    284:        au = ((unsigned int *)&a)[1];
                    285:        al = ((unsigned int *)&a)[0];
                    286: #else
                    287:        al = ((unsigned int *)&a)[1];
                    288:        au = ((unsigned int *)&a)[0];
                    289: #endif
                    290:        if ( au ) {
                    291:                NEWQ(q); SGN(q) = sgn; NM(q)=NALLOC(2); DN(q)=0;
                    292:                PL(NM(q))=2; BD(NM(q))[0]=al; BD(NM(q))[1] = au;
                    293:        } else {
                    294:                UTOQ(al,q); SGN(q) = sgn;
                    295:        }
                    296:        *rp = q;
                    297: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>