[BACK]Return to r-fd.rr CVS log [TXT][DIR] Up to [local] / OpenXM / src / asir-port / cgi

Annotation of OpenXM/src/asir-port/cgi/r-fd.rr, Revision 1.9

1.9     ! takayama    1: /* $OpenXM: OpenXM/src/asir-port/cgi/r-fd.rr,v 1.8 2015/02/28 11:39:13 takayama Exp $ */
1.1       takayama    2: load("tk_fd.rr")$
1.2       takayama    3: import("tk_r.rr")$
1.3       takayama    4: import("oh_number.rr")$
                      5:
                      6: /* r_d2rat(0.3)  --> precision loss in truncation if not ctrl("bigfloat",1) */
                      7: ctrl("bigfloat",1)$
1.9     ! takayama    8: def r_d2rat(Y,Prec) {
        !             9:   if ((type(Y) ==4)||(type(Y)==5)||(type(Y)==6)) return map(r_d2rat,Y,Prec);
1.3       takayama   10:   if ((type(Y)  == 1) && (ntype(Y) >= 1)) {
                     11:     S = rtostr(Y);  Y = "eval(("+S+")*exp(0));";
                     12:     /* print(Y); */
                     13:     Y = eval_str(Y);
1.4       takayama   14:     /* printf("Y=%a\n",Y); */
                     15:     /* return oh_number.rats(Y); */
1.9     ! takayama   16:     return rats2(Y | prec=Prec);  /* temporary  */
1.3       takayama   17:   }else return Y;
                     18: }
1.1       takayama   19: def r_ahvec(A,B,C,Y) {
1.9     ! takayama   20:   if (type(getopt(prec))<0) Prec=20;
        !            21:   else Prec=getopt(prec);
        !            22:   Y = r_d2rat(Y,Prec);
1.7       takayama   23:   Ans=a_ahvec(A,B,C,Y);
                     24:   /*  Fans=map(rtostr,map(tk_fd.tk_number_rattofloat,Ans)); */
                     25:   Fans=map(deval,Ans);
                     26:   Fans = tk_r.asir2r_c(Fans);
                     27:   return Fans;
                     28: }
                     29:
                     30: def a_ahvec(A,B,C,Y) {
1.5       takayama   31:   R=tk_fd.ahvec_abc(A,B,C,Y|all=1);
1.1       takayama   32:   Gamma=R[1];
                     33:   Der=R[0];
                     34:   Z=R[2]*Gamma;
                     35:   Der2 = newvect(length(Der));
                     36:   for (I=0; I<length(Der); I++) Der2[I] = Der[I]*Gamma;
                     37:   Der2 = vtol(Der2);
                     38:   Ans=cons(Z,Der2);
1.7       takayama   39:   return(Ans);
1.1       takayama   40: }
1.4       takayama   41:
                     42: /* temporary */
                     43: def rats2(X) {
1.9     ! takayama   44:   if (type(getopt(prec))<0) Prec=20;
        !            45:   else Prec=getopt(prec);
1.4       takayama   46:   if (X == 0) return 0;
                     47:   Sign=1;
                     48:   if (X <0) {Sign=-1  ; X = -X;}
                     49:   Digit = number_floor(eval(log(X)/log(10)));
1.9     ! takayama   50:   Num = number_floor((X/(10^Digit))*10^Prec);
        !            51:   return Sign*(Num/(10^Prec))*(10^Digit);
1.4       takayama   52: }
                     53:
                     54: def checkrats2() {
                     55:   for (I=0; I<10; I++) {
                     56:      Sign=(-1)^(random()%2);
                     57:      X = eval(exp(0)*(random()/random())*10^(Sign*(random()%300))); /* 308 */
                     58:      printf("X=%a\n",X);
                     59:      Y = rats2(X);
                     60:      printf("Y=%a\n",Y);
                     61:      if (number_abs(eval(Y*exp(0))/X-1) > 0.0000001) {
                     62:         printf("error: X = %a, Y=%a\n",X,Y);
                     63:      }
                     64:   }
                     65: }
1.6       takayama   66:
                     67: def a_expect(A,B,C,Y) {
                     68:   E=tk_fd.expectation_abc(A,B,C,Y);
                     69:   return(E);
                     70: }
                     71: def r_expect(A,B,C,Y) {
1.9     ! takayama   72:   if (type(getopt(prec))<0) Prec=20;
        !            73:   else Prec=getopt(prec);
        !            74:
        !            75:   Y = r_d2rat(Y,Prec);
1.6       takayama   76:   E=a_expect(A,B,C,Y);
1.8       takayama   77:   Fans=map_deval(E);
1.6       takayama   78:   Fans = tk_r.asir2r_c(Fans);
                     79:   return Fans;
                     80: }
                     81:
1.8       takayama   82: def r_ahmat(A,B,C,Y) {
1.9     ! takayama   83:   if (type(getopt(prec))<0) Prec=20;
        !            84:   else Prec=getopt(prec);
        !            85:   Y = r_d2rat(Y,Prec);
1.8       takayama   86:   Ans=a_ahmat(A,B,C,Y);
                     87:   Fans=map_deval(Ans);
                     88:   Fans = tk_r.asir2r_c(Fans);
                     89:   return Fans;
                     90: }
                     91:
                     92: def a_ahmat(A,B,C,Y) {
                     93:   return(tk_fd.ahmat_abc(A,B,C,Y));
                     94: }
                     95:
                     96: def r_log_ahmat(A,B,C,Y) {
1.9     ! takayama   97:   if (type(getopt(prec))<0) Prec=20;
        !            98:   else Prec=getopt(prec);
        !            99:   Y = r_d2rat(Y,Prec);
1.8       takayama  100:   Ans=a_log_ahmat(A,B,C,Y);
                    101:   Fans=map_deval(Ans);
                    102:   Fans = tk_r.asir2r_c(Fans);
                    103:   return Fans;
                    104: }
                    105:
                    106: def a_log_ahmat(A,B,C,Y) {
                    107:   Ans=tk_fd.log_ahmat_abc(A,B,C,Y);
                    108:   return Ans;
                    109: }
                    110:
                    111: def map_deval(L) {
                    112:   if (type(L) >=4) return(map(map_deval,L));
                    113:   return(deval(L));
                    114: }
1.1       takayama  115: end$

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