Annotation of OpenXM_contrib2/asir2018/engine/real.c, Revision 1.1
1.1 ! 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@sec.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$
! 49: */
! 50: #include "ca.h"
! 51: #include "base.h"
! 52: #include <math.h>
! 53:
! 54: double RatnToReal(Q a)
! 55: {
! 56: if ( INT(a) )
! 57: return mpz_get_d(BDY((Z)a));
! 58: else
! 59: return mpq_get_d(BDY((Q)a));
! 60: }
! 61:
! 62: void addreal(Num a,Num b,Real *c)
! 63: {
! 64: double t;
! 65:
! 66: t = ToReal(a)+ToReal(b); MKReal(t,*c);
! 67: }
! 68:
! 69: void subreal(Num a,Num b,Real *c)
! 70: {
! 71: double t;
! 72:
! 73: t = ToReal(a)-ToReal(b); MKReal(t,*c);
! 74: }
! 75:
! 76: void mulreal(Num a,Num b,Real *c)
! 77: {
! 78: double t;
! 79:
! 80: if ( !a || !b )
! 81: *c = 0;
! 82: else {
! 83: t = ToReal(a)*ToReal(b);
! 84: #if 0
! 85: if ( !t )
! 86: error("mulreal : Underflow"); /* XXX */
! 87: else
! 88: #endif
! 89: MKReal(t,*c);
! 90: }
! 91: }
! 92:
! 93: void divreal(Num a,Num b,Real *c)
! 94: {
! 95: double t;
! 96:
! 97: if ( !a )
! 98: *c = 0;
! 99: else {
! 100: t = ToReal(a)/ToReal(b);
! 101: #if 0
! 102: if ( !t )
! 103: error("divreal : Underflow"); /* XXX */
! 104: else
! 105: #endif
! 106: MKReal(t,*c);
! 107: }
! 108: }
! 109:
! 110: void chsgnreal(Num a,Num *c)
! 111: {
! 112: double t;
! 113: Real s;
! 114:
! 115: if ( !a )
! 116: *c = 0;
! 117: else if ( NID(a) == N_Q )
! 118: chsgnq((Q)a,(Q *)c);
! 119: else {
! 120: t = -ToReal(a); MKReal(t,s); *c = (Num)s;
! 121: }
! 122: }
! 123:
! 124: void pwrreal(Num a,Num b,Real *c)
! 125: {
! 126: int e,ea;
! 127: double t;
! 128: double pwrreal0();
! 129:
! 130: if ( !b )
! 131: MKReal(1.0,*c);
! 132: else if ( !a )
! 133: *c = 0;
! 134: else if ( !RATN(b) || !INT(b) || !smallz((Z)b) ) {
! 135: t = (double)pow((double)ToReal(a),(double)ToReal(b));
! 136: MKReal(t,*c);
! 137: } else {
! 138: e = mpz_get_si(BDY((Z)b));
! 139: ea = e>0?e:-e;
! 140: t = pwrreal0(BDY((Real)a),ea);
! 141: t = e>0?t:1/t;
! 142: MKReal(t,*c);
! 143: }
! 144: }
! 145:
! 146: double pwrreal0(double n,int e)
! 147: {
! 148: double t;
! 149:
! 150: if ( e == 1 )
! 151: return n;
! 152: else {
! 153: t = pwrreal0(n,e / 2);
! 154: return e%2 ? t*t*n : t*t;
! 155: }
! 156: }
! 157:
! 158: int cmpreal(Real a,Real b)
! 159: {
! 160: double t;
! 161:
! 162: t = ToReal(a)-ToReal(b);
! 163: return t>0.0 ? 1 : t<0.0?-1 : 0;
! 164: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>