[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.6

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
1.3       noro       26:  * e-mail at risa-admin@sec.flab.fujitsu.co.jp of the detailed specification
1.2       noro       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:  *
1.6     ! noro       48:  * $OpenXM: OpenXM_contrib2/asir2000/builtin/math.c,v 1.5 2003/11/08 01:12:02 noro Exp $
1.2       noro       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},
1.5       noro       68:        {"floor",Pdfloor,1},
1.1       noro       69:        {"dfloor",Pdfloor,1},
1.5       noro       70:        {"ceil",Pdceil,1},
1.1       noro       71:        {"dceil",Pdceil,1},
1.5       noro       72:        {"rint",Pdrint,1},
1.1       noro       73:        {"drint",Pdrint,1},
                     74:        {0,0,0},
                     75: };
                     76:
                     77: void Pabs(arg,rp)
                     78: NODE arg;
                     79: Real *rp;
                     80: {
                     81:        double s;
                     82:
                     83:        s = fabs(ToReal(ARG0(arg)));
                     84:        MKReal(s,*rp);
                     85: }
                     86:
                     87: void Pdsqrt(arg,rp)
                     88: NODE arg;
                     89: Real *rp;
                     90: {
                     91:        double s;
                     92:
                     93:        s = sqrt(ToReal(ARG0(arg)));
                     94:        MKReal(s,*rp);
                     95: }
                     96:
                     97: void Pdsin(arg,rp)
                     98: NODE arg;
                     99: Real *rp;
                    100: {
                    101:        double s;
                    102:
                    103:        s = sin(ToReal(ARG0(arg)));
                    104:        MKReal(s,*rp);
                    105: }
                    106:
                    107: void Pdcos(arg,rp)
                    108: NODE arg;
                    109: Real *rp;
                    110: {
                    111:        double s;
                    112:
                    113:        s = cos(ToReal(ARG0(arg)));
                    114:        MKReal(s,*rp);
                    115: }
                    116:
                    117: void Pdtan(arg,rp)
                    118: NODE arg;
                    119: Real *rp;
                    120: {
                    121:        double s;
                    122:
                    123:        s = tan(ToReal(ARG0(arg)));
                    124:        MKReal(s,*rp);
                    125: }
                    126:
                    127: void Pdasin(arg,rp)
                    128: NODE arg;
                    129: Real *rp;
                    130: {
                    131:        double s;
                    132:
                    133:        s = asin(ToReal(ARG0(arg)));
                    134:        MKReal(s,*rp);
                    135: }
                    136:
                    137: void Pdacos(arg,rp)
                    138: NODE arg;
                    139: Real *rp;
                    140: {
                    141:        double s;
                    142:
                    143:        s = acos(ToReal(ARG0(arg)));
                    144:        MKReal(s,*rp);
                    145: }
                    146:
                    147: void Pdatan(arg,rp)
                    148: NODE arg;
                    149: Real *rp;
                    150: {
                    151:        double s;
                    152:
                    153:        s = atan(ToReal(ARG0(arg)));
                    154:        MKReal(s,*rp);
                    155: }
                    156:
                    157: void Pdlog(arg,rp)
                    158: NODE arg;
                    159: Real *rp;
                    160: {
                    161:        double s;
                    162:
                    163:        s = log(ToReal(ARG0(arg)));
                    164:        MKReal(s,*rp);
                    165: }
                    166:
                    167: void Pdexp(arg,rp)
                    168: NODE arg;
                    169: Real *rp;
                    170: {
                    171:        double s;
                    172:
                    173:        s = exp(ToReal(ARG0(arg)));
                    174:        MKReal(s,*rp);
                    175: }
                    176:
                    177: void Pdfloor(arg,rp)
                    178: NODE arg;
                    179: Q *rp;
                    180: {
                    181:        L a;
                    182:        unsigned int au,al;
                    183:        int sgn;
                    184:        Q q;
                    185:        double d;
                    186:
                    187:        if ( !ARG0(arg) ) {
                    188:                *rp = 0;
                    189:                return;
                    190:        }
                    191:        d = floor(ToReal(ARG0(arg)));
                    192:        if ( d < -9.223372036854775808e18 || d >= 9.223372036854775808e18 )
                    193:                error("dfloor : OverFlow");
1.4       noro      194:        if ( !d ) {
                    195:                *rp = 0;
                    196:                return;
                    197:        }
1.1       noro      198:        a = (L)d;
                    199:        if ( a < 0 ) {
                    200:                sgn = -1;
                    201:                a = -a;
                    202:        } else
                    203:                sgn = 1;
                    204: #if defined(i386) || defined(__alpha) || defined(VISUAL)
                    205:        au = ((unsigned int *)&a)[1];
                    206:        al = ((unsigned int *)&a)[0];
                    207: #else
                    208:        al = ((unsigned int *)&a)[1];
                    209:        au = ((unsigned int *)&a)[0];
                    210: #endif
                    211:        if ( au ) {
                    212:                NEWQ(q); SGN(q) = sgn; NM(q)=NALLOC(2); DN(q)=0;
                    213:                PL(NM(q))=2; BD(NM(q))[0]=al; BD(NM(q))[1] = au;
                    214:        } else {
                    215:                UTOQ(al,q); SGN(q) = sgn;
                    216:        }
                    217:        *rp = q;
                    218: }
                    219:
                    220: void Pdceil(arg,rp)
                    221: NODE arg;
                    222: Q *rp;
                    223: {
                    224:        L a;
                    225:        unsigned int au,al;
                    226:        int sgn;
                    227:        Q q;
                    228:        double d;
                    229:
                    230:        if ( !ARG0(arg) ) {
                    231:                *rp = 0;
                    232:                return;
                    233:        }
                    234:        d = ceil(ToReal(ARG0(arg)));
                    235:        if ( d < -9.223372036854775808e18 || d >= 9.223372036854775808e18 )
                    236:                error("dceil : OverFlow");
1.4       noro      237:        if ( !d ) {
                    238:                *rp = 0;
                    239:                return;
                    240:        }
1.1       noro      241:        a = (L)d;
                    242:        if ( a < 0 ) {
                    243:                sgn = -1;
                    244:                a = -a;
                    245:        } else
                    246:                sgn = 1;
                    247: #if defined(i386) || defined(__alpha) || defined(VISUAL)
                    248:        au = ((unsigned int *)&a)[1];
                    249:        al = ((unsigned int *)&a)[0];
                    250: #else
                    251:        al = ((unsigned int *)&a)[1];
                    252:        au = ((unsigned int *)&a)[0];
                    253: #endif
                    254:        if ( au ) {
                    255:                NEWQ(q); SGN(q) = sgn; NM(q)=NALLOC(2); DN(q)=0;
                    256:                PL(NM(q))=2; BD(NM(q))[0]=al; BD(NM(q))[1] = au;
                    257:        } else {
                    258:                UTOQ(al,q); SGN(q) = sgn;
                    259:        }
                    260:        *rp = q;
                    261: }
                    262:
                    263: void Pdrint(arg,rp)
                    264: NODE arg;
                    265: Q *rp;
                    266: {
                    267:        L a;
                    268:        unsigned int au,al;
                    269:        int sgn;
                    270:        Q q;
                    271:        double d;
                    272:
                    273:        if ( !ARG0(arg) ) {
                    274:                *rp = 0;
                    275:                return;
                    276:        }
                    277: #if defined(VISUAL)
                    278:        d = ToReal(ARG0(arg));
                    279:        if ( d > 0 )
                    280:                d = floor(d+0.5);
                    281:        else
                    282:                d = ceil(d-0.5);
                    283: #else
                    284:        d = rint(ToReal(ARG0(arg)));
                    285: #endif
                    286:        if ( d < -9.223372036854775808e18 || d >= 9.223372036854775808e18 )
                    287:                error("drint : OverFlow");
                    288:        a = (L)d;
                    289:        if ( a < 0 ) {
                    290:                sgn = -1;
                    291:                a = -a;
                    292:        } else
                    293:                sgn = 1;
                    294: #if defined(i386) || defined(__alpha) || defined(VISUAL)
                    295:        au = ((unsigned int *)&a)[1];
                    296:        al = ((unsigned int *)&a)[0];
                    297: #else
                    298:        al = ((unsigned int *)&a)[1];
                    299:        au = ((unsigned int *)&a)[0];
                    300: #endif
                    301:        if ( au ) {
                    302:                NEWQ(q); SGN(q) = sgn; NM(q)=NALLOC(2); DN(q)=0;
                    303:                PL(NM(q))=2; BD(NM(q))[0]=al; BD(NM(q))[1] = au;
1.6     ! noro      304:        } else if ( al ) {
1.1       noro      305:                UTOQ(al,q); SGN(q) = sgn;
1.6     ! noro      306:        } else
        !           307:                q = 0;
1.1       noro      308:        *rp = q;
                    309: }

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