EFPBox.java
     1: //========================================================================================
     2: //  EFPBox.java
     3: //    en:Floating-point number box -- Floating-point calculation and floating-point registers
     4: //    ja:浮動小数点数箱 -- 浮動小数点演算と浮動小数点レジスタ
     5: //  Copyright (C) 2003-2023 Makoto Kamada
     6: //
     7: //  This file is part of the XEiJ (X68000 Emulator in Java).
     8: //  You can use, modify and redistribute the XEiJ if the conditions are met.
     9: //  Read the XEiJ License for more details.
    10: //  https://stdkmd.net/xeij/
    11: //========================================================================================
    12: 
    13: package xeij;
    14: 
    15: import java.lang.*;  //Boolean,Character,Class,Comparable,Double,Exception,Float,IllegalArgumentException,Integer,Long,Math,Number,Object,Runnable,SecurityException,String,StringBuilder,System
    16: import java.util.*;  //ArrayList,Arrays,Calendar,GregorianCalendar,HashMap,Map,Map.Entry,Timer,TimerTask,TreeMap
    17: 
    18: public class EFPBox {
    19: 
    20:   //浮動小数点拡張命令
    21:   //  実験のみ。常用しないこと
    22:   //  $xx70: FLGAMMA *m,FPn
    23:   //  $xx71: FTGAMMA *m,FPn
    24:   //  三角関数
    25:   //    sin    正弦 sine サイン
    26:   //    cos    余弦 cosine コサイン
    27:   //    tan    正接 tangent タンジェント
    28:   //    cot    余接 cotangent コタンジェント
    29:   //    sec    正割 secant セカント
    30:   //    csc    余割 cosecant コセカント
    31:   //  逆三角関数
    32:   //    asin   逆正弦 inverse sine インバースサイン
    33:   //    acos   逆余弦 inverse cosine インバースコサイン
    34:   //    atan   逆正接 inverse tangent インバースタンジェント
    35:   //    acot   逆余接 inverse cotangent インバースコタンジェント
    36:   //    asec   逆正割 inverse secant インバースセカント
    37:   //    acsc   逆余割 inverse cosecant インバースコセカント
    38:   //  双曲線関数
    39:   //    sinh   双曲線正弦 hyperbolic sine ハイパボリックサイン
    40:   //    cosh   双曲線余弦 hyperbolic cosine ハイパボリックコサイン
    41:   //    tanh   双曲線正接 hyperbolic tangent ハイパボリックタンジェント
    42:   //    coth   双曲線余接 hyperbolic cotangent ハイパボリックコタンジェント
    43:   //    sech   双曲線正割 hyperbolic secant ハイパボリックセカント
    44:   //    csch   双曲線余割 hyperbolic cosecant ハイパボリックコセカント
    45:   //  逆双曲線関数
    46:   //    asinh  逆双曲線正弦 inverse hyperbolic sine インバースハイパボリックサイン
    47:   //    acosh  逆双曲線余弦 inverse hyperbolic cosine インバースハイパボリックコサイン
    48:   //    atanh  逆双曲線正接 inverse hyperbolic tangent インバースハイパボリックタンジェント
    49:   //    acoth  逆双曲線余接 inverse hyperbolic cotangent インバースハイパボリックコタンジェント
    50:   //    asech  逆双曲線正割 inverse hyperbolic secant インバースハイパボリックセカント
    51:   //    acsch  逆双曲線余割 inverse hyperbolic cosecant インバースハイパボリックコセカント
    52:   //  その他
    53:   //    lgamma  ログガンマ関数
    54:   //    tgamma  ガンマ関数
    55:   public static final boolean EPB_EXTRA_OPERATION = true;  //true=浮動小数点拡張命令を追加する
    56: 
    57:   //------------------------------------------------------------------------
    58:   //モード
    59:   public static final int EPB_MODE_MC68881  = 1 << 1;  //MC68881
    60:   public static final int EPB_MODE_MC68882  = 1 << 2;  //MC68882
    61:   public static final int EPB_MODE_MC68060  = 1 << 6;  //MC68060
    62:   public static final int EPB_MODE_FULLSPEC = EPB_MODE_MC68881 | EPB_MODE_MC68882 | EPB_MODE_MC68060;
    63:   public static final int EPB_MODE_EXTENDED = 1 << 8;  //拡張精度
    64:   public static final int EPB_MODE_TRIPLE   = 1 << 9;  //三倍精度
    65:   public static int epbMode;
    66: 
    67:   //------------------------------------------------------------------------
    68:   //フラグ flg
    69:   public static final int P = 0 << 31;  //+
    70:   public static final int M = 1 << 31;  //-
    71:   public static final int Z = 1 << 30;  //±0
    72:   public static final int I = 1 << 29;  //±Inf
    73:   public static final int N = 1 << 28;  //±NaN
    74: 
    75:   //------------------------------------------------------------------------
    76:   //FPCR
    77:   //  exception enable byte
    78:   public static final int EPB_FPCR_BS = 1 << 15;  //BSUN   branch/set on unordered
    79:   public static final int EPB_FPCR_SN = 1 << 14;  //SNAN   signaling not a number
    80:   public static final int EPB_FPCR_OE = 1 << 13;  //OPERR  operand error
    81:   public static final int EPB_FPCR_OF = 1 << 12;  //OVFL   overflow
    82:   public static final int EPB_FPCR_UF = 1 << 11;  //UNFL   underflow
    83:   public static final int EPB_FPCR_DZ = 1 << 10;  //DZ     divide by zero
    84:   public static final int EPB_FPCR_X2 = 1 <<  9;  //INEX2  inexact operation
    85:   public static final int EPB_FPCR_X1 = 1 <<  8;  //INEX1  inexact decimal input
    86:   //  rounding precision
    87:   public static final int EPB_FPCR_PX = 0 << 6;  //extended
    88:   public static final int EPB_FPCR_PS = 1 << 6;  //single
    89:   public static final int EPB_FPCR_PD = 2 << 6;  //double
    90:   //                                    3 << 6;  //double
    91:   //  rounding mode
    92:   public static final int EPB_FPCR_RN = 0 << 4;  //to nearest
    93:   public static final int EPB_FPCR_RZ = 1 << 4;  //toward zero
    94:   public static final int EPB_FPCR_RM = 2 << 4;  //toward minus infinity
    95:   public static final int EPB_FPCR_RP = 3 << 4;  //toward plus infinity
    96:   public static final int EPB_FPCR_ALL = 0x0000fff0;
    97:   public int epbFpcr;
    98: 
    99:   //------------------------------------------------------------------------
   100:   //FPSR
   101:   //  FPSRのEXCとAEXCを同時にセットする方法はAEXC_UNFL|=EXC_UNFL&EXC_INEX2の&を処理しにくいので、
   102:   //  命令実行後にテーブルを使ってEXCをAEXCに反映させる方法に変更した
   103:   //  condition code byte
   104:   public static final int EPB_FPSR_M = 1 << 27;  //N    negative
   105:   public static final int EPB_FPSR_Z = 1 << 26;  //Z    zero
   106:   public static final int EPB_FPSR_I = 1 << 25;  //INF  infinity
   107:   public static final int EPB_FPSR_N = 1 << 24;  //NAN  not a number or unordered
   108:   //  quotient byte
   109:   public static final int EPB_FPSR_S = 1 << 23;  //sign of quotient
   110:   public static final int EPB_FPSR_Q = 127 << 16;  //quotient
   111:   //  exception status byte
   112:   public static final int EPB_FPSR_BS = 1 << 15;  //BSUN   branch/set on unordered
   113:   public static final int EPB_FPSR_SN = 1 << 14;  //SNAN   signaling not a number
   114:   public static final int EPB_FPSR_OE = 1 << 13;  //OPERR  operand error
   115:   public static final int EPB_FPSR_OF = 1 << 12;  //OVFL   overflow
   116:   public static final int EPB_FPSR_UF = 1 << 11;  //UNFL   underflow
   117:   public static final int EPB_FPSR_DZ = 1 << 10;  //DZ     divide by zero
   118:   public static final int EPB_FPSR_X2 = 1 <<  9;  //INEX2  inexact operation
   119:   public static final int EPB_FPSR_X1 = 1 <<  8;  //INEX1  inexact decimal input
   120:   //  accrued exception byte
   121:   public static final int EPB_FPSR_AV = 1 << 7;  //IOP   invalid operation  AV|=BS|SN|OE
   122:   public static final int EPB_FPSR_AO = 1 << 6;  //OVFL  overflow           AO|=OF
   123:   public static final int EPB_FPSR_AU = 1 << 5;  //UNFL  underflow          AU|=UF&X2
   124:   public static final int EPB_FPSR_AZ = 1 << 4;  //DZ    divide by zero     AZ|=DZ
   125:   public static final int EPB_FPSR_AX = 1 << 3;  //INEX  inexact            AX|=OF|X2|X1
   126:   public static final int EPB_FPSR_ALL = 0x0ffffff8;
   127:   public int epbFpsr;
   128: 
   129:   //------------------------------------------------------------------------
   130:   //FPIAR instruction address register
   131:   public int epbFpiar;
   132: 
   133:   //------------------------------------------------------------------------
   134:   //商
   135:   public int epbQuotient;  //remの商の下位32bit
   136: 
   137:   //------------------------------------------------------------------------
   138:   //丸め桁数
   139:   public static final int EPB_PREC_EXD  = 0;  //extended
   140:   public static final int EPB_PREC_SGL  = 1;  //single
   141:   public static final int EPB_PREC_DBL  = 2;  //double
   142:   public static final int EPB_PREC_DBL3 = 3;  //double
   143:   //
   144:   public static final int EPB_PREC_TPL  = 4;  //triple
   145:   public static final int EPB_PREC_XSG  = 5;  //xsingle
   146:   public static final int EPB_PREC_EFP  = 6;  //efp
   147:   public int epbRoundingPrec;  //丸め桁数
   148: 
   149:   //------------------------------------------------------------------------
   150:   //丸めモード
   151:   public static final int EPB_MODE_RN = 0;  //To nearest
   152:   public static final int EPB_MODE_RZ = 1;  //Toward zero
   153:   public static final int EPB_MODE_RM = 2;  //Toward minus infinity
   154:   public static final int EPB_MODE_RP = 3;  //Toward plus infinity
   155:   public int epbRoundingMode;  //丸めモード
   156: 
   157:   //------------------------------------------------------------------------
   158:   //例外オペランド
   159:   //  例外発生時のオペランド
   160:   //  MC68060のステートフレームに書き込まれる
   161:   //  MC68060UM 6.7 FLOATING-POINT STATE FRAMESを参照
   162:   //  BSUN
   163:   //    不定
   164:   //  SNAN/OPERR/DZ
   165:   //    ソースオペランド
   166:   //  OVFL
   167:   //    中間結果。ただし指数部のバイアスが$3FFFではなくて$3FFF-$6000になる。それでも収まらなければ$0
   168:   //  UNFL
   169:   //    中間結果。ただし指数部のバイアスが$3FFFではなくて$3FFF+$6000になる。それでも収まらなければ$0
   170:   //  INEX
   171:   //    INEX単独では不定。他の例外もあればそれに従う
   172:   public int epbExceptionOperandExponent;  //extendedの指数部<<16
   173:   public long epbExceptionOperandMantissa;  //extendedの仮数部
   174:   public int epbExceptionStatusWord;  //MC68060の浮動小数点ステートフレームのステータスワード
   175: 
   176:   //------------------------------------------------------------------------
   177:   //内部丸め
   178:   //  関数が内部で他の関数を複数回呼び出すとき、途中の計算を最大精度で行うため一時的に丸め桁数と丸めモードを変更する
   179:   //  同じEFPBoxのインスタンスを複数のスレッドで同時に使用すると誤動作する可能性がある
   180:   public int epbRoundingDepth;  //深さ
   181:   public int epbRoundingOuterPrec;  //epbRoundingDepth==0のときのepbRoundingPrec
   182:   public int epbRoundingOuterMode;  //epbRoundingDepth==0のときのepbRoundingMode
   183: 
   184:   //------------------------------------------------------------------------
   185:   //レジスタ
   186:   public static final int EPB_SRC_TMP = 8;  //ソース用テンポラリレジスタ
   187:   public static final int EPB_DST_TMP = 9;  //デスティネーション用テンポラリレジスタ
   188:   public static final int EPB_CONST_START = 10;  //定数レジスタ0
   189:   public EFP[] epbFPn;  //浮動小数点レジスタ
   190: 
   191:   //------------------------------------------------------------------------
   192:   //定数
   193:   public static final HashMap<String,Integer> epbConstLongMap = new HashMap<String,Integer> ();  //ロング定数
   194:   static {
   195:     //IOCSコール名(0x00~0xff)
   196:     for (int i = 0; i < Disassembler.DIS_IOCS_NAME.length; i++) {
   197:       String name = Disassembler.DIS_IOCS_NAME[i];
   198:       if (name.length () > 0) {
   199:         epbConstLongMap.put (name.toLowerCase (), i);
   200:       }
   201:     }
   202:     //SXコール名(0xa000~0xa7ff)
   203:     for (int i = 0; i < Disassembler.DIS_SXCALL_NAME.length; i++) {
   204:       String name = Disassembler.DIS_SXCALL_NAME[i];
   205:       if (name.length () > 0) {
   206:         epbConstLongMap.put (name.toLowerCase (), 0xa000 + i);
   207:       }
   208:     }
   209:     //FEファンクションコール名(0xfe00~0xfeff)
   210:     for (int i = 0; i < Disassembler.DIS_FPACK_NAME.length; i++) {
   211:       String name = Disassembler.DIS_FPACK_NAME[i];
   212:       if (name.length () > 0) {
   213:         epbConstLongMap.put (name.toLowerCase (), 0xfe00 + i);
   214:       }
   215:     }
   216:     //DOSコール名(0xff00~0xffff)
   217:     for (int i = 0; i < Disassembler.DIS_DOS_NAME.length; i++) {
   218:       String name = Disassembler.DIS_DOS_NAME[i];
   219:       if (name.length () > 0) {
   220:         epbConstLongMap.put (name.toLowerCase (), 0xff00 + i);
   221:       }
   222:     }
   223:   }  //static
   224: 
   225:   //------------------------------------------------------------------------
   226:   //コンストラクタ
   227:   public EFPBox () {
   228:     //モード
   229:     epbMode = EPB_MODE_EXTENDED | EPB_MODE_MC68882;  //拡張精度、MC68882
   230:     //乱数
   231:     //epbRandSeed = 25214903917L;  //乱数の種(48bit)
   232:     epbRandSeed = System.currentTimeMillis () & (1L << 48) - 1L;  //乱数の種(48bit)
   233:     //浮動小数点レジスタ
   234:     epbFPn = new EFPBox.EFP[EPB_CONST_START + 128];  //FPn。[0]~[7]は汎用、[8]~[9]はテンポラリ、[10]~[137]は定数
   235:     for (int i = 0; i < epbFPn.length; i++) {
   236:       epbFPn[i] = new EFP ();
   237:     }
   238:     //定数
   239:     //  FMOVECRはFPCRのrounding precisionとrounding modeの影響を受ける
   240:     //    使用時に丸める場合は定数を予めextendedに丸めた状態で格納してはならない
   241:     //    rounding modeとrounding precisionのすべての組み合わせを展開しておいて定数の開始インデックスで区別する方法もある
   242:     //  060turboのROMはFMOVECR.X #$01,FP0の結果が0かどうかで68881と68882を見分けている
   243:     epbFPn[EPB_CONST_START + 0x00].sete (PI);       //0x00  pi
   244:     epbSetROMSub ();  //ROMオフセット0x01~0x0aを設定する
   245:     epbFPn[EPB_CONST_START + 0x0b].sete (LOG10_2);  //0x0b  log10(2)    MC68882はRNの値が間違っている
   246:     epbFPn[EPB_CONST_START + 0x0c].sete (E);        //0x0c  e           MC68882はRNの値が間違っている
   247:     epbFPn[EPB_CONST_START + 0x0d].sete (LOG2_E);   //0x0d  log2(e)
   248:     epbFPn[EPB_CONST_START + 0x0e].sete (LOG10_E);  //0x0e  log10(e)    MC68882はRPの値が間違っている。MC68882はINEX2がセットされない
   249:     epbFPn[EPB_CONST_START + 0x0f].set0 ();         //0x0f  0
   250:     epbFPn[EPB_CONST_START + 0x30].sete (LOG_2);    //0x30  log(2)
   251:     epbFPn[EPB_CONST_START + 0x31].sete (LOG_10);   //0x31  log(10)
   252:     epbFPn[EPB_CONST_START + 0x32].set1 ();         //0x32  1
   253:     epbFPn[EPB_CONST_START + 0x33].sete (TEN);      //0x33  10
   254:     epbFPn[EPB_CONST_START + 0x34].sete (TENXP1);   //0x34  10^(2^1)=10^2=100
   255:     epbFPn[EPB_CONST_START + 0x35].sete (TENXP2);   //0x35  10^(2^2)=10^4=10000
   256:     epbFPn[EPB_CONST_START + 0x36].sete (TENXP3);   //0x36  10^(2^3)=10^8=100000000
   257:     epbFPn[EPB_CONST_START + 0x37].sete (TENXP4);   //0x37  10^(2^4)=10^16
   258:     epbFPn[EPB_CONST_START + 0x38].sete (TENXP5);   //0x38  10^(2^5)=10^32
   259:     epbFPn[EPB_CONST_START + 0x39].sete (TENXP6);   //0x39  10^(2^6)=10^64
   260:     epbFPn[EPB_CONST_START + 0x3a].sete (TENXP7);   //0x3a  10^(2^7)=10^128
   261:     epbFPn[EPB_CONST_START + 0x3b].sete (TENXP8);   //0x3b  10^(2^8)=10^256
   262:     epbFPn[EPB_CONST_START + 0x3c].sete (TENXP9);   //0x3c  10^(2^9)=10^512
   263:     epbFPn[EPB_CONST_START + 0x3d].sete (TENXP10);  //0x3d  10^(2^10)=10^1024
   264:     epbFPn[EPB_CONST_START + 0x3e].sete (TENXP11);  //0x3e  10^(2^11)=10^2048
   265:     epbFPn[EPB_CONST_START + 0x3f].sete (TENXP12);  //0x3f  10^(2^12)=10^4096
   266:     //その他
   267:     epbReset ();
   268:     //コプロセッサインタフェイス
   269:     cirInit ();
   270:   }
   271: 
   272:   //epbSetROMSub ()
   273:   //  ROMオフセット0x01~0x0aを設定する
   274:   public final void epbSetROMSub () {
   275:     if ((epbMode & EPB_MODE_MC68882) != 0) {  //MC68882、フルスペック
   276:       epbFPn[EPB_CONST_START + 0x01].setx012 (0x40010000, 0xfe00068200000000L);  //0x01 (MC68882)
   277:       epbFPn[EPB_CONST_START + 0x02].setx012 (0x40010000, 0xffc0050380000000L);  //0x02 (MC68882)
   278:       //epbFPn[EPB_CONST_START + 0x03].setx012 (0x20000000, 0x7fffffff00000000L);  //0x03 (MC68882) Nがセットされる。表現できないのでNaNにする
   279:       epbFPn[EPB_CONST_START + 0x03].setnan ();
   280:       epbFPn[EPB_CONST_START + 0x04].setx012 (0x00000000, 0xffffffffffffffffL);  //0x04 (MC68882)
   281:       epbFPn[EPB_CONST_START + 0x05].setx012 (0x3c000000, 0xfffffffffffff800L);  //0x05 (MC68882)
   282:       epbFPn[EPB_CONST_START + 0x06].setx012 (0x3f800000, 0xffffff0000000000L);  //0x06 (MC68882)
   283:       //epbFPn[EPB_CONST_START + 0x07].setx012 (0x00010000, 0xf65d8d9c00000000L);  //0x07 (MC68882) Nがセットされる。表現できないのでNaNにする
   284:       epbFPn[EPB_CONST_START + 0x07].setnan ();
   285:       //epbFPn[EPB_CONST_START + 0x08].setx012 (0x7fff0000, 0x401e000000000000L);  //0x08 (MC68882) Nがセットされる。表現できないのでNaNにする
   286:       epbFPn[EPB_CONST_START + 0x08].setnan ();
   287:       epbFPn[EPB_CONST_START + 0x09].setx012 (0x43f30000, 0xe000000000000000L);  //0x09 (MC68882)
   288:       epbFPn[EPB_CONST_START + 0x0a].setx012 (0x40720000, 0xc000000000000000L);  //0x0a (MC68882)
   289:     } else {  //MC68881、MC68060
   290:       for (int offset = 0x01; offset <= 0x0a; offset++) {
   291:         epbFPn[EPB_CONST_START + offset].set0 ();
   292:       }
   293:     }
   294:   }  //epbSetROMSub(int)
   295: 
   296:   //epbFmovecr (x, offset)
   297:   //  FMOVECRの下請け
   298:   //  レジスタにROMの定数をコピーしてFPSRのコンディションコードバイトとエクセプションバイトを更新する
   299:   public void epbFmovecr (EFP x, int offset) {
   300:     //特別な場合を処理する
   301:     switch (offset) {
   302:     case 0x01:
   303:       if ((epbMode & EPB_MODE_MC68882) != 0) {  //MC68882、フルスペック
   304:         if (epbRoundingPrec == EPB_PREC_SGL) {
   305:           if (epbRoundingMode == EPB_MODE_RN ||
   306:               epbRoundingMode == EPB_MODE_RZ ||
   307:               epbRoundingMode == EPB_MODE_RM) {
   308:             //x.setx012 (0x40010000, 0xfe00068000000000L);
   309:             x.flg = P;
   310:             x.epp = 0x4001 - 0x3fff;
   311:             x.dvl = 0xfe00068000000000L;
   312:             x.cvl = 0L;
   313:             epbFpsr = epbFpsr & 0x00ff00ff | EPB_FPSR_X2;
   314:             return;
   315:           }
   316:         }
   317:       }
   318:       break;
   319:     case 0x02:
   320:       if ((epbMode & EPB_MODE_MC68882) != 0) {  //MC68882、フルスペック
   321:         if (epbRoundingPrec == EPB_PREC_SGL) {
   322:           if (epbRoundingMode == EPB_MODE_RP) {
   323:             //x.setx012 (0x40010000, 0xffc0058000000000L);
   324:             x.flg = P;
   325:             x.epp = 0x4001 - 0x3fff;
   326:             x.dvl = 0xffc0058000000000L;
   327:             x.cvl = 0L;
   328:             epbFpsr = epbFpsr & 0x00ff00ff | EPB_FPSR_X2;
   329:             return;
   330:           }
   331:         }
   332:       }
   333:       break;
   334:     case 0x03:
   335:       if ((epbMode & EPB_MODE_MC68882) != 0) {  //MC68882、フルスペック
   336:         if (epbRoundingPrec == EPB_PREC_SGL) {
   337:           if (epbRoundingMode == EPB_MODE_RN ||
   338:               epbRoundingMode == EPB_MODE_RP) {
   339:             //x.setx012 (0x20000000, 0x8000000000000000L);
   340:             x.flg = P;
   341:             x.epp = 0x2000 - 0x3fff;
   342:             x.dvl = 0x8000000000000000L;
   343:             x.cvl = 0L;
   344:             epbFpsr = epbFpsr & 0x00ff00ff | EPB_FPSR_I | EPB_FPSR_X2;
   345:           } else {
   346:             //x.setx012 (0x20000000, 0x7fffff0000000000L);
   347:             x.flg = P;
   348:             x.epp = 0x2000 - 0x3fff;
   349:             x.dvl = 0x7fffff0000000000L;
   350:             x.cvl = 0L;
   351:             epbFpsr = epbFpsr & 0x00ff00ff | EPB_FPSR_N | EPB_FPSR_X2;
   352:           }
   353:         } else {
   354:           //x.setx012 (0x20000000, 0x7fffffff00000000L);
   355:           x.flg = P;
   356:           x.epp = 0x2000 - 0x3fff;
   357:           x.dvl = 0x7fffffff00000000L;
   358:           x.cvl = 0L;
   359:           epbFpsr = epbFpsr & 0x00ff00ff | EPB_FPSR_N;
   360:         }
   361:         return;
   362:       }
   363:       break;
   364:     case 0x07:
   365:       if ((epbMode & EPB_MODE_MC68882) != 0) {  //MC68882、フルスペック
   366:         if (epbRoundingPrec == EPB_PREC_SGL) {
   367:           if (epbRoundingMode == EPB_MODE_RN ||
   368:               epbRoundingMode == EPB_MODE_RZ ||
   369:               epbRoundingMode == EPB_MODE_RM) {
   370:             //x.setx012 (0x00010000, 0xf65d8d8000000000L);
   371:             x.flg = P;
   372:             x.epp = 0x0001 - 0x3fff;
   373:             x.dvl = 0xf65d8d8000000000L;
   374:             x.cvl = 0L;
   375:             epbFpsr = epbFpsr & 0x00ff00ff | EPB_FPSR_N | EPB_FPSR_X2;
   376:           } else {
   377:             //x.setx012 (0x00010000, 0xf65d8e0000000000L);
   378:             x.flg = P;
   379:             x.epp = 0x0001 - 0x3fff;
   380:             x.dvl = 0xf65d8e0000000000L;
   381:             x.cvl = 0L;
   382:             epbFpsr = epbFpsr & 0x00ff00ff | EPB_FPSR_N | EPB_FPSR_X2;
   383:           }
   384:         } else {
   385:           //x.setx012 (0x00010000, 0xf65d8d9c00000000L);
   386:           x.flg = P;
   387:           x.epp = 0x0001 - 0x3fff;
   388:           x.dvl = 0xf65d8d9c00000000L;
   389:           x.cvl = 0L;
   390:           epbFpsr = epbFpsr & 0x00ff00ff | EPB_FPSR_N;
   391:         }
   392:         return;
   393:       }
   394:       break;
   395:     case 0x08:
   396:       if ((epbMode & EPB_MODE_MC68882) != 0) {  //MC68882、フルスペック
   397:         //x.setx012 (0x7fff0000, 0x401e000000000000L);
   398:         x.flg = N;
   399:         x.epp = 0;
   400:         x.dvl = 0L;
   401:         x.cvl = 0L;
   402:         epbFpsr = epbFpsr & 0x00ff00ff | EPB_FPSR_N;
   403:         return;
   404:       }
   405:       break;
   406:     case 0x0b:
   407:       if (epbRoundingPrec == EPB_PREC_EXD) {
   408:         if (epbRoundingMode == EPB_MODE_RN) {
   409:           //x.setx012 (0x3ffd0000, 0x9a209a84fbcff798L);
   410:           x.flg = P;
   411:           x.epp = 0x3ffd - 0x3fff;
   412:           x.dvl = 0x9a209a84fbcff798L;
   413:           x.cvl = 0L;
   414:           epbFpsr = epbFpsr & 0x00ff00ff | EPB_FPSR_X2;
   415:           return;
   416:         }
   417:       }
   418:       break;
   419:     case 0x0c:
   420:       if (epbRoundingPrec == EPB_PREC_EXD) {
   421:         if (epbRoundingMode == EPB_MODE_RN) {
   422:           //x.setx012 (0x40000000, 0xadf85458a2bb4a9aL);
   423:           x.flg = P;
   424:           x.epp = 0x4000 - 0x3fff;
   425:           x.dvl = 0xadf85458a2bb4a9aL;
   426:           x.cvl = 0L;
   427:           epbFpsr = epbFpsr & 0x00ff00ff | EPB_FPSR_X2;
   428:           return;
   429:         }
   430:       }
   431:       break;
   432:     case 0x0e:
   433:       if (epbRoundingPrec == EPB_PREC_EXD) {
   434:         //x.setx012 (0x3ffd0000, 0xde5bd8a937287195L);
   435:         x.flg = P;
   436:         x.epp = 0x3ffd - 0x3fff;
   437:         x.dvl = 0xde5bd8a937287195L;
   438:         x.cvl = 0L;
   439:         epbFpsr = epbFpsr & 0x00ff00ff;
   440:         return;
   441:       }
   442:       break;
   443:     }
   444:     //ROMからコピーする
   445:     x.sete (epbFPn[EPB_CONST_START + offset]);
   446:     //FPSRのコンディションコードバイトを設定してエクセプションバイトをクリアする
   447:     epbFpsr = epbFpsr & 0x00ff00ff | x.flg >>> 4;
   448:     //仮数部を丸める。X2がセットされる
   449:     if (epbRoundingPrec == EPB_PREC_EXD) {
   450:       x.roundmanx (epbRoundingMode);
   451:     } else if (epbRoundingPrec == EPB_PREC_SGL) {
   452:       x.roundmanf (epbRoundingMode);
   453:     } else if (epbRoundingPrec == EPB_PREC_DBL ||
   454:                epbRoundingPrec == EPB_PREC_DBL3) {
   455:       x.roundmand (epbRoundingMode);
   456:     } else if (epbRoundingPrec == EPB_PREC_TPL) {
   457:       x.roundmany (epbRoundingMode);
   458:     }
   459:   }  //epbFmovecr(EFP,int)
   460: 
   461:   //epbSetMC68881 ()
   462:   //  MC68881モード
   463:   public void epbSetMC68881 () {
   464:     epbMode = epbMode & ~(EPB_MODE_MC68882 | EPB_MODE_MC68060) | EPB_MODE_MC68881;
   465:     epbSetROMSub ();
   466:   }  //epbSetMC68881()
   467: 
   468:   //epbSetMC68882 ()
   469:   //  MC68882モード
   470:   public void epbSetMC68882 () {
   471:     epbMode = epbMode & ~(EPB_MODE_MC68881 | EPB_MODE_MC68060) | EPB_MODE_MC68882;
   472:     epbSetROMSub ();
   473:   }  //epbSetMC68882()
   474: 
   475:   //epbSetMC68060 ()
   476:   //  MC68060モード
   477:   public void epbSetMC68060 () {
   478:     epbMode = epbMode & ~(EPB_MODE_MC68881 | EPB_MODE_MC68882) | EPB_MODE_MC68060;
   479:     epbSetROMSub ();
   480:   }  //epbSetMC68060()
   481: 
   482:   //epbSetFullSpec ()
   483:   //  フルスペックモード
   484:   public void epbSetFullSpec () {
   485:     epbMode |= EPB_MODE_FULLSPEC;
   486:     epbSetROMSub ();
   487:   }  //epbSetFullSpec()
   488: 
   489:   //epbIsFullSpec ()
   490:   //  フルスペックモードか
   491:   public boolean epbIsFullSpec () {
   492:     return (epbMode & EPB_MODE_FULLSPEC) == EPB_MODE_FULLSPEC;
   493:   }  //epbIsFullSpec()
   494: 
   495:   //epbSetExtended ()
   496:   //  拡張精度モード
   497:   public void epbSetExtended () {
   498:     epbMode = epbMode & ~EPB_MODE_TRIPLE | EPB_MODE_EXTENDED;
   499:   }  //epbSetExtended()
   500: 
   501:   //epbSetTriple ()
   502:   //  三倍精度モード
   503:   public void epbSetTriple () {
   504:     epbMode = epbMode & ~EPB_MODE_EXTENDED | EPB_MODE_TRIPLE;
   505:   }  //epbSetTriple()
   506: 
   507:   //epbIsTriple ()
   508:   //  三倍精度モードか
   509:   public boolean epbIsTriple () {
   510:     return (epbMode & EPB_MODE_TRIPLE) != 0;
   511:   }  //epbIsTriple()
   512: 
   513:   //epbReset ()
   514:   //  リセット
   515:   public final void epbReset () {
   516:     //浮動小数点汎用レジスタ
   517:     for (int n = 0; n < 8; n++) {
   518:       epbFPn[n].setnan ();  //ヌルステートをFRESTOREするとNon-signaling NaNになるのでそれに合わせる
   519:     }
   520:     //浮動小数点制御レジスタ
   521:     epbFpcr = 0;
   522:     epbFpsr = 0;
   523:     epbFpiar = 0;
   524:     epbQuotient = 0;
   525:     epbRoundingPrec = EPB_PREC_EFP;
   526:     epbRoundingMode = EPB_MODE_RN;
   527:     epbRoundingDepth = 0;
   528:     epbRoundingOuterPrec = EPB_PREC_EFP;
   529:     epbRoundingOuterMode = EPB_MODE_RN;
   530:     //浮動小数点例外
   531:     epbExceptionOperandExponent = 0;
   532:     epbExceptionOperandMantissa = 0x0000000000000000L;
   533:     epbExceptionStatusWord = 0;
   534:     //コプロセッサインタフェイス
   535:     cirReset ();
   536:   }
   537: 
   538:   //epbSetRoundingPrec (prec)
   539:   //  丸め桁数を設定する
   540:   //  precはEPB_PREC_EXD,EPB_PREC_SGL,EPB_PREC_DBL,EPB_PREC_DBL3,EPB_PREC_XSGのいずれか
   541:   //  三倍精度が選択されているときEPB_PREC_EXDをEPB_PREC_TPLに読み替える
   542:   public void epbSetRoundingPrec (int prec) {
   543:     epbRoundingPrec = prec == EPB_PREC_EXD && (epbMode & EPB_MODE_TRIPLE) != 0 ? EPB_PREC_TPL : prec;
   544:   }  //epbSetRoundingPrec(int)
   545: 
   546:   //epbSetRoundingMode (mode)
   547:   //  丸めモードを設定する
   548:   //  modeはEPB_MODE_RN,EPB_MODE_RZ,EPB_MODE_RM,EPB_MODE_RPのいずれか
   549:   public void epbSetRoundingMode (int mode) {
   550:     epbRoundingMode = mode;
   551:   }  //epbSetRoundingMode(int)
   552: 
   553:   //------------------------------------------------------------------------
   554:   //乱数ジェネレータ
   555:   //  java.util.Randomと同じ線形合同法を用いる
   556:   public long epbRandSeed;
   557: 
   558:   //epbRandStart (n)
   559:   //  乱数列の初期化
   560:   public void epbRandStart (long n) {
   561:     epbRandSeed = (n ^ 25214903917L) & (1L << 48) - 1L;
   562:   }  //epbRandStart(long)
   563: 
   564:   //l = epbRand48 ()
   565:   //  48bit乱数の取得
   566:   public long epbRand48 () {
   567:     return epbRandSeed = epbRandSeed * 25214903917L + 11L & (1L << 48) - 1L;
   568:   }  //epbRand48()
   569: 
   570:   //i = epbRandInt ()
   571:   //  int乱数の取得
   572:   public int epbRandInt () {
   573:     return (int) (epbRand48 () >>> 16);
   574:   }  //epbRandInt()
   575: 
   576:   //l = epbRandLong ()
   577:   //  long乱数の取得
   578:   public long epbRandLong () {
   579:     return epbRand48 () >>> 16 << 32 | epbRand48 () >>> 16;
   580:   }  //epbRandLong()
   581: 
   582:   //------------------------------------------------------------------------
   583:   //epbMakeCmpTable ()
   584:   //  cmp,compare,eq,ge,gt,le,lt,neで引数のどちらかが±0,±Inf,NaNの場合の結果を求めるためのテーブルを作る
   585:   public static void epbMakeCmpTable () {
   586:     int[] fa = new int[] {
   587:       P | Z,
   588:       M | Z,
   589:       P | I,
   590:       M | I,
   591:       N,
   592:       P,
   593:       M,
   594:     };
   595:     double[] da = new double[] {
   596:       +0.0,
   597:       -0.0,
   598:       Double.POSITIVE_INFINITY,
   599:       Double.NEGATIVE_INFINITY,
   600:       Double.NaN,
   601:       +1.0,
   602:       -1.0,
   603:     };
   604:     String[] na = { "CMP", "COMPARE", "EQ", "GE", "GT", "LE", "LT", "NE" };
   605:     int[][] ba = new int[na.length][];
   606:     for (int j = 0; j < na.length; j++) {
   607:       ba[j] = new int[16];
   608:     }
   609:     for (int xi = 0; xi < fa.length; xi++) {
   610:       int xk = fa[xi] >>> 28;
   611:       double x = da[xi];
   612:       for (int yi = 0; yi < fa.length; yi++) {
   613:         int yk = fa[yi] >>> 28 - 1;
   614:         double y = da[yi];
   615:         ba[0][xk] |= (Double.isNaN (x) || Double.isNaN (y) || x == y ? 0 : x < y ? -1 : 1) << 30 >>> yk;  //cmp
   616:         ba[1][xk] |= Double.compare (x, y) << 30 >>> yk;  //compare
   617:         ba[2][xk] |= (x == y ? -1 : 0) << 30 >>> yk;  //eq
   618:         ba[3][xk] |= (x >= y ? -1 : 0) << 30 >>> yk;  //ge
   619:         ba[4][xk] |= (x > y ? -1 : 0) << 30 >>> yk;  //gt
   620:         ba[5][xk] |= (x <= y ? -1 : 0) << 30 >>> yk;  //le
   621:         ba[6][xk] |= (x < y ? -1 : 0) << 30 >>> yk;  //lt
   622:         ba[7][xk] |= (x != y ? -1 : 0) << 30 >>> yk;  //ne
   623:       }
   624:     }
   625:     for (int ni = 0; ni < na.length; ni++) {
   626:       System.out.print ("    protected static final int[] EFP_" + na[ni] + "_TABLE = { ");
   627:       for (int xk = 0; xk < 16; xk++) {
   628:         System.out.print (ba[ni][xk]);
   629:         if (xk < 16 - 1) {
   630:           System.out.print (", ");
   631:         }
   632:       }
   633:       System.out.println (" };");
   634:     }
   635:   }  //epbMakeCmpTable()
   636: 
   637:   //------------------------------------------------------------------------
   638:   //  cmp,compare,eq,ge,gt,le,lt,neで引数のどちらかが±0,±Inf,NaNの場合の結果を求めるためのテーブル
   639:   public static final int[] EFP_CMP_TABLE = { 205538368, 0, 1077953600, 0, -872397824, 0, 0, 0, -859831104, 0, -859782976, 0, -872397824, 0, 0, 0 };
   640:   public static final int[] EFP_COMPARE_TABLE = { 1010844736, 1145062464, 1883259968, 0, -67091392, 0, 0, 0, -54524736, 0, -54476608, 0, -54508544, 0, 0, 0 };
   641:   public static final int[] EFP_EQ_TABLE = { -1073741824, 0, 201326592, 0, 12583104, 0, 0, 0, 49152, 0, 3072, 0, 12583104, 0, 0, 0 };
   642:   public static final int[] EFP_GE_TABLE = { -1061106496, 0, -859779904, 0, 12635328, 0, 0, 0, 52224, 0, 3072, 0, 12635328, 0, 0, 0 };
   643:   public static final int[] EFP_GT_TABLE = { 12635328, 0, -1061106496, 0, 52224, 0, 0, 0, 3072, 0, 0, 0, 52224, 0, 0, 0 };
   644:   public static final int[] EFP_LE_TABLE = { -872415232, 0, 201326592, 0, -859832128, 0, 0, 0, -859782976, 0, -859779904, 0, -859832128, 0, 0, 0 };
   645:   public static final int[] EFP_LT_TABLE = { 201326592, 0, 0, 0, -872415232, 0, 0, 0, -859832128, 0, -859782976, 0, -872415232, 0, 0, 0 };
   646:   public static final int[] EFP_NE_TABLE = { 1019268288, -54473536, -255800128, 0, -67056640, 0, 0, 0, -54522688, 0, -54476608, 0, -67056640, 0, 0, 0 };
   647: 
   648:   //------------------------------------------------------------------------
   649:   //定数
   650:   //  すべてのEFP定数は内部コンストラクタnew EFP(xf,xe,xd,xc)で構築しなければならない
   651:   //  公開コンストラクタは丸めの処理が入るので定数の構築には使用できない
   652:   public final EFP     ZERO = new EFP (P | Z, 0, 0L, 0L);  //+0
   653:   public final EFP  NEGZERO = new EFP (M | Z, 0, 0L, 0L);  //-0
   654:   public final EFP      INF = new EFP (P | I, 0, 0L, 0L);  //+Inf
   655:   public final EFP   NEGINF = new EFP (M | I, 0, 0L, 0L);  //-Inf
   656:   public final EFP      NAN = new EFP (    N, 0, 0L, 0L);  //NaN
   657: 
   658:   //------------------------------------------------------------------------
   659:   //範囲
   660:   //  echo read("efp.gp");efppub(["EXDNOMAX",EXDNOMAX],["EXDDEMIN",EXDDEMIN],["NEGEXDDEMIN",-EXDDEMIN],["NEGEXDNOMAX",-EXDNOMAX],["SGLNOMAX",SGLNOMAX],["SGLDEMIN",SGLDEMIN],["NEGSGLDEMIN",-SGLDEMIN],["NEGSGLNOMAX",-SGLNOMAX],["DBLNOMAX",DBLNOMAX],["DBLDEMIN",DBLDEMIN],["NEGDBLDEMIN",-DBLDEMIN],["NEGDBLNOMAX",-DBLNOMAX],["TPLNOMAX",TPLNOMAX],["TPLDEMIN",TPLDEMIN],["NEGTPLDEMIN",-TPLDEMIN],["NEGTPLNOMAX",-TPLNOMAX],["XSGNOMAX",XSGNOMAX],["XSGDEMIN",XSGDEMIN],["NEGXSGDEMIN",-XSGDEMIN],["NEGXSGNOMAX",-XSGNOMAX],["EFPNOMAX",EFPNOMAX],["EFPDEMIN",eval("2^-32768")],["NEGEFPDEMIN",eval("-2^-32768")],["NEGEFPNOMAX",-EFPNOMAX]) | gp -q
   661:   public final EFP     EXDNOMAX = new EFP (P,  16383, 0xffffffffffffffffL, 0x0000000L << 36);  //=1.18973149535723176502126385303e+4932
   662:   public final EFP     EXDDEMIN = new EFP (P, -16446, 0x8000000000000000L, 0x0000000L << 36);  //=1.82259976594123730126420296681e-4951
   663:   public final EFP  NEGEXDDEMIN = new EFP (M, -16446, 0x8000000000000000L, 0x0000000L << 36);  //=-1.82259976594123730126420296681e-4951
   664:   public final EFP  NEGEXDNOMAX = new EFP (M,  16383, 0xffffffffffffffffL, 0x0000000L << 36);  //=-1.18973149535723176502126385303e+4932
   665:   public final EFP     SGLNOMAX = new EFP (P,    127, 0xffffff0000000000L, 0x0000000L << 36);  //=3.40282346638528859811704183485e+38
   666:   public final EFP     SGLDEMIN = new EFP (P,   -149, 0x8000000000000000L, 0x0000000L << 36);  //=1.40129846432481707092372958329e-45
   667:   public final EFP  NEGSGLDEMIN = new EFP (M,   -149, 0x8000000000000000L, 0x0000000L << 36);  //=-1.40129846432481707092372958329e-45
   668:   public final EFP  NEGSGLNOMAX = new EFP (M,    127, 0xffffff0000000000L, 0x0000000L << 36);  //=-3.40282346638528859811704183485e+38
   669:   public final EFP     DBLNOMAX = new EFP (P,   1023, 0xfffffffffffff800L, 0x0000000L << 36);  //=1.79769313486231570814527423732e+308
   670:   public final EFP     DBLDEMIN = new EFP (P,  -1074, 0x8000000000000000L, 0x0000000L << 36);  //=4.94065645841246544176568792868e-324
   671:   public final EFP  NEGDBLDEMIN = new EFP (M,  -1074, 0x8000000000000000L, 0x0000000L << 36);  //=-4.94065645841246544176568792868e-324
   672:   public final EFP  NEGDBLNOMAX = new EFP (M,   1023, 0xfffffffffffff800L, 0x0000000L << 36);  //=-1.79769313486231570814527423732e+308
   673:   public final EFP     TPLNOMAX = new EFP (P,  16383, 0xffffffffffffffffL, 0xffff000L << 36);  //=1.18973149535723176508575834251e+4932
   674:   public final EFP     TPLDEMIN = new EFP (P, -16462, 0x8000000000000000L, 0x0000000L << 36);  //=2.78106653738592117502472376527e-4956
   675:   public final EFP  NEGTPLDEMIN = new EFP (M, -16462, 0x8000000000000000L, 0x0000000L << 36);  //=-2.78106653738592117502472376527e-4956
   676:   public final EFP  NEGTPLNOMAX = new EFP (M,  16383, 0xffffffffffffffffL, 0xffff000L << 36);  //=-1.18973149535723176508575834251e+4932
   677:   public final EFP     XSGNOMAX = new EFP (P,  16383, 0xffffff0000000000L, 0x0000000L << 36);  //=1.18973142444370860622365937597e+4932
   678:   public final EFP     XSGDEMIN = new EFP (P, -16406, 0x8000000000000000L, 0x0000000L << 36);  //=2.00396963543420642987649310668e-4939
   679:   public final EFP  NEGXSGDEMIN = new EFP (M, -16406, 0x8000000000000000L, 0x0000000L << 36);  //=-2.00396963543420642987649310668e-4939
   680:   public final EFP  NEGXSGNOMAX = new EFP (M,  16383, 0xffffff0000000000L, 0x0000000L << 36);  //=-1.18973142444370860622365937597e+4932
   681:   public final EFP     EFPNOMAX = new EFP (P,  32767, 0xffffffffffffffffL, 0xfffffffL << 36);  //=1.41546103104495478900155302746e+9864
   682:   public final EFP     EFPDEMIN = new EFP (P, -32768, 0x8000000000000000L, 0x0000000L << 36);  //=7.06483596557763644277740218786e-9865
   683:   public final EFP  NEGEFPDEMIN = new EFP (M, -32768, 0x8000000000000000L, 0x0000000L << 36);  //=-7.06483596557763644277740218786e-9865
   684:   public final EFP  NEGEFPNOMAX = new EFP (M,  32767, 0xffffffffffffffffL, 0xfffffffL << 36);  //=-1.41546103104495478900155302746e+9864
   685: 
   686:   //------------------------------------------------------------------------
   687:   //オーバーフローの値
   688:   //  指数部が大きくなりすぎたときのオーバーフローの値はいつも±Infというわけではなく丸め桁数と丸めモードと符号によって変化する
   689:   //  端数に関係なく±0に近付く方向に丸めるときは±Infではなく絶対値が最大の正規化数を返す
   690:   //  絶対値が最大の正規化数は丸め桁数によって異なる
   691:   //  XSGはアンダーフローしたときは±XSGDEMINだがオーバーフローしたときは±EXDNOMAXになる
   692:   //  OVFL_RESULTS[epbRoundingPrec << 3 | epbRoundingMode << 1 | flg >>> 31]
   693:   //  inner()~outer()の内側ではepbRoundingPrecが効かないことに注意する
   694:   public final EFP[] OVFL_RESULTS = new EFP[] {
   695:     INF,          //EPB_PREC_EXD,EPB_MODE_RN,+
   696:     NEGINF,       //EPB_PREC_EXD,EPB_MODE_RN,-
   697:     EXDNOMAX,     //EPB_PREC_EXD,EPB_MODE_RZ,+
   698:     NEGEXDNOMAX,  //EPB_PREC_EXD,EPB_MODE_RZ,-
   699:     EXDNOMAX,     //EPB_PREC_EXD,EPB_MODE_RM,+
   700:     NEGINF,       //EPB_PREC_EXD,EPB_MODE_RM,-
   701:     INF,          //EPB_PREC_EXD,EPB_MODE_RP,+
   702:     NEGEXDNOMAX,  //EPB_PREC_EXD,EPB_MODE_RP,-
   703:     //
   704:     INF,          //EPB_PREC_SGL,EPB_MODE_RN,+
   705:     NEGINF,       //EPB_PREC_SGL,EPB_MODE_RN,-
   706:     SGLNOMAX,     //EPB_PREC_SGL,EPB_MODE_RZ,+
   707:     NEGSGLNOMAX,  //EPB_PREC_SGL,EPB_MODE_RZ,-
   708:     SGLNOMAX,     //EPB_PREC_SGL,EPB_MODE_RM,+
   709:     NEGINF,       //EPB_PREC_SGL,EPB_MODE_RM,-
   710:     INF,          //EPB_PREC_SGL,EPB_MODE_RP,+
   711:     NEGSGLNOMAX,  //EPB_PREC_SGL,EPB_MODE_RP,-
   712:     //
   713:     INF,          //EPB_PREC_DBL,EPB_MODE_RN,+
   714:     NEGINF,       //EPB_PREC_DBL,EPB_MODE_RN,-
   715:     DBLNOMAX,     //EPB_PREC_DBL,EPB_MODE_RZ,+
   716:     NEGDBLNOMAX,  //EPB_PREC_DBL,EPB_MODE_RZ,-
   717:     DBLNOMAX,     //EPB_PREC_DBL,EPB_MODE_RM,+
   718:     NEGINF,       //EPB_PREC_DBL,EPB_MODE_RM,-
   719:     INF,          //EPB_PREC_DBL,EPB_MODE_RP,+
   720:     NEGDBLNOMAX,  //EPB_PREC_DBL,EPB_MODE_RP,-
   721:     //
   722:     INF,          //EPB_PREC_DBL3,EPB_MODE_RN,+
   723:     NEGINF,       //EPB_PREC_DBL3,EPB_MODE_RN,-
   724:     DBLNOMAX,     //EPB_PREC_DBL3,EPB_MODE_RZ,+
   725:     NEGDBLNOMAX,  //EPB_PREC_DBL3,EPB_MODE_RZ,-
   726:     DBLNOMAX,     //EPB_PREC_DBL3,EPB_MODE_RM,+
   727:     NEGINF,       //EPB_PREC_DBL3,EPB_MODE_RM,-
   728:     INF,          //EPB_PREC_DBL3,EPB_MODE_RP,+
   729:     NEGDBLNOMAX,  //EPB_PREC_DBL3,EPB_MODE_RP,-
   730:     //
   731:     INF,          //EPB_PREC_TPL,EPB_MODE_RN,+
   732:     NEGINF,       //EPB_PREC_TPL,EPB_MODE_RN,-
   733:     TPLNOMAX,     //EPB_PREC_TPL,EPB_MODE_RZ,+
   734:     NEGTPLNOMAX,  //EPB_PREC_TPL,EPB_MODE_RZ,-
   735:     TPLNOMAX,     //EPB_PREC_TPL,EPB_MODE_RM,+
   736:     NEGINF,       //EPB_PREC_TPL,EPB_MODE_RM,-
   737:     INF,          //EPB_PREC_TPL,EPB_MODE_RP,+
   738:     NEGTPLNOMAX,  //EPB_PREC_TPL,EPB_MODE_RP,-
   739:     //
   740:     INF,          //EPB_PREC_XSG,EPB_MODE_RN,+
   741:     NEGINF,       //EPB_PREC_XSG,EPB_MODE_RN,-
   742:     EXDNOMAX,     //EPB_PREC_XSG,EPB_MODE_RZ,+  XSGNOMAX → EXDNOMAX
   743:     NEGEXDNOMAX,  //EPB_PREC_XSG,EPB_MODE_RZ,-  -XSGNOMAX → -EXDNOMAX
   744:     EXDNOMAX,     //EPB_PREC_XSG,EPB_MODE_RM,+  XSGNOMAX→EXDNOMAX
   745:     NEGINF,       //EPB_PREC_XSG,EPB_MODE_RM,-
   746:     INF,          //EPB_PREC_XSG,EPB_MODE_RP,+
   747:     NEGEXDNOMAX,  //EPB_PREC_XSG,EPB_MODE_RP,-  -XSGNOMAX→-EXDNOMAX
   748:     //
   749:     INF,          //EPB_PREC_EFP,EPB_MODE_RN,+
   750:     NEGINF,       //EPB_PREC_EFP,EPB_MODE_RN,-
   751:     EFPNOMAX,     //EPB_PREC_EFP,EPB_MODE_RZ,+
   752:     NEGEFPNOMAX,  //EPB_PREC_EFP,EPB_MODE_RZ,-
   753:     EFPNOMAX,     //EPB_PREC_EFP,EPB_MODE_RM,+
   754:     NEGINF,       //EPB_PREC_EFP,EPB_MODE_RM,-
   755:     INF,          //EPB_PREC_EFP,EPB_MODE_RP,+
   756:     NEGEFPNOMAX,  //EPB_PREC_EFP,EPB_MODE_RP,-
   757:   };
   758: 
   759:   //------------------------------------------------------------------------
   760:   //アンダーフローの値
   761:   //  指数部が小さくなりすぎたときのアンダーフローの値はいつも±0というわけではなく丸め桁数と丸めモードと符号によって変化する
   762:   //  端数に関係なく±0から遠ざかる方向に丸めるときは±0ではなく絶対値が最小の非正規化数を返す
   763:   //  絶対値が最小の非正規化数は丸め桁数によって異なる
   764:   //  XSGはアンダーフローしたときは±XSGDEMINだがオーバーフローしたときは±EXDNOMAXになる
   765:   //  UNFL_RESULTS[epbRoundingPrec << 3 | epbRoundingMode << 1 | flg >>> 31]
   766:   //  inner()~outer()の内側ではepbRoundingPrecが効かないことに注意する
   767:   public final EFP[] UNFL_RESULTS = new EFP[] {
   768:     ZERO,         //EPB_PREC_EXD,EPB_MODE_RN,+
   769:     NEGZERO,      //EPB_PREC_EXD,EPB_MODE_RN,-
   770:     ZERO,         //EPB_PREC_EXD,EPB_MODE_RZ,+
   771:     NEGZERO,      //EPB_PREC_EXD,EPB_MODE_RZ,-
   772:     ZERO,         //EPB_PREC_EXD,EPB_MODE_RM,+
   773:     NEGEXDDEMIN,  //EPB_PREC_EXD,EPB_MODE_RM,-
   774:     EXDDEMIN,     //EPB_PREC_EXD,EPB_MODE_RP,+
   775:     NEGZERO,      //EPB_PREC_EXD,EPB_MODE_RP,-
   776:     //
   777:     ZERO,         //EPB_PREC_SGL,EPB_MODE_RN,+
   778:     NEGZERO,      //EPB_PREC_SGL,EPB_MODE_RN,-
   779:     ZERO,         //EPB_PREC_SGL,EPB_MODE_RZ,+
   780:     NEGZERO,      //EPB_PREC_SGL,EPB_MODE_RZ,-
   781:     ZERO,         //EPB_PREC_SGL,EPB_MODE_RM,+
   782:     NEGSGLDEMIN,  //EPB_PREC_SGL,EPB_MODE_RM,-
   783:     SGLDEMIN,     //EPB_PREC_SGL,EPB_MODE_RP,+
   784:     NEGZERO,      //EPB_PREC_SGL,EPB_MODE_RP,-
   785:     //
   786:     ZERO,         //EPB_PREC_DBL,EPB_MODE_RN,+
   787:     NEGZERO,      //EPB_PREC_DBL,EPB_MODE_RN,-
   788:     ZERO,         //EPB_PREC_DBL,EPB_MODE_RZ,+
   789:     NEGZERO,      //EPB_PREC_DBL,EPB_MODE_RZ,-
   790:     ZERO,         //EPB_PREC_DBL,EPB_MODE_RM,+
   791:     NEGDBLDEMIN,  //EPB_PREC_DBL,EPB_MODE_RM,-
   792:     DBLDEMIN,     //EPB_PREC_DBL,EPB_MODE_RP,+
   793:     NEGZERO,      //EPB_PREC_DBL,EPB_MODE_RP,-
   794:     //
   795:     ZERO,         //EPB_PREC_DBL3,EPB_MODE_RN,+
   796:     NEGZERO,      //EPB_PREC_DBL3,EPB_MODE_RN,-
   797:     ZERO,         //EPB_PREC_DBL3,EPB_MODE_RZ,+
   798:     NEGZERO,      //EPB_PREC_DBL3,EPB_MODE_RZ,-
   799:     ZERO,         //EPB_PREC_DBL3,EPB_MODE_RM,+
   800:     NEGDBLDEMIN,  //EPB_PREC_DBL3,EPB_MODE_RM,-
   801:     DBLDEMIN,     //EPB_PREC_DBL3,EPB_MODE_RP,+
   802:     NEGZERO,      //EPB_PREC_DBL3,EPB_MODE_RP,-
   803:     //
   804:     ZERO,         //EPB_PREC_TPL,EPB_MODE_RN,+
   805:     NEGZERO,      //EPB_PREC_TPL,EPB_MODE_RN,-
   806:     ZERO,         //EPB_PREC_TPL,EPB_MODE_RZ,+
   807:     NEGZERO,      //EPB_PREC_TPL,EPB_MODE_RZ,-
   808:     ZERO,         //EPB_PREC_TPL,EPB_MODE_RM,+
   809:     NEGTPLDEMIN,  //EPB_PREC_TPL,EPB_MODE_RM,-
   810:     TPLDEMIN,     //EPB_PREC_TPL,EPB_MODE_RP,+
   811:     NEGZERO,      //EPB_PREC_TPL,EPB_MODE_RP,-
   812:     //
   813:     ZERO,         //EPB_PREC_XSG,EPB_MODE_RN,+
   814:     NEGZERO,      //EPB_PREC_XSG,EPB_MODE_RN,-
   815:     ZERO,         //EPB_PREC_XSG,EPB_MODE_RZ,+
   816:     NEGZERO,      //EPB_PREC_XSG,EPB_MODE_RZ,-
   817:     ZERO,         //EPB_PREC_XSG,EPB_MODE_RM,+
   818:     NEGXSGDEMIN,  //EPB_PREC_XSG,EPB_MODE_RM,-
   819:     XSGDEMIN,     //EPB_PREC_XSG,EPB_MODE_RP,+
   820:     NEGZERO,      //EPB_PREC_XSG,EPB_MODE_RP,-
   821:     //
   822:     ZERO,         //EPB_PREC_EFP,EPB_MODE_RN,+
   823:     NEGZERO,      //EPB_PREC_EFP,EPB_MODE_RN,-
   824:     ZERO,         //EPB_PREC_EFP,EPB_MODE_RZ,+
   825:     NEGZERO,      //EPB_PREC_EFP,EPB_MODE_RZ,-
   826:     ZERO,         //EPB_PREC_EFP,EPB_MODE_RM,+
   827:     NEGEFPDEMIN,  //EPB_PREC_EFP,EPB_MODE_RM,-
   828:     EFPDEMIN,     //EPB_PREC_EFP,EPB_MODE_RP,+
   829:     NEGZERO,      //EPB_PREC_EFP,EPB_MODE_RP,-
   830:   };
   831: 
   832:   //------------------------------------------------------------------------
   833:   //  ±1に隣接する値
   834:   //    三角関数や双曲線関数で丸めモードによって結果が±1になってはならないのに端数が小さすぎて±1になってしまうことがある
   835:   //    結果を調節するときに使う
   836:   public final EFP[] NEXTDOWN_MINUSONE = {
   837:     //  echo read("efp.gp");efpmem([exdnextdown(-1)],[sglnextdown(-1)],[dblnextdown(-1)],[dblnextdown(-1)],[tplnextdown(-1)],[xsgnextdown(-1)],[efpnextdown(-1)]) | gp -q
   838:     new EFP (M,      0, 0x8000000000000001L, 0x0000000L << 36),  //=-1.00000000000000000010842021725
   839:     new EFP (M,      0, 0x8000010000000000L, 0x0000000L << 36),  //=-1.00000011920928955078125000000
   840:     new EFP (M,      0, 0x8000000000000800L, 0x0000000L << 36),  //=-1.00000000000000022204460492503
   841:     new EFP (M,      0, 0x8000000000000800L, 0x0000000L << 36),  //=-1.00000000000000022204460492503
   842:     new EFP (M,      0, 0x8000000000000000L, 0x0001000L << 36),  //=-1.00000000000000000000000165436
   843:     new EFP (M,      0, 0x8000010000000000L, 0x0000000L << 36),  //=-1.00000011920928955078125000000
   844:     new EFP (M,      0, 0x8000000000000000L, 0x0000001L << 36),  //=-1.00000000000000000000000000040
   845:   };
   846:   public final EFP[] NEXTUP_MINUSONE = {
   847:     //  echo read("efp.gp");efpmem([exdnextup(-1)],[sglnextup(-1)],[dblnextup(-1)],[dblnextup(-1)],[tplnextup(-1)],[xsgnextup(-1)],[efpnextup(-1)]) | gp -q
   848:     new EFP (M,     -1, 0xffffffffffffffffL, 0x0000000L << 36),  //=-0.999999999999999999945789891376
   849:     new EFP (M,     -1, 0xffffff0000000000L, 0x0000000L << 36),  //=-0.999999940395355224609375000000
   850:     new EFP (M,     -1, 0xfffffffffffff800L, 0x0000000L << 36),  //=-0.999999999999999888977697537484
   851:     new EFP (M,     -1, 0xfffffffffffff800L, 0x0000000L << 36),  //=-0.999999999999999888977697537484
   852:     new EFP (M,     -1, 0xffffffffffffffffL, 0xffff000L << 36),  //=-0.999999999999999999999999172819
   853:     new EFP (M,     -1, 0xffffff0000000000L, 0x0000000L << 36),  //=-0.999999940395355224609375000000
   854:     new EFP (M,     -1, 0xffffffffffffffffL, 0xfffffffL << 36),  //=-0.999999999999999999999999999798
   855:   };
   856:   public final EFP[] NEXTDOWN_PLUSONE = {
   857:     //  echo read("efp.gp");efpmem([exdnextdown(1)],[sglnextdown(1)],[dblnextdown(1)],[dblnextdown(1)],[tplnextdown(1)],[xsgnextdown(1)],[efpnextdown(1)]) | gp -q
   858:     new EFP (P,     -1, 0xffffffffffffffffL, 0x0000000L << 36),  //=0.999999999999999999945789891376
   859:     new EFP (P,     -1, 0xffffff0000000000L, 0x0000000L << 36),  //=0.999999940395355224609375000000
   860:     new EFP (P,     -1, 0xfffffffffffff800L, 0x0000000L << 36),  //=0.999999999999999888977697537484
   861:     new EFP (P,     -1, 0xfffffffffffff800L, 0x0000000L << 36),  //=0.999999999999999888977697537484
   862:     new EFP (P,     -1, 0xffffffffffffffffL, 0xffff000L << 36),  //=0.999999999999999999999999172819
   863:     new EFP (P,     -1, 0xffffff0000000000L, 0x0000000L << 36),  //=0.999999940395355224609375000000
   864:     new EFP (P,     -1, 0xffffffffffffffffL, 0xfffffffL << 36),  //=0.999999999999999999999999999798
   865:   };
   866:   public final EFP[] NEXTUP_PLUSONE = {
   867:     //  echo read("efp.gp");efpmem([exdnextup(1)],[sglnextup(1)],[dblnextup(1)],[dblnextup(1)],[tplnextup(1)],[xsgnextup(1)],[efpnextup(1)]) | gp -q
   868:     new EFP (P,      0, 0x8000000000000001L, 0x0000000L << 36),  //=1.00000000000000000010842021725
   869:     new EFP (P,      0, 0x8000010000000000L, 0x0000000L << 36),  //=1.00000011920928955078125000000
   870:     new EFP (P,      0, 0x8000000000000800L, 0x0000000L << 36),  //=1.00000000000000022204460492503
   871:     new EFP (P,      0, 0x8000000000000800L, 0x0000000L << 36),  //=1.00000000000000022204460492503
   872:     new EFP (P,      0, 0x8000000000000000L, 0x0001000L << 36),  //=1.00000000000000000000000165436
   873:     new EFP (P,      0, 0x8000010000000000L, 0x0000000L << 36),  //=1.00000011920928955078125000000
   874:     new EFP (P,      0, 0x8000000000000000L, 0x0000001L << 36),  //=1.00000000000000000000000000040
   875:   };
   876: 
   877:   //------------------------------------------------------------------------
   878:   //汎用定数
   879:   //  echo read("efp.gp");efppub(["NEGONE",-1],["ONE",1],["TWO",2],["THREE",3],["FOUR",4],["FIVE",5],["SIX",6],["SEVEN",7],["EIGHT",8],["NINE",9],["TEN",10],["ELEVEN",11],["TWELVE",12],["THIRTEEN",13],["FOURTEEN",14],["FIFTEEN",15],[SIXTEEN,16]) | gp -q
   880:   public final EFP       NEGONE = new EFP (M,      0, 0x8000000000000000L, 0x0000000L << 36);  //=-1.00000000000000000000000000000
   881:   public final EFP          ONE = new EFP (P,      0, 0x8000000000000000L, 0x0000000L << 36);  //=1.00000000000000000000000000000
   882:   public final EFP          TWO = new EFP (P,      1, 0x8000000000000000L, 0x0000000L << 36);  //=2.00000000000000000000000000000
   883:   public final EFP        THREE = new EFP (P,      1, 0xc000000000000000L, 0x0000000L << 36);  //=3.00000000000000000000000000000
   884:   public final EFP         FOUR = new EFP (P,      2, 0x8000000000000000L, 0x0000000L << 36);  //=4.00000000000000000000000000000
   885:   public final EFP         FIVE = new EFP (P,      2, 0xa000000000000000L, 0x0000000L << 36);  //=5.00000000000000000000000000000
   886:   public final EFP          SIX = new EFP (P,      2, 0xc000000000000000L, 0x0000000L << 36);  //=6.00000000000000000000000000000
   887:   public final EFP        SEVEN = new EFP (P,      2, 0xe000000000000000L, 0x0000000L << 36);  //=7.00000000000000000000000000000
   888:   public final EFP        EIGHT = new EFP (P,      3, 0x8000000000000000L, 0x0000000L << 36);  //=8.00000000000000000000000000000
   889:   public final EFP         NINE = new EFP (P,      3, 0x9000000000000000L, 0x0000000L << 36);  //=9.00000000000000000000000000000
   890:   public final EFP          TEN = new EFP (P,      3, 0xa000000000000000L, 0x0000000L << 36);  //=10.0000000000000000000000000000
   891:   public final EFP       ELEVEN = new EFP (P,      3, 0xb000000000000000L, 0x0000000L << 36);  //=11.0000000000000000000000000000
   892:   public final EFP       TWELVE = new EFP (P,      3, 0xc000000000000000L, 0x0000000L << 36);  //=12.0000000000000000000000000000
   893:   public final EFP     THIRTEEN = new EFP (P,      3, 0xd000000000000000L, 0x0000000L << 36);  //=13.0000000000000000000000000000
   894:   public final EFP     FOURTEEN = new EFP (P,      3, 0xe000000000000000L, 0x0000000L << 36);  //=14.0000000000000000000000000000
   895:   public final EFP      FIFTEEN = new EFP (P,      3, 0xf000000000000000L, 0x0000000L << 36);  //=15.0000000000000000000000000000
   896:   public final EFP      SIXTEEN = new EFP (P,      4, 0x8000000000000000L, 0x0000000L << 36);  //=16.0000000000000000000000000000
   897:   public final EFP[] EFP_DIGIT = {
   898:     ZERO,
   899:     ONE,
   900:     TWO,
   901:     THREE,
   902:     FOUR,
   903:     FIVE,
   904:     SIX,
   905:     SEVEN,
   906:     EIGHT,
   907:     NINE,
   908:     TEN,
   909:     ELEVEN,
   910:     TWELVE,
   911:     THIRTEEN,
   912:     FOURTEEN,
   913:     FIFTEEN,
   914:     SIXTEEN,
   915:   };
   916:   //  echo read("efp.gp");efppub(["ONE_2",1/2],["ONE_3",1/3],["TWO_3",2/3],["ONE_4",1/4],["THREE_4",3/4],["ONE_5",1/5],["TWO_5",2/5],["THREE_5",3/5],["FOUR_5",4/5],["ONE_6",1/6],["FIVE_6",5/6],[ONE_10,1/10]) | gp -q
   917:   public final EFP        ONE_2 = new EFP (P,     -1, 0x8000000000000000L, 0x0000000L << 36);  //=0.500000000000000000000000000000
   918:   public final EFP        ONE_3 = new EFP (P,     -2, 0xaaaaaaaaaaaaaaaaL, 0xaaaaaabL << 36);  //>0.333333333333333333333333333333
   919:   public final EFP        TWO_3 = new EFP (P,     -1, 0xaaaaaaaaaaaaaaaaL, 0xaaaaaabL << 36);  //>0.666666666666666666666666666667
   920:   public final EFP        ONE_4 = new EFP (P,     -2, 0x8000000000000000L, 0x0000000L << 36);  //=0.250000000000000000000000000000
   921:   public final EFP      THREE_4 = new EFP (P,     -1, 0xc000000000000000L, 0x0000000L << 36);  //=0.750000000000000000000000000000
   922:   public final EFP        ONE_5 = new EFP (P,     -3, 0xccccccccccccccccL, 0xccccccdL << 36);  //>0.200000000000000000000000000000
   923:   public final EFP        TWO_5 = new EFP (P,     -2, 0xccccccccccccccccL, 0xccccccdL << 36);  //>0.400000000000000000000000000000
   924:   public final EFP      THREE_5 = new EFP (P,     -1, 0x9999999999999999L, 0x999999aL << 36);  //>0.600000000000000000000000000000
   925:   public final EFP       FOUR_5 = new EFP (P,     -1, 0xccccccccccccccccL, 0xccccccdL << 36);  //>0.800000000000000000000000000000
   926:   public final EFP        ONE_6 = new EFP (P,     -3, 0xaaaaaaaaaaaaaaaaL, 0xaaaaaabL << 36);  //>0.166666666666666666666666666667
   927:   public final EFP       FIVE_6 = new EFP (P,     -1, 0xd555555555555555L, 0x5555555L << 36);  //<0.833333333333333333333333333333
   928:   public final EFP       ONE_10 = new EFP (P,     -4, 0xccccccccccccccccL, 0xccccccdL << 36);  //>0.100000000000000000000000000000
   929:   //  echo read("efp.gp");efppub2(["SQRT2",sqrt(2)],["SQRT2_2",sqrt(2)/2],["DECSQRT2",sqrt(2)-1],["INCSQRT2",sqrt(2)+1]) | gp -q
   930:   public final EFP        SQRT2 = new EFP (P,      0, 0xb504f333f9de6484L, 0x597d89bL << 36);  //<1.41421356237309504880168872421
   931:   public final EFP       SQRT2A = new EFP (P,    -94, 0xdd52afa7c75bd82eL, 0xa24eea1L << 36);  //<8.72965282186712870062036635269e-29
   932:   public final EFP      SQRT2_2 = new EFP (P,     -1, 0xb504f333f9de6484L, 0x597d89bL << 36);  //<0.707106781186547524400844362105
   933:   public final EFP     SQRT2_2A = new EFP (P,    -95, 0xdd52afa7c75bd82eL, 0xa24eea1L << 36);  //<4.36482641093356435031018317635e-29
   934:   public final EFP     DECSQRT2 = new EFP (P,     -2, 0xd413cccfe7799211L, 0x65f626dL << 36);  //>0.414213562373095048801688724210
   935:   public final EFP    DECSQRT2A = new EFP (M,    -96, 0x8ab54160e2909f45L, 0x76c457bL << 36);  //>-1.36776676496182240864975928293e-29
   936:   public final EFP     INCSQRT2 = new EFP (P,      1, 0x9a827999fcef3242L, 0x2cbec4eL << 36);  //>2.41421356237309504880168872421
   937:   public final EFP    INCSQRT2A = new EFP (M,    -92, 0xc8ab54160e2909f4L, 0x576c458L << 36);  //<-3.16600255254486757364601361898e-28
   938:   //  echo read("efp.gp");efppub2(["PI",Pi],["NEGPI",-Pi],["PI2",Pi*2],["PI_2",Pi/2],["NEGPI_2",-Pi/2],["PI3_2",Pi*3/2],["PI_4",Pi/4],["NEGPI_4",-Pi/4],["PI3_4",Pi*3/4],["NEGPI3_4",-Pi*3/4],["PI_6",Pi/6],["PI_8",Pi/8],["TO_RAD",Pi/180]) | gp -q
   939:   public final EFP           PI = new EFP (P,      1, 0xc90fdaa22168c234L, 0xc4c6629L << 36);  //>3.14159265358979323846264338328
   940:   public final EFP          PIA = new EFP (M,    -92, 0x8fe47c65dadfb63eL, 0xeeb3067L << 36);  //>-2.27022372150444021965698652772e-28
   941:   public final EFP        NEGPI = new EFP (M,      1, 0xc90fdaa22168c234L, 0xc4c6629L << 36);  //<-3.14159265358979323846264338328
   942:   public final EFP       NEGPIA = new EFP (P,    -92, 0x8fe47c65dadfb63eL, 0xeeb3067L << 36);  //<2.27022372150444021965698652772e-28
   943:   public final EFP          PI2 = new EFP (P,      2, 0xc90fdaa22168c234L, 0xc4c6629L << 36);  //>6.28318530717958647692528676656
   944:   public final EFP         PI2A = new EFP (M,    -91, 0x8fe47c65dadfb63eL, 0xeeb3067L << 36);  //>-4.54044744300888043931397305544e-28
   945:   public final EFP         PI_2 = new EFP (P,      0, 0xc90fdaa22168c234L, 0xc4c6629L << 36);  //>1.57079632679489661923132169164
   946:   public final EFP        PI_2A = new EFP (M,    -93, 0x8fe47c65dadfb63eL, 0xeeb3067L << 36);  //>-1.13511186075222010982849326386e-28
   947:   public final EFP      NEGPI_2 = new EFP (M,      0, 0xc90fdaa22168c234L, 0xc4c6629L << 36);  //<-1.57079632679489661923132169164
   948:   public final EFP     NEGPI_2A = new EFP (P,    -93, 0x8fe47c65dadfb63eL, 0xeeb3067L << 36);  //<1.13511186075222010982849326386e-28
   949:   public final EFP        PI3_2 = new EFP (P,      2, 0x96cbe3f9990e91a7L, 0x9394c9fL << 36);  //>4.71238898038468985769396507492
   950:   public final EFP       PI3_2A = new EFP (M,    -91, 0xebeb5d4c6427c8afL, 0x330644dL << 36);  //>-7.44430341698824077319353004583e-28
   951:   public final EFP         PI_4 = new EFP (P,     -1, 0xc90fdaa22168c234L, 0xc4c6629L << 36);  //>0.785398163397448309615660845820
   952:   public final EFP        PI_4A = new EFP (M,    -94, 0x8fe47c65dadfb63eL, 0xeeb3067L << 36);  //>-5.67555930376110054914246631930e-29
   953:   public final EFP      NEGPI_4 = new EFP (M,     -1, 0xc90fdaa22168c234L, 0xc4c6629L << 36);  //<-0.785398163397448309615660845820
   954:   public final EFP     NEGPI_4A = new EFP (P,    -94, 0x8fe47c65dadfb63eL, 0xeeb3067L << 36);  //<5.67555930376110054914246631930e-29
   955:   public final EFP        PI3_4 = new EFP (P,      1, 0x96cbe3f9990e91a7L, 0x9394c9fL << 36);  //>2.35619449019234492884698253746
   956:   public final EFP       PI3_4A = new EFP (M,    -92, 0xebeb5d4c6427c8afL, 0x330644dL << 36);  //>-3.72215170849412038659676502291e-28
   957:   public final EFP     NEGPI3_4 = new EFP (M,      1, 0x96cbe3f9990e91a7L, 0x9394c9fL << 36);  //<-2.35619449019234492884698253746
   958:   public final EFP    NEGPI3_4A = new EFP (P,    -92, 0xebeb5d4c6427c8afL, 0x330644dL << 36);  //<3.72215170849412038659676502291e-28
   959:   public final EFP         PI_6 = new EFP (P,     -1, 0x860a91c16b9b2c23L, 0x2dd9970L << 36);  //<0.523598775598298873077107230547
   960:   public final EFP        PI_6A = new EFP (P,    -94, 0xf567ad116e158680L, 0xb633511L << 36);  //>9.67951991326453444626518996796e-29
   961:   public final EFP         PI_8 = new EFP (P,     -2, 0xc90fdaa22168c234L, 0xc4c6629L << 36);  //>0.392699081698724154807830422910
   962:   public final EFP        PI_8A = new EFP (M,    -95, 0x8fe47c65dadfb63eL, 0xeeb3067L << 36);  //>-2.83777965188055027457123315965e-29
   963:   public final EFP       TO_RAD = new EFP (P,     -6, 0x8efa351294e9c8aeL, 0x0ec5f67L << 36);  //>0.0174532925199432957692369076849
   964:   public final EFP      TO_RADA = new EFP (M,   -101, 0xb5bd1d937fa42885L, 0x7f250caL << 36);  //>-5.60025707306011850554567124038e-31
   965:   //  echo read("efp.gp");efppub2(["ONE_2PI",1/(2*Pi)],["ONE_PI",1/Pi],["TWO_PI",2/Pi],["FOUR_PI",4/Pi],["TO_DEG",180/Pi]) | gp -q
   966:   public final EFP      ONE_2PI = new EFP (P,     -3, 0xa2f9836e4e441529L, 0xfc2757dL << 36);  //<0.159154943091895335768883763373
   967:   public final EFP     ONE_2PIA = new EFP (P,    -98, 0xfa9a6ee06db14accL, 0x9e21c82L << 36);  //<6.17784718978010796644368056118e-30
   968:   public final EFP       ONE_PI = new EFP (P,     -2, 0xa2f9836e4e441529L, 0xfc2757dL << 36);  //<0.318309886183790671537767526745
   969:   public final EFP      ONE_PIA = new EFP (P,    -97, 0xfa9a6ee06db14accL, 0x9e21c82L << 36);  //<1.23556943795602159328873611224e-29
   970:   public final EFP       TWO_PI = new EFP (P,     -1, 0xa2f9836e4e441529L, 0xfc2757dL << 36);  //<0.636619772367581343075535053490
   971:   public final EFP      TWO_PIA = new EFP (P,    -96, 0xfa9a6ee06db14accL, 0x9e21c82L << 36);  //<2.47113887591204318657747222447e-29
   972:   public final EFP      FOUR_PI = new EFP (P,      0, 0xa2f9836e4e441529L, 0xfc2757dL << 36);  //<1.27323954473516268615107010698
   973:   public final EFP     FOUR_PIA = new EFP (P,    -95, 0xfa9a6ee06db14accL, 0x9e21c82L << 36);  //<4.94227775182408637315494444895e-29
   974:   public final EFP       TO_DEG = new EFP (P,      5, 0xe52ee0d31e0fbdc3L, 0x0a97538L << 36);  //>57.2957795130823208767981548141
   975:   public final EFP      TO_DEGA = new EFP (M,    -91, 0xbf2da828cb7d5da0L, 0x8340fd2L << 36);  //>-6.03252495991267442675910175947e-28
   976:   //  echo read("efp.gp");efppub2(["E",exp(1)]) | gp -q
   977:   public final EFP            E = new EFP (P,      1, 0xadf85458a2bb4a9aL, 0xafdc562L << 36);  //<2.71828182845904523536028747135
   978:   public final EFP           EA = new EFP (P,    -97, 0x9cf4f3c762e7160fL, 0x38b4da5L << 36);  //<7.73856991537314016398963167104e-30
   979:   //  echo read("efp.gp");efppub2(["LOG_2",log(2)],["LOG_2_2",log(2)/2],["LOG_10",log(10)],["LOG2_E",1/log(2)],["LOG2_10",log(10)/log(2)],["LOG10_2",log(2)/log(10)],["LOG10_E",1/log(10)]) | gp -q
   980:   public final EFP        LOG_2 = new EFP (P,     -1, 0xb17217f7d1cf79abL, 0xc9e3b3aL << 36);  //>0.693147180559945309417232121458
   981:   public final EFP       LOG_2A = new EFP (M,    -94, 0xff81a12a17e1979bL, 0x31ace94L << 36);  //<-1.00779491359051436097542460399e-28
   982:   public final EFP      LOG_2_2 = new EFP (P,     -2, 0xb17217f7d1cf79abL, 0xc9e3b3aL << 36);  //>0.346573590279972654708616060729
   983:   public final EFP     LOG_2_2A = new EFP (M,    -95, 0xff81a12a17e1979bL, 0x31ace94L << 36);  //<-5.03897456795257180487712301994e-29
   984:   public final EFP       LOG_10 = new EFP (P,      1, 0x935d8dddaaa8ac16L, 0xea56d63L << 36);  //>2.30258509299404568401799145468
   985:   public final EFP      LOG_10A = new EFP (M,    -92, 0x8fa59ebae3ae0260L, 0xc4b440eL << 36);  //<-2.26634931190478263500410602069e-28
   986:   public final EFP       LOG2_E = new EFP (P,      0, 0xb8aa3b295c17f0bbL, 0xbe87fedL << 36);  //<1.44269504088896340735992468100
   987:   public final EFP      LOG2_EA = new EFP (P,    -97, 0xd23a7d11d6aef551L, 0xbad2b4bL << 36);  //<1.03650638666742465296873972532e-29
   988:   public final EFP      LOG2_10 = new EFP (P,      1, 0xd49a784bcd1b8afeL, 0x492bf70L << 36);  //>3.32192809488736234787031942949
   989:   public final EFP     LOG2_10A = new EFP (M,    -95, 0xb25024b32693aa01L, 0xc84c52bL << 36);  //>-3.51660504800210370161854327284e-29
   990:   public final EFP      LOG10_2 = new EFP (P,     -2, 0x9a209a84fbcff798L, 0x8f8959bL << 36);  //>0.301029995663981195213738894724
   991:   public final EFP     LOG10_2A = new EFP (M,    -96, 0xfd20dba1f654b3ceL, 0xaf0b833L << 36);  //<-2.49603825457634309563856476519e-29
   992:   public final EFP      LOG10_E = new EFP (P,     -2, 0xde5bd8a937287195L, 0x355baabL << 36);  //>0.434294481903251827651128918917
   993:   public final EFP     LOG10_EA = new EFP (M,    -99, 0xa598479b823973fbL, 0x746cbc0L << 36);  //<-2.04111402292715890833493215303e-30
   994:   //  echo read("efp.gp");for(n=1,14,efppub([Str("TENXP",n),Str("10^(2^",n,")")])) | gp -q
   995:   public final EFP       TENXP1 = new EFP (P,      6, 0xc800000000000000L, 0x0000000L << 36);  //=10^(2^1)=100.000000000000000000000000000
   996:   public final EFP       TENXP2 = new EFP (P,     13, 0x9c40000000000000L, 0x0000000L << 36);  //=10^(2^2)=10000.0000000000000000000000000
   997:   public final EFP       TENXP3 = new EFP (P,     26, 0xbebc200000000000L, 0x0000000L << 36);  //=10^(2^3)=100000000.000000000000000000000
   998:   public final EFP       TENXP4 = new EFP (P,     53, 0x8e1bc9bf04000000L, 0x0000000L << 36);  //=10^(2^4)=10000000000000000.0000000000000
   999:   public final EFP       TENXP5 = new EFP (P,    106, 0x9dc5ada82b70b59dL, 0xf020000L << 36);  //=10^(2^5)=1.00000000000000000000000000000e+32
  1000:   public final EFP       TENXP6 = new EFP (P,    212, 0xc2781f49ffcfa6d5L, 0x3cbf6b7L << 36);  //<10^(2^6)=1.00000000000000000000000000000e+64
  1001:   public final EFP       TENXP7 = new EFP (P,    425, 0x93ba47c980e98cdfL, 0xc66f337L << 36);  //>10^(2^7)=1.00000000000000000000000000000e+128
  1002:   public final EFP       TENXP8 = new EFP (P,    850, 0xaa7eebfb9df9de8dL, 0xddbb902L << 36);  //>10^(2^8)=1.00000000000000000000000000000e+256
  1003:   public final EFP       TENXP9 = new EFP (P,   1700, 0xe319a0aea60e91c6L, 0xcc655c5L << 36);  //<10^(2^9)=1.00000000000000000000000000000e+512
  1004:   public final EFP      TENXP10 = new EFP (P,   3401, 0xc976758681750c17L, 0x650d3d3L << 36);  //>10^(2^10)=1.00000000000000000000000000000e+1024
  1005:   public final EFP      TENXP11 = new EFP (P,   6803, 0x9e8b3b5dc53d5de4L, 0xa74d28dL << 36);  //>10^(2^11)=1.00000000000000000000000000000e+2048
  1006:   public final EFP      TENXP12 = new EFP (P,  13606, 0xc46052028a20979aL, 0xc94c154L << 36);  //>10^(2^12)=1.00000000000000000000000000000e+4096
  1007:   public final EFP      TENXP13 = new EFP (P,  27213, 0x96a3a1d17faf211aL, 0x0c7c289L << 36);  //<10^(2^13)=1.00000000000000000000000000000e+8192
  1008:   public final EFP      TENXP14 = new EFP (P,  54426, 0xb1485471f16603b5L, 0x6226e11L << 36);  //<10^(2^14)=1.00000000000000000000000000000e+16384
  1009:   public final EFP[] EFP_TEN_POWER_P = {
  1010:     TEN,
  1011:     TENXP1,
  1012:     TENXP2,
  1013:     TENXP3,
  1014:     TENXP4,
  1015:     TENXP5,
  1016:     TENXP6,
  1017:     TENXP7,
  1018:     TENXP8,
  1019:     TENXP9,
  1020:     TENXP10,
  1021:     TENXP11,
  1022:     TENXP12,
  1023:     TENXP13,
  1024:     TENXP14,
  1025:     INF,  //番兵 +Inf
  1026:   };
  1027:   //  echo read("efp.gp");for(n=1,14,efppub([Str("TENXM",n),Str("10^(-2^",n,")")])) | gp -q
  1028:   public final EFP       TENXM1 = new EFP (P,     -7, 0xa3d70a3d70a3d70aL, 0x3d70a3dL << 36);  //<10^(-2^1)=0.0100000000000000000000000000000
  1029:   public final EFP       TENXM2 = new EFP (P,    -14, 0xd1b71758e219652bL, 0xd3c3611L << 36);  //<10^(-2^2)=1.00000000000000000000000000000e-4
  1030:   public final EFP       TENXM3 = new EFP (P,    -27, 0xabcc77118461cefcL, 0xfdc20d3L << 36);  //>10^(-2^3)=1.00000000000000000000000000000e-8
  1031:   public final EFP       TENXM4 = new EFP (P,    -54, 0xe69594bec44de15bL, 0x4c2ebe7L << 36);  //>10^(-2^4)=1.00000000000000000000000000000e-16
  1032:   public final EFP       TENXM5 = new EFP (P,   -107, 0xcfb11ead453994baL, 0x67de18fL << 36);  //>10^(-2^5)=1.00000000000000000000000000000e-32
  1033:   public final EFP       TENXM6 = new EFP (P,   -213, 0xa87fea27a539e9a5L, 0x3f2398dL << 36);  //<10^(-2^6)=1.00000000000000000000000000000e-64
  1034:   public final EFP       TENXM7 = new EFP (P,   -426, 0xddd0467c64bce4a0L, 0xac7cb3fL << 36);  //<10^(-2^7)=1.00000000000000000000000000000e-128
  1035:   public final EFP       TENXM8 = new EFP (P,   -851, 0xc0314325637a1939L, 0xfa91115L << 36);  //<10^(-2^8)=1.00000000000000000000000000000e-256
  1036:   public final EFP       TENXM9 = new EFP (P,  -1701, 0x9049ee32db23d21cL, 0x7132d33L << 36);  //<10^(-2^9)=1.00000000000000000000000000000e-512
  1037:   public final EFP      TENXM10 = new EFP (P,  -3402, 0xa2a682a5da57c0bdL, 0x87a6016L << 36);  //>10^(-2^10)=1.00000000000000000000000000000e-1024
  1038:   public final EFP      TENXM11 = new EFP (P,  -6804, 0xceae534f34362de4L, 0x492512dL << 36);  //<10^(-2^11)=1.00000000000000000000000000000e-2048
  1039:   public final EFP      TENXM12 = new EFP (P, -13607, 0xa6dd04c8d2ce9fdeL, 0x2de3812L << 36);  //<10^(-2^12)=1.00000000000000000000000000000e-4096
  1040:   public final EFP      TENXM13 = new EFP (P, -27214, 0xd986c20b686da869L, 0x5d1d4feL << 36);  //>10^(-2^13)=1.00000000000000000000000000000e-8192
  1041:   public final EFP      TENXM14 = new EFP (P, -54427, 0xb8d5bbe70e108517L, 0x456e9e1L << 36);  //>10^(-2^14)=1.00000000000000000000000000000e-16384
  1042:   public final EFP[] EFP_TEN_POWER_M = {
  1043:     ONE_10,
  1044:     TENXM1,
  1045:     TENXM2,
  1046:     TENXM3,
  1047:     TENXM4,
  1048:     TENXM5,
  1049:     TENXM6,
  1050:     TENXM7,
  1051:     TENXM8,
  1052:     TENXM9,
  1053:     TENXM10,
  1054:     TENXM11,
  1055:     TENXM12,
  1056:     TENXM13,
  1057:     TENXM14,
  1058:     ZERO,  //番兵 +0
  1059:   };
  1060: 
  1061:   //------------------------------------------------------------------------
  1062:   //asin
  1063:   //  echo read("efp.gp");efpchebyshev("ASIN_C",asin,-1/16,1/16,17) | gp -q
  1064:   public final EFP      ASIN_C1 = new EFP (P,      0, 0x8000000000000000L, 0x0000000L << 36);  //=1.00000000000000000000000000000
  1065:   public final EFP      ASIN_C3 = new EFP (P,     -3, 0xaaaaaaaaaaaaaaaaL, 0xaa9f5a6L << 36);  //=0.166666666666666666666664327061
  1066:   public final EFP      ASIN_C5 = new EFP (P,     -4, 0x999999999999999bL, 0x27bc1b8L << 36);  //=0.0750000000000000000105385402653
  1067:   public final EFP      ASIN_C7 = new EFP (P,     -5, 0xb6db6db6db6d9dfbL, 0x62327e8L << 36);  //=0.0446428571428571212813671978867
  1068:   public final EFP      ASIN_C9 = new EFP (P,     -6, 0xf8e38e38e465b639L, 0x780782eL << 36);  //=0.0303819444444683685951253163427
  1069:   public final EFP     ASIN_C11 = new EFP (P,     -6, 0xb745d17238e942a1L, 0xe80f5beL << 36);  //=0.0223721590753288857337240816603
  1070:   public final EFP     ASIN_C13 = new EFP (P,     -6, 0x8e2765c0b9aaa792L, 0xa93870aL << 36);  //=0.0173527705535908188340798484805
  1071:   public final EFP     ASIN_C15 = new EFP (P,     -7, 0xe4c6ca7a5689895bL, 0x0fdd729L << 36);  //=0.0139634110758853644843472082762
  1072:   public final EFP     ASIN_C17 = new EFP (P,     -7, 0xc0428d0d9769d446L, 0x583b42dL << 36);  //=0.0117346169921491621622941093289
  1073:   //  92.12bit
  1074: 
  1075:   //------------------------------------------------------------------------
  1076:   //asinh
  1077:   //  echo read("efp.gp");efpchebyshev("ASINH_C",asinh,-1/2,1/2,43) | gp -q
  1078:   public final EFP     ASINH_C1 = new EFP (P,      0, 0x8000000000000000L, 0x0000000L << 36);  //=1.00000000000000000000000000000
  1079:   public final EFP     ASINH_C3 = new EFP (M,     -3, 0xaaaaaaaaaaaaaaaaL, 0xaaaa73cL << 36);  //=-0.166666666666666666666666622305
  1080:   public final EFP     ASINH_C5 = new EFP (P,     -4, 0x9999999999999999L, 0x98eba3eL << 36);  //=0.0749999999999999999999820129717
  1081:   public final EFP     ASINH_C7 = new EFP (M,     -5, 0xb6db6db6db6db6daL, 0x693062cL << 36);  //=-0.0446428571428571428536948337862
  1082:   public final EFP     ASINH_C9 = new EFP (P,     -6, 0xf8e38e38e38e3802L, 0x877ce5fL << 36);  //=0.0303819444444444440632350540650
  1083:   public final EFP    ASINH_C11 = new EFP (M,     -6, 0xb745d1745d17072fL, 0x8f119f4L << 36);  //=-0.0223721590909090637466150767286
  1084:   public final EFP    ASINH_C13 = new EFP (P,     -6, 0x8e27627627566903L, 0xdf845ccL << 36);  //=0.0173527644230755851112834055009
  1085:   public final EFP    ASINH_C15 = new EFP (M,     -7, 0xe4ccccccc9700e9eL, 0xe0b4a69L << 36);  //=-0.0139648437499522191713609105717
  1086:   public final EFP    ASINH_C17 = new EFP (P,     -7, 0xbd43c3c369baae2eL, 0x0efcbb2L << 36);  //=0.0115518008948602246771685034495
  1087:   public final EFP    ASINH_C19 = new EFP (M,     -7, 0x9fef28648d7f5526L, 0x95df2b5L << 36);  //=-0.00976160950286693766098184072269
  1088:   public final EFP    ASINH_C21 = new EFP (P,     -7, 0x89779e056ca4e338L, 0xd00497cL << 36);  //=0.00839033538586369462750852571141
  1089:   public final EFP    ASINH_C23 = new EFP (M,     -8, 0xef9dde222ea1963bL, 0xe27b426L << 36);  //=-0.00731252046931722928944285830165
  1090:   public final EFP    ASINH_C25 = new EFP (P,     -8, 0xd342a867c46a40d7L, 0x608fa17L << 36);  //=0.00644715521733314071113327514541
  1091:   public final EFP    ASINH_C27 = new EFP (M,     -8, 0xbc1323a7fe6984a7L, 0x201509dL << 36);  //=-0.00573958626772545827330135382977
  1092:   public final EFP    ASINH_C29 = new EFP (P,     -8, 0xa8c41a9477d0f87aL, 0x533f07cL << 36);  //=0.00515033052300720080631063831135
  1093:   public final EFP    ASINH_C31 = new EFP (M,     -8, 0x982f5aab1d57a757L, 0x87f7027L << 36);  //=-0.00464431693238042269332079800182
  1094:   public final EFP    ASINH_C33 = new EFP (P,     -8, 0x88c1b2170947d07cL, 0x03ff2fcL << 36);  //=0.00417348094749513993640755085487
  1095:   public final EFP    ASINH_C35 = new EFP (M,     -9, 0xef58f638c3ca7cffL, 0x77a770cL << 36);  //=-0.00365215312264336578286676378192
  1096:   public final EFP    ASINH_C37 = new EFP (P,     -9, 0xc1c49585f23563ecL, 0x9a83aedL << 36);  //=0.00295666361302767397480120706092
  1097:   public final EFP    ASINH_C39 = new EFP (M,     -9, 0x844314a5dc2c3362L, 0x37b5811L << 36);  //=-0.00201815847491166045931431987253
  1098:   public final EFP    ASINH_C41 = new EFP (P,    -10, 0x824564bc0126d26dL, 0x0c5dd9fL << 36);  //=9.93889376333981375114292565553e-4
  1099:   public final EFP    ASINH_C43 = new EFP (M,    -12, 0x85dfcbe40f7ac39fL, 0xb82e7c3L << 36);  //=-2.55344781642232531153119989033e-4
  1100:   //  94.34bit
  1101: 
  1102:   //------------------------------------------------------------------------
  1103:   //atan
  1104:   //  echo read("efp.gp");efpchebyshev("ATAN_C",atan,1-sqrt(2),sqrt(2)-1,39) | gp -q
  1105:   public final EFP      ATAN_C1 = new EFP (P,      0, 0x8000000000000000L, 0x0000000L << 36);  //=1.00000000000000000000000000000
  1106:   public final EFP      ATAN_C3 = new EFP (M,     -2, 0xaaaaaaaaaaaaaaaaL, 0xaaaa510L << 36);  //=-0.333333333333333333333333188469
  1107:   public final EFP      ATAN_C5 = new EFP (P,     -3, 0xccccccccccccccccL, 0xcb75e59L << 36);  //=0.199999999999999999999929089265
  1108:   public final EFP      ATAN_C7 = new EFP (M,     -3, 0x9249249249249247L, 0xef2e1e8L << 36);  //=-0.142857142857142857126478105101
  1109:   public final EFP      ATAN_C9 = new EFP (P,     -4, 0xe38e38e38e38e24dL, 0x0fb9b9aL << 36);  //=0.111111111111111108934840916430
  1110:   public final EFP     ATAN_C11 = new EFP (M,     -4, 0xba2e8ba2e8b9c37fL, 0xd40106dL << 36);  //=-0.0909090909090907233954815301475
  1111:   public final EFP     ATAN_C13 = new EFP (P,     -4, 0x9d89d89d89c01044L, 0xee8e878L << 36);  //=0.0769230769230660198728951590461
  1112:   public final EFP     ATAN_C15 = new EFP (M,     -4, 0x888888888479743eL, 0xd1a4c1cL << 36);  //=-0.0666666666662052227836546394505
  1113:   public final EFP     ATAN_C17 = new EFP (P,     -5, 0xf0f0f0eff12a86f3L, 0x34f4f78L << 36);  //=0.0588235293972255773084039586191
  1114:   public final EFP     ATAN_C19 = new EFP (M,     -5, 0xd79435cd132b46adL, 0x026fbddL << 36);  //=-0.0526315785984461994745177668558
  1115:   public final EFP     ATAN_C21 = new EFP (P,     -5, 0xc30c2f05b9b60e24L, 0x4f7cf62L << 36);  //=0.0476190411387569357252301278730
  1116:   public final EFP     ATAN_C23 = new EFP (M,     -5, 0xb216298497a81754L, 0x9c69988L << 36);  //=-0.0434781667513366645605035624712
  1117:   public final EFP     ATAN_C25 = new EFP (P,     -5, 0xa3d5e99dc5d0a87cL, 0x531842aL << 36);  //=0.0399989247929292486609759555531
  1118:   public final EFP     ATAN_C27 = new EFP (M,     -5, 0x97aa006d0e00c9c7L, 0x30d6815L << 36);  //=-0.0370273605957438052706320851811
  1119:   public final EFP     ATAN_C29 = new EFP (P,     -5, 0x8cf60e9e64655ffeL, 0x38ac19cL << 36);  //=0.0344143458408095737006383246276
  1120:   public final EFP     ATAN_C31 = new EFP (M,     -5, 0x82959208f1c7a2afL, 0xdae8a29L << 36);  //=-0.0318809227456870204466446023911
  1121:   public final EFP     ATAN_C33 = new EFP (P,     -6, 0xeb2210cae680d538L, 0x15fff4fL << 36);  //=0.0287027671794960285031110247127
  1122:   public final EFP     ATAN_C35 = new EFP (M,     -6, 0xc010e629b0e973a6L, 0xe64c5d3L << 36);  //=-0.0234455581062579745139013801043
  1123:   public final EFP     ATAN_C37 = new EFP (P,     -7, 0xf4fd1335dff0ecefL, 0x1237cb3L << 36);  //=0.0149529159166368844370818258508
  1124:   public final EFP     ATAN_C39 = new EFP (M,     -8, 0xae06e746e01494ddL, 0xc1bb093L << 36);  //=-0.00531088154616611800320323885484
  1125:   //  92.91bit
  1126: 
  1127:   //------------------------------------------------------------------------
  1128:   //atanh
  1129:   //  echo read("efp.gp");efpchebyshev("ATANH_C",atanh,-1/16,1/16,19) | gp -q
  1130:   public final EFP     ATANH_C1 = new EFP (P,      0, 0x8000000000000000L, 0x0000000L << 36);  //=1.00000000000000000000000000000
  1131:   public final EFP     ATANH_C3 = new EFP (P,     -2, 0xaaaaaaaaaaaaaaaaL, 0xaaaab40L << 36);  //=0.333333333333333333333333348412
  1132:   public final EFP     ATANH_C5 = new EFP (P,     -3, 0xccccccccccccccccL, 0xcb39274L << 36);  //=0.199999999999999999999916527823
  1133:   public final EFP     ATANH_C7 = new EFP (P,     -3, 0x9249249249249258L, 0xc166b48L << 36);  //=0.142857142857142857354447548729
  1134:   public final EFP     ATANH_C9 = new EFP (P,     -4, 0xe38e38e38e38399dL, 0xe3605a0L << 36);  //=0.111111111111110816314276914861
  1135:   public final EFP    ATANH_C11 = new EFP (P,     -4, 0xba2e8ba2eae60f89L, 0xa98ab82L << 36);  //=0.0909090909093377689017810115409
  1136:   public final EFP    ATANH_C13 = new EFP (P,     -4, 0x9d89d8991665e749L, 0xd36e921L << 36);  //=0.0769230767935366725885888098730
  1137:   public final EFP    ATANH_C15 = new EFP (P,     -4, 0x88888e4ace4d77aaL, 0xa2aa416L << 36);  //=0.0666667095736446080100633321247
  1138:   public final EFP    ATANH_C17 = new EFP (P,     -5, 0xf0e7cfa2bdbf9821L, 0x93bcd2aL << 36);  //=0.0588148222703778409986221399492
  1139:   public final EFP    ATANH_C19 = new EFP (P,     -5, 0xdb9f4d0dedd2896fL, 0x4b48c7fL << 36);  //=0.0536187181413551121288347545022
  1140:   //  99.69bit
  1141:   public final EFP[] ATH_T = {
  1142:     //  echo read("efp.gp");for(n=0,92,efpmem([Str("1-2/(2^",n,".5+1)")])) | gp -q
  1143:     new EFP (P,     -3, 0xafb0ccc06219b7baL, 0x682764dL << 36),  //>1-2/(2^0.5+1)=0.171572875253809902396622551581
  1144:     new EFP (P,     -2, 0xf486f8adc4df1a3fL, 0x3373579L << 36),  //>1-2/(2^1.5+1)=0.477592250072517114970463586166
  1145:     new EFP (P,     -1, 0xb31638273cf89250L, 0x55f0c13L << 36),  //>1-2/(2^2.5+1)=0.699557790355330309986660974397
  1146:     new EFP (P,     -1, 0xd66b9a67d12abc57L, 0x98d2421L << 36),  //<1-2/(2^3.5+1)=0.837579393716775426922621893013
  1147:     new EFP (P,     -1, 0xea548bdf707c71a8L, 0x48f4c93L << 36),  //>1-2/(2^4.5+1)=0.915352575350412834517311077936
  1148:     new EFP (P,     -1, 0xf4ee4e9693348047L, 0xc360937L << 36),  //<1-2/(2^5.5+1)=0.956761276017646271068242267538
  1149:     new EFP (P,     -1, 0xfa67aba3bd4ef753L, 0x97d0d24L << 36),  //>1-2/(2^6.5+1)=0.978144385791264050024830160335
  1150:     new EFP (P,     -1, 0xfd2fe692fd3e80eaL, 0xf06feacL << 36),  //>1-2/(2^7.5+1)=0.989012156377834030198271666207
  1151:     new EFP (P,     -1, 0xfe96f56512becc96L, 0x5d9833cL << 36),  //>1-2/(2^8.5+1)=0.994490945030288739194890825379
  1152:     new EFP (P,     -1, 0xff4b3af63364e808L, 0x18a7859L << 36),  //>1-2/(2^9.5+1)=0.997241673572165532752151151462
  1153:     new EFP (P,     -1, 0xffa58d83926f2d61L, 0x373e4afL << 36),  //<1-2/(2^10.5+1)=0.998619885084221356182770883686
  1154:     new EFP (P,     -1, 0xffd2c2c2d8870e17L, 0xed05d07L << 36),  //<1-2/(2^11.5+1)=0.999309704370286962147601894210
  1155:     new EFP (P,     -1, 0xffe960618e30f4faL, 0x87ef4d9L << 36),  //<1-2/(2^12.5+1)=0.999654792611355549595229809320
  1156:     new EFP (P,     -1, 0xfff4aff0cb566033L, 0x22866e9L << 36),  //>1-2/(2^13.5+1)=0.999827381408374463164023282349
  1157:     new EFP (P,     -1, 0xfffa57e86632f050L, 0x0d74b69L << 36),  //<1-2/(2^14.5+1)=0.999913686979379216955639576948
  1158:     new EFP (P,     -1, 0xfffd2bf0332a7066L, 0xd4437adL << 36),  //<1-2/(2^15.5+1)=0.999956842558427322377129017797
  1159:     new EFP (P,     -1, 0xfffe95f71997573eL, 0xc3c2f8aL << 36),  //<1-2/(2^16.5+1)=0.999978421046390553788765568617
  1160:     new EFP (P,     -1, 0xffff4afb4ccbef81L, 0x0515247L << 36),  //<1-2/(2^17.5+1)=0.999989210464988558024532263171
  1161:     new EFP (P,     -1, 0xffffa57d9666003cL, 0xba71034L << 36),  //<1-2/(2^18.5+1)=0.999994605217942481540092531517
  1162:     new EFP (P,     -1, 0xffffd2bec733012dL, 0xe46d4faL << 36),  //<1-2/(2^19.5+1)=0.999997302605333276682525030987
  1163:     new EFP (P,     -1, 0xffffe95f629980b8L, 0xe320c19L << 36),  //<1-2/(2^20.5+1)=0.999998651301757145479438792148
  1164:     new EFP (P,     -1, 0xfffff4afb10cc060L, 0xafaddc0L << 36),  //<1-2/(2^21.5+1)=0.999999325650651199294269995571
  1165:     new EFP (P,     -1, 0xfffffa57d8766030L, 0xdf9aa0eL << 36),  //<1-2/(2^22.5+1)=0.999999662825268756257023430024
  1166:     new EFP (P,     -1, 0xfffffd2bec373018L, 0x80c5c71L << 36),  //>1-2/(2^23.5+1)=0.999999831412620167277390168747
  1167:     new EFP (P,     -1, 0xfffffe95f61a980cL, 0x4281f26L << 36),  //>1-2/(2^24.5+1)=0.999999915706306530925465490884
  1168:     new EFP (P,     -1, 0xffffff4afb0d0c06L, 0x2184db1L << 36),  //>1-2/(2^25.5+1)=0.999999957853152377284369196196
  1169:     new EFP (P,     -1, 0xffffffa57d867603L, 0x10cae9cL << 36),  //>1-2/(2^26.5+1)=0.999999978926575966597586691927
  1170:     new EFP (P,     -1, 0xffffffd2bec33701L, 0x8866846L << 36),  //<1-2/(2^27.5+1)=0.999999989463287927787642992063
  1171:     new EFP (P,     -1, 0xffffffe95f619a80L, 0xc433642L << 36),  //<1-2/(2^28.5+1)=0.999999994731643950016033797887
  1172:     new EFP (P,     -1, 0xfffffff4afb0cd00L, 0x6219b65L << 36),  //<1-2/(2^29.5+1)=0.999999997365821971538569960698
  1173:     new EFP (P,     -1, 0xfffffffa57d86670L, 0x310cdbbL << 36),  //>1-2/(2^30.5+1)=0.999999998682910984901923244074
  1174:     new EFP (P,     -1, 0xfffffffd2bec3334L, 0x18866dfL << 36),  //>1-2/(2^31.5+1)=0.999999999341455492234121187754
  1175:     new EFP (P,     -1, 0xfffffffe95f61999L, 0x0c4336fL << 36),  //<1-2/(2^32.5+1)=0.999999999670727746062850485280
  1176:     new EFP (P,     -1, 0xffffffff4afb0cccL, 0x46219b8L << 36),  //>1-2/(2^33.5+1)=0.999999999835363873017872715487
  1177:     new EFP (P,     -1, 0xffffffffa57d8666L, 0x1310cdcL << 36),  //>1-2/(2^34.5+1)=0.999999999917681936505548225955
  1178:     new EFP (P,     -1, 0xffffffffd2bec333L, 0x058866eL << 36),  //>1-2/(2^35.5+1)=0.999999999958840968251927080030
  1179:     new EFP (P,     -1, 0xffffffffe95f6199L, 0x81c4337L << 36),  //>1-2/(2^36.5+1)=0.999999999979420484125751781778
  1180:     new EFP (P,     -1, 0xfffffffff4afb0ccL, 0xc0a219bL << 36),  //<1-2/(2^37.5+1)=0.999999999989710242062822951330
  1181:     new EFP (P,     -1, 0xfffffffffa57d866L, 0x60410ceL << 36),  //>1-2/(2^38.5+1)=0.999999999994855121031398240775
  1182:     new EFP (P,     -1, 0xfffffffffd2bec33L, 0x301c867L << 36),  //>1-2/(2^39.5+1)=0.999999999997427560515695811665
  1183:     new EFP (P,     -1, 0xfffffffffe95f619L, 0x980d433L << 36),  //<1-2/(2^40.5+1)=0.999999999998713780257847078652
  1184:     new EFP (P,     -1, 0xffffffffff4afb0cL, 0xcc0661aL << 36),  //>1-2/(2^41.5+1)=0.999999999999356890128923332531
  1185:     new EFP (P,     -1, 0xffffffffffa57d86L, 0x660320dL << 36),  //>1-2/(2^42.5+1)=0.999999999999678445064461614567
  1186:     new EFP (P,     -1, 0xffffffffffd2bec3L, 0x33018c6L << 36),  //<1-2/(2^43.5+1)=0.999999999999839222532230794359
  1187:     new EFP (P,     -1, 0xffffffffffe95f61L, 0x9980c53L << 36),  //<1-2/(2^44.5+1)=0.999999999999919611266115393948
  1188:     new EFP (P,     -1, 0xfffffffffff4afb0L, 0xccc0626L << 36),  //>1-2/(2^45.5+1)=0.999999999999959805633057696166
  1189:     new EFP (P,     -1, 0xfffffffffffa57d8L, 0x6660312L << 36),  //>1-2/(2^46.5+1)=0.999999999999979902816528847881
  1190:     new EFP (P,     -1, 0xfffffffffffd2becL, 0x3330189L << 36),  //>1-2/(2^47.5+1)=0.999999999999989951408264423890
  1191:     new EFP (P,     -1, 0xfffffffffffe95f6L, 0x19980c4L << 36),  //<1-2/(2^48.5+1)=0.999999999999994975704132211932
  1192:     new EFP (P,     -1, 0xffffffffffff4afbL, 0x0ccc062L << 36),  //<1-2/(2^49.5+1)=0.999999999999997487852066105963
  1193:     new EFP (P,     -1, 0xffffffffffffa57dL, 0x8666031L << 36),  //<1-2/(2^50.5+1)=0.999999999999998743926033052981
  1194:     new EFP (P,     -1, 0xffffffffffffd2beL, 0xc333019L << 36),  //>1-2/(2^51.5+1)=0.999999999999999371963016526490
  1195:     new EFP (P,     -1, 0xffffffffffffe95fL, 0x619980cL << 36),  //<1-2/(2^52.5+1)=0.999999999999999685981508263245
  1196:     new EFP (P,     -1, 0xfffffffffffff4afL, 0xb0ccc06L << 36),  //<1-2/(2^53.5+1)=0.999999999999999842990754131623
  1197:     new EFP (P,     -1, 0xfffffffffffffa57L, 0xd866603L << 36),  //<1-2/(2^54.5+1)=0.999999999999999921495377065811
  1198:     new EFP (P,     -1, 0xfffffffffffffd2bL, 0xec33302L << 36),  //>1-2/(2^55.5+1)=0.999999999999999960747688532906
  1199:     new EFP (P,     -1, 0xfffffffffffffe95L, 0xf619981L << 36),  //>1-2/(2^56.5+1)=0.999999999999999980373844266453
  1200:     new EFP (P,     -1, 0xffffffffffffff4aL, 0xfb0ccc0L << 36),  //<1-2/(2^57.5+1)=0.999999999999999990186922133226
  1201:     new EFP (P,     -1, 0xffffffffffffffa5L, 0x7d86660L << 36),  //<1-2/(2^58.5+1)=0.999999999999999995093461066613
  1202:     new EFP (P,     -1, 0xffffffffffffffd2L, 0xbec3330L << 36),  //<1-2/(2^59.5+1)=0.999999999999999997546730533307
  1203:     new EFP (P,     -1, 0xffffffffffffffe9L, 0x5f61998L << 36),  //<1-2/(2^60.5+1)=0.999999999999999998773365266653
  1204:     new EFP (P,     -1, 0xfffffffffffffff4L, 0xafb0cccL << 36),  //<1-2/(2^61.5+1)=0.999999999999999999386682633327
  1205:     new EFP (P,     -1, 0xfffffffffffffffaL, 0x57d8666L << 36),  //<1-2/(2^62.5+1)=0.999999999999999999693341316663
  1206:     new EFP (P,     -1, 0xfffffffffffffffdL, 0x2bec333L << 36),  //<1-2/(2^63.5+1)=0.999999999999999999846670658332
  1207:     new EFP (P,     -1, 0xfffffffffffffffeL, 0x95f619aL << 36),  //>1-2/(2^64.5+1)=0.999999999999999999923335329166
  1208:     new EFP (P,     -1, 0xffffffffffffffffL, 0x4afb0cdL << 36),  //>1-2/(2^65.5+1)=0.999999999999999999961667664583
  1209:     new EFP (P,     -1, 0xffffffffffffffffL, 0xa57d866L << 36),  //<1-2/(2^66.5+1)=0.999999999999999999980833832291
  1210:     new EFP (P,     -1, 0xffffffffffffffffL, 0xd2bec33L << 36),  //<1-2/(2^67.5+1)=0.999999999999999999990416916146
  1211:     new EFP (P,     -1, 0xffffffffffffffffL, 0xe95f61aL << 36),  //>1-2/(2^68.5+1)=0.999999999999999999995208458073
  1212:     new EFP (P,     -1, 0xffffffffffffffffL, 0xf4afb0dL << 36),  //>1-2/(2^69.5+1)=0.999999999999999999997604229036
  1213:     new EFP (P,     -1, 0xffffffffffffffffL, 0xfa57d86L << 36),  //<1-2/(2^70.5+1)=0.999999999999999999998802114518
  1214:     new EFP (P,     -1, 0xffffffffffffffffL, 0xfd2bec3L << 36),  //<1-2/(2^71.5+1)=0.999999999999999999999401057259
  1215:     new EFP (P,     -1, 0xffffffffffffffffL, 0xfe95f62L << 36),  //>1-2/(2^72.5+1)=0.999999999999999999999700528630
  1216:     new EFP (P,     -1, 0xffffffffffffffffL, 0xff4afb1L << 36),  //>1-2/(2^73.5+1)=0.999999999999999999999850264315
  1217:     new EFP (P,     -1, 0xffffffffffffffffL, 0xffa57d8L << 36),  //<1-2/(2^74.5+1)=0.999999999999999999999925132157
  1218:     new EFP (P,     -1, 0xffffffffffffffffL, 0xffd2becL << 36),  //<1-2/(2^75.5+1)=0.999999999999999999999962566079
  1219:     new EFP (P,     -1, 0xffffffffffffffffL, 0xffe95f6L << 36),  //<1-2/(2^76.5+1)=0.999999999999999999999981283039
  1220:     new EFP (P,     -1, 0xffffffffffffffffL, 0xfff4afbL << 36),  //<1-2/(2^77.5+1)=0.999999999999999999999990641520
  1221:     new EFP (P,     -1, 0xffffffffffffffffL, 0xfffa57eL << 36),  //>1-2/(2^78.5+1)=0.999999999999999999999995320760
  1222:     new EFP (P,     -1, 0xffffffffffffffffL, 0xfffd2bfL << 36),  //>1-2/(2^79.5+1)=0.999999999999999999999997660380
  1223:     new EFP (P,     -1, 0xffffffffffffffffL, 0xfffe95fL << 36),  //<1-2/(2^80.5+1)=0.999999999999999999999998830190
  1224:     new EFP (P,     -1, 0xffffffffffffffffL, 0xffff4b0L << 36),  //>1-2/(2^81.5+1)=0.999999999999999999999999415095
  1225:     new EFP (P,     -1, 0xffffffffffffffffL, 0xffffa58L << 36),  //>1-2/(2^82.5+1)=0.999999999999999999999999707547
  1226:     new EFP (P,     -1, 0xffffffffffffffffL, 0xffffd2cL << 36),  //>1-2/(2^83.5+1)=0.999999999999999999999999853774
  1227:     new EFP (P,     -1, 0xffffffffffffffffL, 0xffffe96L << 36),  //>1-2/(2^84.5+1)=0.999999999999999999999999926887
  1228:     new EFP (P,     -1, 0xffffffffffffffffL, 0xfffff4bL << 36),  //>1-2/(2^85.5+1)=0.999999999999999999999999963443
  1229:     new EFP (P,     -1, 0xffffffffffffffffL, 0xfffffa5L << 36),  //<1-2/(2^86.5+1)=0.999999999999999999999999981722
  1230:     new EFP (P,     -1, 0xffffffffffffffffL, 0xfffffd3L << 36),  //>1-2/(2^87.5+1)=0.999999999999999999999999990861
  1231:     new EFP (P,     -1, 0xffffffffffffffffL, 0xfffffe9L << 36),  //<1-2/(2^88.5+1)=0.999999999999999999999999995430
  1232:     new EFP (P,     -1, 0xffffffffffffffffL, 0xffffff5L << 36),  //>1-2/(2^89.5+1)=0.999999999999999999999999997715
  1233:     new EFP (P,     -1, 0xffffffffffffffffL, 0xffffffaL << 36),  //<1-2/(2^90.5+1)=0.999999999999999999999999998858
  1234:     new EFP (P,     -1, 0xffffffffffffffffL, 0xffffffdL << 36),  //<1-2/(2^91.5+1)=0.999999999999999999999999999429
  1235:     new EFP (P,     -1, 0xffffffffffffffffL, 0xfffffffL << 36),  //>1-2/(2^92.5+1)=0.999999999999999999999999999714
  1236:   };  //ATH_T
  1237:   //  echo read("efp.gp");efpchebyshev("ATH_C",atanh,2*sqrt(2)-3,3-2*sqrt(2),27) | gp -q
  1238:   public final EFP       ATH_C1 = new EFP (P,      0, 0x8000000000000000L, 0x0000000L << 36);  //=1.00000000000000000000000000000
  1239:   public final EFP       ATH_C3 = new EFP (P,     -2, 0xaaaaaaaaaaaaaaaaL, 0xaaaaafaL << 36);  //=0.333333333333333333333333341344
  1240:   public final EFP       ATH_C5 = new EFP (P,     -3, 0xccccccccccccccccL, 0xcc9635cL << 36);  //=0.199999999999999999999988711045
  1241:   public final EFP       ATH_C7 = new EFP (P,     -3, 0x9249249249249249L, 0xb11c709L << 36);  //=0.142857142857142857150297250720
  1242:   public final EFP       ATH_C9 = new EFP (P,     -4, 0xe38e38e38e38e1f4L, 0xa08ab7fL << 36);  //=0.111111111111111108335586715660
  1243:   public final EFP      ATH_C11 = new EFP (P,     -4, 0xba2e8ba2e8bba550L, 0x957b4b0L << 36);  //=0.0909090909090915592120576087311
  1244:   public final EFP      ATH_C13 = new EFP (P,     -4, 0x9d89d89d88f3a6b4L, 0xb83ee9bL << 36);  //=0.0769230769229752425509012132237
  1245:   public final EFP      ATH_C15 = new EFP (P,     -4, 0x88888888e97610a0L, 0x018bbc5L << 36);  //=0.0666666666776860883121262399402
  1246:   public final EFP      ATH_C17 = new EFP (P,     -5, 0xf0f0f0b6e98b6c2fL, 0x176ec78L << 36);  //=0.0588235285673331770514149020773
  1247:   public final EFP      ATH_C19 = new EFP (P,     -5, 0xd79442422528c14bL, 0xdacdc08L << 36);  //=0.0526316250055264844984084010822
  1248:   public final EFP      ATH_C21 = new EFP (P,     -5, 0xc30a54423d395d6dL, 0xa2f5188L << 36);  //=0.0476172725064557245020882061529
  1249:   public final EFP      ATH_C23 = new EFP (P,     -5, 0xb247b3a940a7a020L, 0x5cb7483L << 36);  //=0.0435254114163771411702547167136
  1250:   public final EFP      ATH_C25 = new EFP (P,     -5, 0xa07d6fb3e1085165L, 0x68590abL << 36);  //=0.0391821254143583526005317341260
  1251:   public final EFP      ATH_C27 = new EFP (P,     -5, 0xb976c8a2f3029b2dL, 0xa0b471bL << 36);  //=0.0452792966236194263462909201691
  1252:   //  98.60bit
  1253: 
  1254:   //------------------------------------------------------------------------
  1255:   //cos
  1256:   //  echo read("efp.gp");efpchebyshev("COS_C",cos,-Pi/4,Pi/4,20) | gp -q
  1257:   public final EFP       COS_C0 = new EFP (P,      0, 0x8000000000000000L, 0x0000000L << 36);  //=1.00000000000000000000000000000
  1258:   public final EFP       COS_C2 = new EFP (M,     -2, 0xffffffffffffffffL, 0xffffff8L << 36);  //=-0.499999999999999999999999999192
  1259:   public final EFP       COS_C4 = new EFP (P,     -5, 0xaaaaaaaaaaaaaaaaL, 0xaaa9a56L << 36);  //=0.0416666666666666666666666138992
  1260:   public final EFP       COS_C6 = new EFP (M,    -10, 0xb60b60b60b60b60bL, 0x5d7bff4L << 36);  //=-0.00138888888888888888888755433738
  1261:   public final EFP       COS_C8 = new EFP (P,    -16, 0xd00d00d00d00d002L, 0x8a46e65L << 36);  //=2.48015873015873015699919557419e-5
  1262:   public final EFP      COS_C10 = new EFP (M,    -22, 0x93f27dbbc4facfccL, 0xd7af990L << 36);  //=-2.75573192239858775556350380978e-7
  1263:   public final EFP      COS_C12 = new EFP (P,    -29, 0x8f76c77fc6961076L, 0x0290d00L << 36);  //=2.08767569878619213856987201647e-9
  1264:   public final EFP      COS_C14 = new EFP (M,    -37, 0xc9cba54576804449L, 0x648c611L << 36);  //=-1.14707455958584021049089234187e-11
  1265:   public final EFP      COS_C16 = new EFP (P,    -45, 0xd73f9e26754ce09dL, 0xec906ebL << 36);  //=4.77947696821877613102951591111e-14
  1266:   public final EFP      COS_C18 = new EFP (M,    -53, 0xb412768e7c3c3046L, 0x846cd1fL << 36);  //=-1.56187668293428465635746630579e-16
  1267:   public final EFP      COS_C20 = new EFP (P,    -62, 0xf0dad505af592189L, 0x064973cL << 36);  //=4.08023924165342585701515258359e-19
  1268:   //  97.20bit
  1269:   //  echo read("efp.gp");efpchebyshev("SIN_C",sin,-Pi/4,Pi/4,21) | gp -q
  1270:   public final EFP       SIN_C1 = new EFP (P,      0, 0x8000000000000000L, 0x0000000L << 36);  //=1.00000000000000000000000000000
  1271:   public final EFP       SIN_C3 = new EFP (M,     -3, 0xaaaaaaaaaaaaaaaaL, 0xaaaaaa8L << 36);  //=-0.166666666666666666666666666532
  1272:   public final EFP       SIN_C5 = new EFP (P,     -7, 0x8888888888888888L, 0x88880d0L << 36);  //=0.00833333333333333333333332709649
  1273:   public final EFP       SIN_C7 = new EFP (M,    -13, 0xd00d00d00d00d00cL, 0xfe77205L << 36);  //=-1.98412698412698412698291342662e-4
  1274:   public final EFP       SIN_C9 = new EFP (P,    -19, 0xb8ef1d2ab6399c76L, 0xfe4484aL << 36);  //=2.75573192239858906394404635468e-6
  1275:   public final EFP      SIN_C11 = new EFP (M,    -26, 0xd7322b3faa27078eL, 0x1700055L << 36);  //=-2.50521083854417101136670463394e-8
  1276:   public final EFP      SIN_C13 = new EFP (P,    -33, 0xb092309d433be4baL, 0xeb15e86L << 36);  //=1.60590438368179416703490738961e-10
  1277:   public final EFP      SIN_C15 = new EFP (M,    -41, 0xd73f9f392253780eL, 0x670f3ecL << 36);  //=-7.64716373079884612335141370435e-13
  1278:   public final EFP      SIN_C17 = new EFP (P,    -49, 0xca963aa1cfea3bf8L, 0x08cec0aL << 36);  //=2.81145706929778488157207193776e-15
  1279:   public final EFP      SIN_C19 = new EFP (M,    -57, 0x97a3db8f70e5ae02L, 0x8f1dd1fL << 36);  //=-8.22042461090320344889517792891e-18
  1280:   public final EFP      SIN_C21 = new EFP (P,    -66, 0xb791d94ca9fd98fdL, 0x74f2261L << 36);  //=1.94362003290782920561352619652e-20
  1281:   //  96.74bit
  1282: 
  1283:   //------------------------------------------------------------------------
  1284:   //cosh
  1285:   //  echo read("efp.gp");efpchebyshev("COSH_C",cosh,-1/8,1/8,14) | gp -q
  1286:   public final EFP      COSH_C0 = new EFP (P,      0, 0x8000000000000000L, 0x0000000L << 36);  //=1.00000000000000000000000000000
  1287:   public final EFP      COSH_C2 = new EFP (P,     -1, 0x8000000000000000L, 0x0000000L << 36);  //=0.500000000000000000000000000000
  1288:   public final EFP      COSH_C4 = new EFP (P,     -5, 0xaaaaaaaaaaaaaaaaL, 0xaaa9902L << 36);  //=0.0416666666666666666666666096078
  1289:   public final EFP      COSH_C6 = new EFP (P,    -10, 0xb60b60b60b60b60bL, 0xa75a997L << 36);  //=0.00138888888888888888891810606314
  1290:   public final EFP      COSH_C8 = new EFP (P,    -16, 0xd00d00d00d00beb4L, 0xa29cfbaL << 36);  //=2.48015873015872942413289979337e-5
  1291:   public final EFP     COSH_C10 = new EFP (P,    -22, 0x93f27dbbc74aee4dL, 0x312895cL << 36);  //=2.75573192240861864407003360028e-7
  1292:   public final EFP     COSH_C12 = new EFP (P,    -29, 0x8f76c72851473b51L, 0xdc04f2cL << 36);  //=2.08767562292826617371683025321e-9
  1293:   public final EFP     COSH_C14 = new EFP (P,    -37, 0xc9d919ab996aa4aeL, 0x80c913fL << 36);  //=1.14737331357355798829750446122e-11
  1294:   //  100.26bit
  1295: 
  1296:   //------------------------------------------------------------------------
  1297:   //exp
  1298:   public final EFP[] EXP_P_I = {
  1299:     //  echo read("efp.gp");for(n=0,14,efpmem([Str("exp(2^",n,")")])) | gp -q
  1300:     new EFP (P,      1, 0xadf85458a2bb4a9aL, 0xafdc562L << 36),  //<exp(2^0)=2.71828182845904523536028747135
  1301:     new EFP (P,      2, 0xec7325c6a6ed6e61L, 0x9d1dd10L << 36),  //<exp(2^1)=7.38905609893065022723042746058
  1302:     new EFP (P,      5, 0xda64817139d2c33cL, 0x6b69dffL << 36),  //>exp(2^2)=54.5981500331442390781102612029
  1303:     new EFP (P,     11, 0xba4f53ea38636f85L, 0xf007042L << 36),  //<exp(2^3)=2980.95798704172827474359209945
  1304:     new EFP (P,     23, 0x87975e8540010249L, 0x11f8b84L << 36),  //<exp(2^4)=8886110.52050787263676302374078
  1305:     new EFP (P,     46, 0x8fa1fe625b3163ecL, 0x23c4201L << 36),  //>exp(2^5)=78962960182680.6951609780226351
  1306:     new EFP (P,     92, 0xa12cc167acbe6902L, 0xe71eadaL << 36),  //<exp(2^6)=6235149080811616882909238708.93
  1307:     new EFP (P,    184, 0xcaf2a62eea10bbfaL, 0x9fa6a91L << 36),  //>exp(2^7)=3.88770840599459509222267368836e+55
  1308:     new EFP (P,    369, 0xa0e3d440a5f5d071L, 0x919807cL << 36),  //>exp(2^8)=1.51142766500410354252008966571e+111
  1309:     new EFP (P,    738, 0xca3b2825d4297360L, 0x4e42b3eL << 36),  //<exp(2^9)=2.28441358653975664037875151712e+222
  1310:     new EFP (P,   1477, 0x9fc169073a8d0d13L, 0x21c376bL << 36),  //<exp(2^10)=5.21854543436743420112120953370e+444
  1311:     new EFP (P,   2954, 0xc763a52d0570da4eL, 0xe13cad2L << 36),  //<exp(2^11)=2.72332164505571925012480592774e+889
  1312:     new EFP (P,   5909, 0x9b4c119529dab99dL, 0xde62927L << 36),  //<exp(2^12)=7.41648078242898890481921050373e+1778
  1313:     new EFP (P,  11818, 0xbc6a67ca24e9ba38L, 0x5a44770L << 36),  //<exp(2^13)=5.50041871961385074607498352511e+3557
  1314:     new EFP (P,  23637, 0x8aac74ab03b22463L, 0x55451adL << 36),  //<exp(2^14)=3.02546060910784732301427230567e+7115
  1315:   };  //EXP_P_I
  1316:   public final EFP[] EXP_M_I = {
  1317:     //  echo read("efp.gp");for(n=0,14,efpmem([Str("exp(-2^",n,")")])) | gp -q
  1318:     new EFP (P,     -2, 0xbc5ab1b16779be35L, 0x75bd8f0L << 36),  //<exp(-2^0)=0.367879441171442321595523770161
  1319:     new EFP (P,     -3, 0x8a95551dfc0e5cfeL, 0xdbb7571L << 36),  //>exp(-2^1)=0.135335283236612691893999494972
  1320:     new EFP (P,     -6, 0x960aadc109e7a3bfL, 0x4578099L << 36),  //<exp(-2^2)=0.0183156388887341802937180212732
  1321:     new EFP (P,    -12, 0xafe10820813d65dfL, 0xe6a33c0L << 36),  //<exp(-2^3)=3.35462627902511838821389125781e-4
  1322:     new EFP (P,    -24, 0xf1aaddd7742e56d3L, 0x2fb9f99L << 36),  //<exp(-2^4)=1.12535174719259114513775179060e-7
  1323:     new EFP (P,    -47, 0xe42327bb0b2340f1L, 0x4cd0092L << 36),  //<exp(-2^5)=1.26641655490941757231209041560e-14
  1324:     new EFP (P,    -93, 0xcb4ea3990f265d5fL, 0x9694038L << 36),  //<exp(-2^6)=1.60381089054863785297608703414e-28
  1325:     new EFP (P,   -185, 0xa175cf9cd7d85844L, 0x76b75a8L << 36),  //>exp(-2^7)=2.57220937264241482683953808361e-56
  1326:     new EFP (P,   -370, 0xcbaacab56a74dfdcL, 0xe09d13dL << 36),  //<exp(-2^8)=6.61626105670948526102953080736e-112
  1327:     new EFP (P,   -739, 0xa2084f6d90498ad1L, 0xc4658daL << 36),  //<exp(-2^9)=4.37749103705305145412147276290e-223
  1328:     new EFP (P,  -1478, 0xcd1d09977435cc77L, 0x7a9a998L << 36),  //>exp(-2^10)=1.91624277794797998988359419145e-445
  1329:     new EFP (P,  -2955, 0xa45784a7bcca7d6dL, 0xc205c90L << 36),  //<exp(-2^11)=3.67198638403779134660860694154e-890
  1330:     new EFP (P,  -5910, 0xd3007fc4b14655ddL, 0x1be84e5L << 36),  //>exp(-2^12)=1.34834840045589340763610867190e-1779
  1331:     new EFP (P, -11819, 0xade9d29e7bfeb08eL, 0x33a8236L << 36),  //<exp(-2^13)=1.81804340901196629372122861908e-3558
  1332:     new EFP (P, -23638, 0xec4bb8768ab8ab91L, 0x718a7e7L << 36),  //<exp(-2^14)=3.30528183705185176386021874079e-7116
  1333:   };  //EXP_M_I
  1334:   //  echo read("efp.gp");efpchebyshev("EXP_C",exp,-1/64,1/64,10) | gp -q
  1335:   public final EFP       EXP_C0 = new EFP (P,      0, 0x8000000000000000L, 0x0000000L << 36);  //=1.00000000000000000000000000000
  1336:   public final EFP       EXP_C1 = new EFP (P,      0, 0x8000000000000000L, 0x0000001L << 36);  //=1.00000000000000000000000000040
  1337:   public final EFP       EXP_C2 = new EFP (P,     -1, 0x8000000000000000L, 0x0000000L << 36);  //=0.500000000000000000000000000000
  1338:   public final EFP       EXP_C3 = new EFP (P,     -3, 0xaaaaaaaaaaaaaaaaL, 0xaa4e330L << 36);  //=0.166666666666666666666647544847
  1339:   public final EFP       EXP_C4 = new EFP (P,     -5, 0xaaaaaaaaaaaaaaaaL, 0xaa6fd2eL << 36);  //=0.0416666666666666666666636245582
  1340:   public final EFP       EXP_C5 = new EFP (P,     -7, 0x8888888888888a8eL, 0x59cdd2cL << 36);  //=0.00833333333333333377194178560698
  1341:   public final EFP       EXP_C6 = new EFP (P,    -10, 0xb60b60b60b60b801L, 0x80edd29L << 36);  //=0.00138888888888888894205353133322
  1342:   public final EFP       EXP_C7 = new EFP (P,    -13, 0xd00d00cffa827bd9L, 0xd1653b8L << 36);  //=1.98412698408592036950274523884e-4
  1343:   public final EFP       EXP_C8 = new EFP (P,    -16, 0xd00d00cffddf45a5L, 0xbdc8fc1L << 36);  //=2.48015873011673314697922289744e-5
  1344:   public final EFP       EXP_C9 = new EFP (P,    -19, 0xb8ef6724028aa32dL, 0x54addf6L << 36);  //=2.75574874209809900360756318657e-6
  1345:   public final EFP      EXP_C10 = new EFP (P,    -22, 0x93f2b38858c23b84L, 0xa93e7c6L << 36);  //=2.75574721303097208995296164475e-7
  1346:   //  98.10bit
  1347:   public final EFP[] EXP_P_T = {
  1348:     //  echo read("efp.gp");for(n=0,63,efpmem([Str("exp(",n,"/64)")])) | gp -q
  1349:     new EFP (P,      0, 0x8000000000000000L, 0x0000000L << 36),  //=exp(0/64)=1.00000000000000000000000000000
  1350:     new EFP (P,      0, 0x8204055aaef1c8bdL, 0x5c3259fL << 36),  //<exp(1/64)=1.01574770858668574745853507208
  1351:     new EFP (P,      0, 0x84102b00893f64c7L, 0x05e841dL << 36),  //<exp(2/64)=1.03174340749910267093874781528
  1352:     new EFP (P,      0, 0x862491b414f45e14L, 0x967f31fL << 36),  //>exp(3/64)=1.04799100201663270227673829182
  1353:     new EFP (P,      0, 0x88415abbe9a76beaL, 0xd8d00cfL << 36),  //<exp(4/64)=1.06449445891785942956339059464
  1354:     new EFP (P,      0, 0x8a66a7e4c4e6b22aL, 0xaf50ce3L << 36),  //<exp(5/64)=1.08125780744903960314089465174
  1355:     new EFP (P,      0, 0x8c949b83a7066b44L, 0x9e8c66eL << 36),  //>exp(6/64)=1.09828514030782584865020993426
  1356:     new EFP (P,      0, 0x8ecb5877f873c9e8L, 0xac7a4d3L << 36),  //<exp(7/64)=1.11558061464248075869370450838
  1357:     new EFP (P,      0, 0x910b022db7ae67ceL, 0x76b441cL << 36),  //<exp(8/64)=1.13314845306682631682900722781
  1358:     new EFP (P,      0, 0x9353bc9fb00b215aL, 0xeb98600L << 36),  //<exp(9/64)=1.15099294469117644932213966578
  1359:     new EFP (P,      0, 0x95a5ac59b963ca80L, 0x9bb3e06L << 36),  //<exp(10/64)=1.16911844616950440229818469151
  1360:     new EFP (P,      0, 0x9800f67b00d7b805L, 0xeae44b2L << 36),  //>exp(11/64)=1.18752938276310060558880782283
  1361:     new EFP (P,      0, 0x9a65c0b85ac1a96aL, 0x7062466L << 36),  //>exp(12/64)=1.20623024942098071065558601045
  1362:     new EFP (P,      0, 0x9cd4315e9e0832fbL, 0xa34f398L << 36),  //>exp(13/64)=1.22522561187730757944926592758
  1363:     new EFP (P,      0, 0x9f4c6f5508ee5d51L, 0xbbdee02L << 36),  //<exp(14/64)=1.24452010776609515494619895208
  1364:     new EFP (P,      0, 0xa1cea21faf8ac771L, 0xd268bc6L << 36),  //<exp(15/64)=1.26411844775346636339843460346
  1365:     new EFP (P,      0, 0xa45af1e1f40c333bL, 0x3de1db5L << 36),  //>exp(16/64)=1.28402541668774148407342056806
  1366:     new EFP (P,      0, 0xa6f1876108f3009dL, 0xa911f65L << 36),  //<exp(17/64)=1.30424587476763777548930001105
  1367:     new EFP (P,      0, 0xa9928c067d67bb65L, 0x16cc14dL << 36),  //>exp(18/64)=1.32478475872886556893523756069
  1368:     new EFP (P,      0, 0xac3e29e2d3d7813bL, 0x0e93c01L << 36),  //<exp(19/64)=1.34564708304941053148260309432
  1369:     new EFP (P,      0, 0xaef48bb022ffa9daL, 0x899232aL << 36),  //>exp(20/64)=1.36683794117379636283875677272
  1370:     new EFP (P,      0, 0xb1b5dcd4c192c269L, 0x39863eeL << 36),  //<exp(21/64)=1.38836250675662682438443747530
  1371:     new EFP (P,      0, 0xb4824965fca1967eL, 0xd7cc083L << 36),  //>exp(22/64)=1.41022603492571070569972793418
  1372:     new EFP (P,      0, 0xb759fe2ad8f3ada4L, 0xeb266efL << 36),  //>exp(23/64)=1.43243386356507811497143795682
  1373:     new EFP (P,      0, 0xba3d289edf7b5311L, 0xa3c5b2dL << 36),  //>exp(24/64)=1.45499141461820133605379369199
  1374:     new EFP (P,      0, 0xbd2bf6f4f511ef19L, 0xfdaedb7L << 36),  //<exp(25/64)=1.47790419541173842781020947116
  1375:     new EFP (P,      0, 0xc026981a3daa2e5dL, 0x65cddb9L << 36),  //>exp(26/64)=1.50117780000012275190098436819
  1376:     new EFP (P,      0, 0xc32d3bb90b262a0aL, 0xee10dd1L << 36),  //>exp(27/64)=1.52481791053132670462330880246
  1377:     new EFP (P,      0, 0xc640123bd8007ee1L, 0x26da077L << 36),  //>exp(28/64)=1.54883029863413309799855198460
  1378:     new EFP (P,      0, 0xc95f4cd04df7fdb9L, 0x9bfe7cfL << 36),  //>exp(29/64)=1.57322082682725288629956103460
  1379:     new EFP (P,      0, 0xcc8b1d6a58ee609bL, 0x8c7b82aL << 36),  //>exp(30/64)=1.59799544995063326789964514708
  1380:     new EFP (P,      0, 0xcfc3b6c7462b3282L, 0xc0bf5ecL << 36),  //>exp(31/64)=1.62316021661930561000723988290
  1381:     new EFP (P,      0, 0xd3094c70f034de4bL, 0x96ff7d6L << 36),  //>exp(32/64)=1.64872127070012814684865078781
  1382:     new EFP (P,      0, 0xd65c12c0f772a298L, 0xdbec9f1L << 36),  //>exp(33/64)=1.67468485281178399151929488215
  1383:     new EFP (P,      0, 0xd9bc3ee407caf517L, 0x6670eb8L << 36),  //<exp(34/64)=1.70105730184840067940618349548
  1384:     new EFP (P,      0, 0xdd2a06dd2b72af4bL, 0x7809cf2L << 36),  //>exp(35/64)=1.72784505652716322817720155244
  1385:     new EFP (P,      0, 0xe0a5a1892b223221L, 0x955289eL << 36),  //>exp(36/64)=1.75505465696029855724404703660
  1386:     new EFP (P,      0, 0xe42f46a1fbe683ddL, 0x1461033L << 36),  //<exp(37/64)=1.78269274625181505976568319611
  1387:     new EFP (P,      0, 0xe7c72ec23ac545bfL, 0x66c74a2L << 36),  //<exp(38/64)=1.81076607211938716412053043885
  1388:     new EFP (P,      0, 0xeb6d9368b66b3bf1L, 0xc77fd15L << 36),  //>exp(39/64)=1.83928148854178086081396691197
  1389:     new EFP (P,      0, 0xef22aefc071e02e5L, 0x44bd839L << 36),  //<exp(40/64)=1.86824595743222240650183562019
  1390:     new EFP (P,      0, 0xf2e6bcce352a7191L, 0x2542fa9L << 36),  //>exp(41/64)=1.89766655033811875072299372819
  1391:     new EFP (P,      0, 0xf6b9f9206e0a0fc3L, 0xabd8e27L << 36),  //>exp(42/64)=1.92755045016754466459088319259
  1392:     new EFP (P,      0, 0xfa9ca126c87af32bL, 0xb68e7a5L << 36),  //<exp(43/64)=1.95790495294291808566640006188
  1393:     new EFP (P,      0, 0xfe8ef30c17c644e9L, 0x61db684L << 36),  //<exp(44/64)=1.98873746958229183111747734965
  1394:     new EFP (P,      1, 0x814896fae739522fL, 0xd207331L << 36),  //>exp(45/64)=2.02005552770869657368538323652
  1395:     new EFP (P,      1, 0x8351c903f850495fL, 0xf940cd1L << 36),  //>exp(46/64)=2.05186677348797682356990329034
  1396:     new EFP (P,      1, 0x856330348b2806b5L, 0x6ded10fL << 36),  //<exp(47/64)=2.08417897349556861578737600208
  1397:     new EFP (P,      1, 0x877ceda33ee7bdeaL, 0x61ab772L << 36),  //>exp(48/64)=2.11700001661267466854536981984
  1398:     new EFP (P,      1, 0x899f22ec174a8c1aL, 0x3d1e65aL << 36),  //>exp(49/64)=2.15033791595229995544075729131
  1399:     new EFP (P,      1, 0x8bc9f23296628075L, 0x3fa07acL << 36),  //<exp(50/64)=2.18420081081561792457635501545
  1400:     new EFP (P,      1, 0x8dfd7e23ded395adL, 0xcd8bb99L << 36),  //<exp(51/64)=2.21859696867914500278504863552
  1401:     new EFP (P,      1, 0x9039e9f8dea8bffcL, 0x88e9e18L << 36),  //<exp(52/64)=2.25353478721320854485733107843
  1402:     new EFP (P,      1, 0x927f597882e5bd3aL, 0x5153fb8L << 36),  //<exp(53/64)=2.28902279633220102782484126941
  1403:     new EFP (P,      1, 0x94cdf0f9f3f8e05cL, 0x238b7d8L << 36),  //<exp(54/64)=2.32506966027712105082411019795
  1404:     new EFP (P,      1, 0x9725d566db309f9dL, 0x44caba1L << 36),  //<exp(55/64)=2.36168417973090958374598641969
  1405:     new EFP (P,      1, 0x99872c3db1593ce1L, 0x10ffabeL << 36),  //>exp(56/64)=2.39887529396709791469164573372
  1406:     new EFP (P,      1, 0x9bf21b9416a77258L, 0x29f648fL << 36),  //>exp(57/64)=2.43665208303229187916051857011
  1407:     new EFP (P,      1, 0x9e66ca193415a245L, 0xd019082L << 36),  //<exp(58/64)=2.47502376996302521487450632646
  1408:     new EFP (P,      1, 0xa0e55f1826599febL, 0x28fc34fL << 36),  //>exp(59/64)=2.51399972303752327721338612207
  1409:     new EFP (P,      1, 0xa36e027a7299c128L, 0x96ff655L << 36),  //>exp(60/64)=2.55358945806292687344696507755
  1410:     new EFP (P,      1, 0xa600dcca8508845aL, 0xa0a2a0dL << 36),  //<exp(61/64)=2.59380264069853463138124458905
  1411:     new EFP (P,      1, 0xa89e1736398eb461L, 0xfd1d370L << 36),  //>exp(62/64)=2.63464908881563111180226593835
  1412:     new EFP (P,      1, 0xab45db916eac95afL, 0x15018e6L << 36),  //>exp(63/64)=2.67613877489447680634939027005
  1413:   };  //EXP_P_T
  1414:   public final EFP[] EXP_M_T = {
  1415:     //  echo read("efp.gp");for(n=0,63,efpmem([Str("exp(-",n,"/64)")])) | gp -q
  1416:     new EFP (P,      0, 0x8000000000000000L, 0x0000000L << 36),  //=exp(-0/64)=1.00000000000000000000000000000
  1417:     new EFP (P,     -1, 0xfc07f55ff77d2493L, 0xe885eebL << 36),  //>exp(-1/64)=0.984496437005408405986988829697
  1418:     new EFP (P,     -1, 0xf81fab5445aebc8aL, 0x58055fdL << 36),  //>exp(-2/64)=0.969233234476344081848109193246
  1419:     new EFP (P,     -1, 0xf446e357f67dfd8eL, 0x33bd6c8L << 36),  //>exp(-3/64)=0.954206665969188316193630283451
  1420:     new EFP (P,     -1, 0xf07d5fde38151e72L, 0xf18ff03L << 36),  //<exp(-4/64)=0.939413062813475786119710824622
  1421:     new EFP (P,     -1, 0xecc2e44e820d18c3L, 0xcc6f18aL << 36),  //>exp(-5/64)=0.924848813216204834253805278288
  1422:     new EFP (P,     -1, 0xe9173500cbe0159aL, 0xa3084a2L << 36),  //>exp(-6/64)=0.910510361380034127843504886276
  1423:     new EFP (P,     -1, 0xe57a1739d263ec94L, 0x8222e86L << 36),  //<exp(-7/64)=0.896394206635150411490036193614
  1424:     new EFP (P,     -1, 0xe1eb51276c110c3cL, 0x3eb126aL << 36),  //>exp(-8/64)=0.882496902584595402864892143229
  1425:     new EFP (P,     -1, 0xde6aa9dcebdb100bL, 0x56a61aaL << 36),  //>exp(-9/64)=0.868815056262843166738503531191
  1426:     new EFP (P,     -1, 0xdaf7e94f9261313dL, 0x5fd7d71L << 36),  //>exp(-10/64)=0.855345327307422537695731635071
  1427:     new EFP (P,     -1, 0xd792d8530d3da531L, 0x2b5abcbL << 36),  //<exp(-11/64)=0.842084427143382346804098369012
  1428:     new EFP (P,     -1, 0xd43b4096043bde02L, 0xc9dd905L << 36),  //<exp(-12/64)=0.829029118180400343014645509343
  1429:     new EFP (P,     -1, 0xd0f0ec9eb43e8078L, 0xe9af6bbL << 36),  //<exp(-13/64)=0.816176213022339786977651290021
  1430:     new EFP (P,     -1, 0xcdb3a7c7979ebd5cL, 0x80489dbL << 36),  //>exp(-14/64)=0.803522573689060733999784586587
  1431:     new EFP (P,     -1, 0xca833e3c1bcf93e9L, 0x0747d1aL << 36),  //>exp(-15/64)=0.791065110850296014797613273422
  1432:     new EFP (P,     -1, 0xc75f7cf564105743L, 0x415cbcaL << 36),  //>exp(-16/64)=0.778800783071404868245170266978
  1433:     new EFP (P,     -1, 0xc44831b718faa1d9L, 0xc29d8daL << 36),  //>exp(-17/64)=0.766726596070820080189659545196
  1434:     new EFP (P,     -1, 0xc13d2b0c44b8af4aL, 0x68aa4e8L << 36),  //>exp(-18/64)=0.754839601989007337327347095918
  1435:     new EFP (P,     -1, 0xbe3e38443bb1dfefL, 0x65597dbL << 36),  //>exp(-19/64)=0.743136898668758315788243931197
  1436:     new EFP (P,     -1, 0xbb4b296f917bf09aL, 0x22fbaa2L << 36),  //<exp(-20/64)=0.731615628946641791159559420491
  1437:     new EFP (P,     -1, 0xb863cf5d19e0354eL, 0x91dbb17L << 36),  //<exp(-21/64)=0.720272979955439780859653963562
  1438:     new EFP (P,     -1, 0xb587fb96f5c4e712L, 0xa053452L << 36),  //>exp(-22/64)=0.709106182437398411721447410017
  1439:     new EFP (P,     -1, 0xb2b7805fabcb5327L, 0xcdbad0eL << 36),  //<exp(-23/64)=0.698112510068125846011729230536
  1440:     new EFP (P,     -1, 0xaff230af4c747553L, 0xd8db805L << 36),  //>exp(-24/64)=0.687289278790972198545202339147
  1441:     new EFP (P,     -1, 0xad37e030a19e3f45L, 0x315a9f6L << 36),  //<exp(-25/64)=0.676633846161728936684014615264
  1442:     new EFP (P,     -1, 0xaa88633e692c84abL, 0x9760affL << 36),  //<exp(-26/64)=0.666143610703487774469791357130
  1443:     new EFP (P,     -1, 0xa7e38ee09ab13658L, 0x8e4fa89L << 36),  //>exp(-27/64)=0.655816011271501552530892254763
  1444:     new EFP (P,     -1, 0xa54938c9b7e846b1L, 0x22756d1L << 36),  //<exp(-28/64)=0.645648526427892037348355680061
  1445:     new EFP (P,     -1, 0xa2b9375427dc3ef5L, 0xfdb6013L << 36),  //<exp(-29/64)=0.635638673826051977545950221758
  1446:     new EFP (P,     -1, 0xa033617f9c893772L, 0xb7f2709L << 36),  //>exp(-30/64)=0.625784009604591121679874456535
  1447:     new EFP (P,     -1, 0x9db78eee82d48c8cL, 0x5e432e4L << 36),  //>exp(-31/64)=0.616082127790678232119777202994
  1448:     new EFP (P,     -1, 0x9b4597e37cb04ff3L, 0xd675a35L << 36),  //<exp(-32/64)=0.606530659712633423603799534991
  1449:     new EFP (P,     -1, 0x98dd553ee54217fdL, 0x5f7533bL << 36),  //>exp(-33/64)=0.597127273421627413476334433038
  1450:     new EFP (P,     -1, 0x967ea07c5ee56f55L, 0x27376f0L << 36),  //>exp(-34/64)=0.587869673122346494029544878732
  1451:     new EFP (P,     -1, 0x942953b06ae2c503L, 0xc6e249aL << 36),  //<exp(-35/64)=0.578755598612484226311212770922
  1452:     new EFP (P,     -1, 0x91dd49860ab457feL, 0x49ecbc0L << 36),  //<exp(-36/64)=0.569782824730923009766629689829
  1453:     new EFP (P,     -1, 0x8f9a5d3c6ab3325dL, 0xe98839bL << 36),  //>exp(-37/64)=0.560949160814470803677121262158
  1454:     new EFP (P,     -1, 0x8d606aa49606deddL, 0x68c91a3L << 36),  //<exp(-38/64)=0.552252450163020365060397724731
  1455:     new EFP (P,     -1, 0x8b2f4e1f33b31766L, 0x67ee085L << 36),  //>exp(-39/64)=0.543690569513000424018191779441
  1456:     new EFP (P,     -1, 0x8906e49a4c9f3d59L, 0x58a5d18L << 36),  //>exp(-40/64)=0.535261428518990241956622508022
  1457:     new EFP (P,     -1, 0x86e70b8f1a73fbd8L, 0x1858e19L << 36),  //>exp(-41/64)=0.526962969243370991158669068037
  1458:     new EFP (P,     -1, 0x84cfa0ffdf2c01beL, 0x9229f8cL << 36),  //>exp(-42/64)=0.518793165653889356342645457337
  1459:     new EFP (P,     -1, 0x82c08375c5354c26L, 0xfed9d9bL << 36),  //>exp(-43/64)=0.510750023129010690574689186791
  1460:     new EFP (P,     -1, 0x80b991fec8010361L, 0x182aa18L << 36),  //<exp(-44/64)=0.502831577970940959688636611438
  1461:     new EFP (P,     -2, 0xfd75585749c0e65aL, 0xe0e13c7L << 36),  //<exp(-45/64)=0.495035896926198581667568450965
  1462:     new EFP (P,     -2, 0xf987641ba81c57c1L, 0x08b166eL << 36),  //>exp(-46/64)=0.487361076713619110714884696034
  1463:     new EFP (P,     -2, 0xf5a9086b1385b9a8L, 0xb38238dL << 36),  //>exp(-47/64)=0.479805243559677530439035766024
  1464:     new EFP (P,     -2, 0xf1da075f7e6bf297L, 0x7e1e9a0L << 36),  //>exp(-48/64)=0.472366552741014707138046550943
  1465:     new EFP (P,     -2, 0xee1a240886d56f4fL, 0x1d073e3L << 36),  //>exp(-49/64)=0.465043188134056313033903075269
  1466:     new EFP (P,     -2, 0xea692267a754ef29L, 0x4911dc3L << 36),  //<exp(-50/64)=0.457833361771614260902146840654
  1467:     new EFP (P,     -2, 0xe6c6c76c771c2d60L, 0x96a4be2L << 36),  //<exp(-51/64)=0.450735313406362396291400791633
  1468:     new EFP (P,     -2, 0xe332d8f0f8f06820L, 0xcd7f8e6L << 36),  //<exp(-52/64)=0.443747310081079871847240349999
  1469:     new EFP (P,     -2, 0xdfad1db5f8c5b458L, 0x70f8209L << 36),  //<exp(-53/64)=0.436867645705557280554577433900
  1470:     new EFP (P,     -2, 0xdc355d5f77c6f7b3L, 0x2d36b03L << 36),  //<exp(-54/64)=0.430094640640062251395946518606
  1471:     new EFP (P,     -2, 0xd8cb6071269148f0L, 0x7444892L << 36),  //<exp(-55/64)=0.423426641285262812386917145715
  1472:     new EFP (P,     -2, 0xd56ef04aed6a5a01L, 0x2a76dd4L << 36),  //<exp(-56/64)=0.416862019678508402585297182336
  1473:     new EFP (P,     -2, 0xd21fd725823a6f09L, 0x0871f0bL << 36),  //<exp(-57/64)=0.410399173096369966862764164781
  1474:     new EFP (P,     -2, 0xcedde00f0c13419aL, 0x4cddcf7L << 36),  //>exp(-58/64)=0.404036523663342095355029060572
  1475:     new EFP (P,     -2, 0xcba8d6e7d40e0852L, 0x3c9f035L << 36),  //>exp(-59/64)=0.397772517966611673942683333515
  1476:     new EFP (P,     -2, 0xc880885f034bb070L, 0x530b9f4L << 36),  //<exp(-60/64)=0.391605626676798993226807728469
  1477:     new EFP (P,     -2, 0xc564c1ef6de32926L, 0x3b6f5ecL << 36),  //<exp(-61/64)=0.385534344174578721612836653797
  1478:     new EFP (P,     -2, 0xc25551dc6a8a6f40L, 0xdc958f1L << 36),  //<exp(-62/64)=0.379557188183089583659076182722
  1479:     new EFP (P,     -2, 0xbf52072eb6c7d377L, 0xd431325L << 36),  //>exp(-63/64)=0.373672699406042998133147992189
  1480:   };  //EXP_M_T
  1481: 
  1482:   //------------------------------------------------------------------------
  1483:   //exp10
  1484:   public final EFP[] EXP10_P_I = {
  1485:     //  echo read("efp.gp");for(n=0,13,efpmem([Str("10^(2^",n,")")])) | gp -q
  1486:     new EFP (P,      3, 0xa000000000000000L, 0x0000000L << 36),  //=10^(2^0)=10.0000000000000000000000000000
  1487:     new EFP (P,      6, 0xc800000000000000L, 0x0000000L << 36),  //=10^(2^1)=100.000000000000000000000000000
  1488:     new EFP (P,     13, 0x9c40000000000000L, 0x0000000L << 36),  //=10^(2^2)=10000.0000000000000000000000000
  1489:     new EFP (P,     26, 0xbebc200000000000L, 0x0000000L << 36),  //=10^(2^3)=100000000.000000000000000000000
  1490:     new EFP (P,     53, 0x8e1bc9bf04000000L, 0x0000000L << 36),  //=10^(2^4)=10000000000000000.0000000000000
  1491:     new EFP (P,    106, 0x9dc5ada82b70b59dL, 0xf020000L << 36),  //=10^(2^5)=1.00000000000000000000000000000e+32
  1492:     new EFP (P,    212, 0xc2781f49ffcfa6d5L, 0x3cbf6b7L << 36),  //<10^(2^6)=1.00000000000000000000000000000e+64
  1493:     new EFP (P,    425, 0x93ba47c980e98cdfL, 0xc66f337L << 36),  //>10^(2^7)=1.00000000000000000000000000000e+128
  1494:     new EFP (P,    850, 0xaa7eebfb9df9de8dL, 0xddbb902L << 36),  //>10^(2^8)=1.00000000000000000000000000000e+256
  1495:     new EFP (P,   1700, 0xe319a0aea60e91c6L, 0xcc655c5L << 36),  //<10^(2^9)=1.00000000000000000000000000000e+512
  1496:     new EFP (P,   3401, 0xc976758681750c17L, 0x650d3d3L << 36),  //>10^(2^10)=1.00000000000000000000000000000e+1024
  1497:     new EFP (P,   6803, 0x9e8b3b5dc53d5de4L, 0xa74d28dL << 36),  //>10^(2^11)=1.00000000000000000000000000000e+2048
  1498:     new EFP (P,  13606, 0xc46052028a20979aL, 0xc94c154L << 36),  //>10^(2^12)=1.00000000000000000000000000000e+4096
  1499:     new EFP (P,  27213, 0x96a3a1d17faf211aL, 0x0c7c289L << 36),  //<10^(2^13)=1.00000000000000000000000000000e+8192
  1500:   };  //EXP10_P_I
  1501:   public final EFP[] EXP10_M_I = {
  1502:     //  echo read("efp.gp");for(n=0,13,efpmem([Str("10^(-2^",n,")")])) | gp -q
  1503:     new EFP (P,     -4, 0xccccccccccccccccL, 0xccccccdL << 36),  //>10^(-2^0)=0.100000000000000000000000000000
  1504:     new EFP (P,     -7, 0xa3d70a3d70a3d70aL, 0x3d70a3dL << 36),  //<10^(-2^1)=0.0100000000000000000000000000000
  1505:     new EFP (P,    -14, 0xd1b71758e219652bL, 0xd3c3611L << 36),  //<10^(-2^2)=1.00000000000000000000000000000e-4
  1506:     new EFP (P,    -27, 0xabcc77118461cefcL, 0xfdc20d3L << 36),  //>10^(-2^3)=1.00000000000000000000000000000e-8
  1507:     new EFP (P,    -54, 0xe69594bec44de15bL, 0x4c2ebe7L << 36),  //>10^(-2^4)=1.00000000000000000000000000000e-16
  1508:     new EFP (P,   -107, 0xcfb11ead453994baL, 0x67de18fL << 36),  //>10^(-2^5)=1.00000000000000000000000000000e-32
  1509:     new EFP (P,   -213, 0xa87fea27a539e9a5L, 0x3f2398dL << 36),  //<10^(-2^6)=1.00000000000000000000000000000e-64
  1510:     new EFP (P,   -426, 0xddd0467c64bce4a0L, 0xac7cb3fL << 36),  //<10^(-2^7)=1.00000000000000000000000000000e-128
  1511:     new EFP (P,   -851, 0xc0314325637a1939L, 0xfa91115L << 36),  //<10^(-2^8)=1.00000000000000000000000000000e-256
  1512:     new EFP (P,  -1701, 0x9049ee32db23d21cL, 0x7132d33L << 36),  //<10^(-2^9)=1.00000000000000000000000000000e-512
  1513:     new EFP (P,  -3402, 0xa2a682a5da57c0bdL, 0x87a6016L << 36),  //>10^(-2^10)=1.00000000000000000000000000000e-1024
  1514:     new EFP (P,  -6804, 0xceae534f34362de4L, 0x492512dL << 36),  //<10^(-2^11)=1.00000000000000000000000000000e-2048
  1515:     new EFP (P, -13607, 0xa6dd04c8d2ce9fdeL, 0x2de3812L << 36),  //<10^(-2^12)=1.00000000000000000000000000000e-4096
  1516:     new EFP (P, -27214, 0xd986c20b686da869L, 0x5d1d4feL << 36),  //>10^(-2^13)=1.00000000000000000000000000000e-8192
  1517:   };  //EXP10_M_I
  1518:   //  echo read("efp.gp");eval("exp10(x)=10^x");efpchebyshev("EXP10_C",exp10,-1/64,1/64,11) | gp -q
  1519:   public final EFP     EXP10_C0 = new EFP (P,      0, 0x8000000000000000L, 0x0000000L << 36);  //=1.00000000000000000000000000000
  1520:   public final EFP     EXP10_C1 = new EFP (P,      1, 0x935d8dddaaa8ac16L, 0xea56d63L << 36);  //=2.30258509299404568401799145491
  1521:   public final EFP     EXP10_C2 = new EFP (P,      1, 0xa9a92639e753443aL, 0x80aa0a5L << 36);  //=2.65094905523919900528083460848
  1522:   public final EFP     EXP10_C3 = new EFP (P,      1, 0x82382c8ef1652304L, 0x6a4fce8L << 36);  //=2.03467859229347619683099182492
  1523:   public final EFP     EXP10_C4 = new EFP (P,      0, 0x95ebb04fecc62263L, 0x3516d57L << 36);  //=1.17125514891226696311068508120
  1524:   public final EFP     EXP10_C5 = new EFP (P,     -1, 0x8a14ffe8ea6bb111L, 0x0f9d433L << 36);  //=0.539382929195581410178946055296
  1525:   public final EFP     EXP10_C6 = new EFP (P,     -3, 0xd3f6b8423e47031dL, 0xb2e8d4cL << 36);  //=0.206995848696869277613713506791
  1526:   public final EFP     EXP10_C7 = new EFP (P,     -4, 0x8b726fe199d4dd8aL, 0x0319896L << 36);  //=0.0680893650744373537029952682197
  1527:   public final EFP     EXP10_C8 = new EFP (P,     -6, 0xa08b582ea51b0457L, 0xa2bc993L << 36);  //=0.0195976946171499984930236007292
  1528:   public final EFP     EXP10_C9 = new EFP (P,     -8, 0xa44be22db201cf47L, 0x94dcaeaL << 36);  //=0.00501392883178657960091531266074
  1529:   public final EFP    EXP10_C10 = new EFP (P,    -10, 0x9753b9561c0a683fL, 0x0135acdL << 36);  //=0.00115453374296954907615286737273
  1530:   public final EFP    EXP10_C11 = new EFP (P,    -13, 0xfd69aac60b9f8924L, 0x6d6c8b2L << 36);  //=2.41673242615286373608040289945e-4
  1531:   //  95.99bit
  1532:   public final EFP[] EXP10_P_T = {
  1533:     //  echo read("efp.gp");for(n=0,63,efpmem([Str("10^(",n,"/64)")])) | gp -q
  1534:     new EFP (P,      0, 0x8000000000000000L, 0x0000000L << 36),  //=10^(0/64)=1.00000000000000000000000000000
  1535:     new EFP (P,      0, 0x84b06346cc5e15f9L, 0x701148dL << 36),  //>10^(1/64)=1.03663292843769799729165172493
  1536:     new EFP (P,      0, 0x898cbfd35533bb59L, 0x3c49e31L << 36),  //<10^(2/64)=1.07460782832131749721594153196
  1537:     new EFP (P,      0, 0x8e96b208a3664881L, 0x0ec125aL << 36),  //<10^(3/64)=1.11397385999480237628676508624
  1538:     new EFP (P,      0, 0x93cfe56520272d66L, 0x5aa4cf9L << 36),  //<10^(4/64)=1.15478198468945817966648288730
  1539:     new EFP (P,      0, 0x993a151041524281L, 0xa5bb585L << 36),  //>10^(5/64)=1.19708503049572996552827088892
  1540:     new EFP (P,      0, 0x9ed70c6d6669efa1L, 0xfe3df3cL << 36),  //<10^(6/64)=1.24093776075171956609870735535
  1541:     new EFP (P,      0, 0xa4a8a7b416dcf6d2L, 0xcb3598fL << 36),  //>10^(7/64)=1.28639694493697450748440704963
  1542:     new EFP (P,      0, 0xaab0d48dd40a21eeL, 0xe3993e6L << 36),  //<10^(8/64)=1.33352143216332402567593171530
  1543:     new EFP (P,      0, 0xb0f192b9b34f3a68L, 0x955eb28L << 36),  //>10^(9/64)=1.38237222735789961915257040197
  1544:     new EFP (P,      0, 0xb76cf4b5f65b3109L, 0xa96afc1L << 36),  //>10^(10/64)=1.43301257023696274155836644455
  1545:     new EFP (P,      0, 0xbe25206fd9f7d185L, 0xaebfd1dL << 36),  //>10^(11/64)=1.48550801717277507269503768560
  1546:     new EFP (P,      0, 0xc51c4ff9d58e742dL, 0x8b26b72L << 36),  //>10^(12/64)=1.53992652605949198957048599495
  1547:     new EFP (P,      0, 0xcc54d24887cd8593L, 0x587bd74L << 36),  //<10^(13/64)=1.59633854428794223977352853358
  1548:     new EFP (P,      0, 0xd3d10bf68f0b258cL, 0xf7a8720L << 36),  //>10^(14/64)=1.65481709994318142294561394026
  1549:     new EFP (P,      0, 0xdb93780f8e4c4878L, 0xa97bdbaL << 36),  //<10^(15/64)=1.71543789634287892263242774792
  1550:     new EFP (P,      0, 0xe39ea8e2a2387187L, 0xf37c989L << 36),  //>10^(16/64)=1.77827941003892280122542119519
  1551:     new EFP (P,      0, 0xebf548dc8bb914d9L, 0x7f50e38L << 36),  //<10^(17/64)=1.84342299240911047379928682108
  1552:     new EFP (P,      0, 0xf49a1b69d891c56dL, 0x960a16fL << 36),  //>10^(18/64)=1.91095297497044051626887333608
  1553:     new EFP (P,      0, 0xfd8ffde154e45e46L, 0x6d275e3L << 36),  //<10^(19/64)=1.98095677855033875589271948122
  1554:     new EFP (P,      1, 0x836cf43b89a99c01L, 0x4fdf0c0L << 36),  //>10^(20/64)=2.05352502645714607460575234830
  1555:     new EFP (P,      1, 0x883d779c2e260ef2L, 0x8fcb8a1L << 36),  //>10^(21/64)=2.12875166179637259331084646179
  1556:     new EFP (P,      1, 0x8d3b21886bfd0401L, 0xb2e86d9L << 36),  //<10^(22/64)=2.20673406908458980028232378190
  1557:     new EFP (P,      1, 0x9267996ca4b54f44L, 0xfac62acL << 36),  //>10^(23/64)=2.28757320031839568693918290553
  1558:     new EFP (P,      1, 0x97c496381a501b96L, 0x8f187f6L << 36),  //>10^(24/64)=2.37137370566165526165175275748
  1559:     new EFP (P,      1, 0x9d53deee66493377L, 0x48d07c3L << 36),  //>10^(25/64)=2.45824406892019739301085187675
  1560:     new EFP (P,      1, 0xa3174b3e44c3bf1cL, 0x5882b85L << 36),  //>10^(26/64)=2.54829674797934652767525759152
  1561:     new EFP (P,      1, 0xa910c41de5dcba7fL, 0x26e2683L << 36),  //<10^(27/64)=2.64164832038609245760602422495
  1562:     new EFP (P,      1, 0xaf42446cf8f10ddbL, 0xdeffc99L << 36),  //<10^(28/64)=2.73841963426436129418869698739
  1563:     new EFP (P,      1, 0xb5add99ca78b05aeL, 0xb531acaL << 36),  //>10^(29/64)=2.83873596475875476410634665940
  1564:     new EFP (P,      1, 0xbc55a45db7a285f3L, 0x2c86e23L << 36),  //<10^(30/64)=2.94272717620928181136420323011
  1565:     new EFP (P,      1, 0xc33bd9550ee56612L, 0x36b705cL << 36),  //<10^(31/64)=3.05052789026702553649413782738
  1566:     new EFP (P,      1, 0xca62c1d6d2da9490L, 0x2515e42L << 36),  //>10^(32/64)=3.16227766016837933199889354443
  1567:     new EFP (P,      1, 0xd1ccbca863e3a684L, 0x9dcd927L << 36),  //<10^(33/64)=3.27812115139345863868052715836
  1568:     new EFP (P,      1, 0xd97c3ec973660921L, 0xc624e27L << 36),  //>10^(34/64)=3.39820832894255937150660921812
  1569:     new EFP (P,      1, 0xe173d44477bfebc8L, 0xc9e83d6L << 36),  //<10^(35/64)=3.52269465147310144505670477089
  1570:     new EFP (P,      1, 0xe9b62106c31def2cL, 0x8c4b218L << 36),  //<10^(36/64)=3.65174127254837705824995256605
  1571:     new EFP (P,      1, 0xf245e1c084ce80edL, 0x038ee92L << 36),  //>10^(37/64)=3.78551524925862997316336724952
  1572:     new EFP (P,      1, 0xfb25ecccff4f619aL, 0x3e59575L << 36),  //<10^(38/64)=3.92418975848453586166641294060
  1573:     new EFP (P,      2, 0x822c9991a00501dfL, 0x459ef69L << 36),  //>10^(39/64)=4.06794432108304725128134842000
  1574:     new EFP (P,      2, 0x86f160a7d4429212L, 0x10e2195L << 36),  //>10^(40/64)=4.21696503428582248569013359509
  1575:     new EFP (P,      2, 0x8be2e03b4ddf0e98L, 0x12bb325L << 36),  //>10^(41/64)=4.37144481261108970238502724308
  1576:     new EFP (P,      2, 0x9102bbb052b20069L, 0x01f46c1L << 36),  //>10^(42/64)=4.53158363760081788320489309709
  1577:     new EFP (P,      2, 0x9652a5c839e93b97L, 0xa26a9f7L << 36),  //<10^(43/64)=4.69758881670649182019894641275
  1578:     new EFP (P,      2, 0x9bd461318075e327L, 0xba8d5a6L << 36),  //<10^(44/64)=4.86967525165863114935297485034
  1579:     new EFP (P,      2, 0xa189c11d24a8aa65L, 0x85c7857L << 36),  //<10^(45/64)=5.04806571666747076993748259343
  1580:     new EFP (P,      2, 0xa774a9d97a7cc699L, 0x267ff04L << 36),  //<10^(46/64)=5.23299114681494688097670550264
  1581:     new EFP (P,      2, 0xad971172abe13529L, 0x4e7987eL << 36),  //<10^(47/64)=5.42469093701132600419719579894
  1582:     new EFP (P,      2, 0xb3f300591a312caeL, 0x82ddc80L << 36),  //>10^(48/64)=5.62341325190349080394951039776
  1583:     new EFP (P,      2, 0xba8a920dd7ff6294L, 0x8fdbe3cL << 36),  //>10^(49/64)=5.82941534713607396382074746488
  1584:     new EFP (P,      2, 0xc15ff5d5745ce801L, 0xf9cbdb1L << 36),  //>10^(50/64)=6.04296390238132819036274581338
  1585:     new EFP (P,      2, 0xc8756f7152dc6b33L, 0xd916f2aL << 36),  //<10^(51/64)=6.26433536656885561228272629955
  1586:     new EFP (P,      2, 0xcfcd57dfcdbe57f5L, 0x06243dfL << 36),  //>10^(52/64)=6.49381631576211315128032840698
  1587:     new EFP (P,      2, 0xd76a1e2361f25a79L, 0x376f47eL << 36),  //<10^(53/64)=6.73170382414498230366796296997
  1588:     new EFP (P,      2, 0xdf4e481126efea96L, 0x226ac46L << 36),  //<10^(54/64)=6.97830584859866338414831761727
  1589:     new EFP (P,      2, 0xe77c7326d6d287faL, 0x80d6746L << 36),  //>10^(55/64)=7.23394162736674761521631443578
  1590:     new EFP (P,      2, 0xeff75568ada7ffc1L, 0x9a2a3e9L << 36),  //<10^(56/64)=7.49894209332455827302184275615
  1591:     new EFP (P,      2, 0xf8c1be4769784541L, 0xfbc290fL << 36),  //>10^(57/64)=7.77365030238775803292348188791
  1592:     new EFP (P,      3, 0x80ef4bc75b9ffbd5L, 0x0910ec4L << 36),  //>10^(58/64)=8.05842187761481817002575395741
  1593:     new EFP (P,      3, 0x85a8732e2df0c035L, 0xb3cb958L << 36),  //<10^(59/64)=8.35362546957826173294463685160
  1594:     new EFP (P,      3, 0x8a8de610357adc41L, 0x4850544L << 36),  //>10^(60/64)=8.65964323360065352353169183420
  1595:     new EFP (P,      3, 0x8fa143d3703294f4L, 0x841b5f8L << 36),  //>10^(61/64)=8.97687132447314194541938363834
  1596:     new EFP (P,      3, 0x94e43b157a67a6c0L, 0x97fe98cL << 36),  //>10^(62/64)=9.30572040929698979290646316499
  1597:     new EFP (P,      3, 0x9a588a3a43ff4e3cL, 0x381b0ceL << 36),  //<10^(63/64)=9.64661619911199213711208256038
  1598:   };  //EXP10_P_T
  1599:   public final EFP[] EXP10_M_T = {
  1600:     //  echo read("efp.gp");for(n=0,63,efpmem([Str("10^(-",n,"/64)")])) | gp -q
  1601:     new EFP (P,      0, 0x8000000000000000L, 0x0000000L << 36),  //=10^(-0/64)=1.00000000000000000000000000000
  1602:     new EFP (P,     -1, 0xf6f4105d39987d2dL, 0x2691ae4L << 36),  //>10^(-1/64)=0.964661619911199213711208256038
  1603:     new EFP (P,     -1, 0xee39f8225d72a467L, 0x59975acL << 36),  //<10^(-2/64)=0.930572040929698979290646316499
  1604:     new EFP (P,     -1, 0xe5ced2ebe6b754baL, 0x6cf898cL << 36),  //<10^(-3/64)=0.897687132447314194541938363834
  1605:     new EFP (P,     -1, 0xddafd68055916068L, 0x73b3b9fL << 36),  //<10^(-4/64)=0.865964323360065352353169183420
  1606:     new EFP (P,     -1, 0xd5da51e37cb466bcL, 0x52df55aL << 36),  //>10^(-5/64)=0.835362546957826173294463685160
  1607:     new EFP (P,     -1, 0xce4bac722c332c88L, 0x0e8179fL << 36),  //<10^(-6/64)=0.805842187761481817002575395741
  1608:     new EFP (P,     -1, 0xc7016505edf9d101L, 0x963540cL << 36),  //>10^(-7/64)=0.777365030238775803292348188791
  1609:     new EFP (P,     -1, 0xbff911208aeccc9aL, 0xe1bb654L << 36),  //<10^(-8/64)=0.749894209332455827302184275615
  1610:     new EFP (P,     -1, 0xb9305c1f12420662L, 0x00ab904L << 36),  //<10^(-9/64)=0.723394162736674761521631443578
  1611:     new EFP (P,     -1, 0xb2a506741f265544L, 0xe85569fL << 36),  //>10^(-10/64)=0.697830584859866338414831761727
  1612:     new EFP (P,     -1, 0xac54e4e91b284860L, 0xf925d32L << 36),  //>10^(-11/64)=0.673170382414498230366796296997
  1613:     new EFP (P,     -1, 0xa63ddfe63e31dff7L, 0x381cfe5L << 36),  //<10^(-12/64)=0.649381631576211315128032840698
  1614:     new EFP (P,     -1, 0xa05df2c10f16bc29L, 0x7a78c22L << 36),  //>10^(-13/64)=0.626433536656885561228272629955
  1615:     new EFP (P,     -1, 0x9ab32b1129e3ecceL, 0x616fe27L << 36),  //>10^(-14/64)=0.604296390238132819036274581338
  1616:     new EFP (P,     -1, 0x953ba80b1332b543L, 0xa649830L << 36),  //>10^(-15/64)=0.582941534713607396382074746488
  1617:     new EFP (P,     -1, 0x8ff599e0e1c0f08bL, 0x9be4a00L << 36),  //>10^(-16/64)=0.562341325190349080394951039776
  1618:     new EFP (P,     -1, 0x8adf41288980f754L, 0x3ec79ffL << 36),  //>10^(-17/64)=0.542469093701132600419719579894
  1619:     new EFP (P,     -1, 0x85f6ee4795309ee0L, 0xeb998d0L << 36),  //<10^(-18/64)=0.523299114681494688097670550264
  1620:     new EFP (P,     -1, 0x813b00e41d53bb84L, 0x6b06046L << 36),  //>10^(-19/64)=0.504806571666747076993748259343
  1621:     new EFP (P,     -2, 0xf953ceb59a56383fL, 0x90e22a4L << 36),  //>10^(-20/64)=0.486967525165863114935297485034
  1622:     new EFP (P,     -2, 0xf0843c738fdb928cL, 0x3710ff2L << 36),  //<10^(-21/64)=0.469758881670649182019894641275
  1623:     new EFP (P,     -2, 0xe8045f80845000a8L, 0x0320aceL << 36),  //>10^(-22/64)=0.453158363760081788320489309709
  1624:     new EFP (P,     -2, 0xdfd166c54964e426L, 0x845eb6eL << 36),  //<10^(-23/64)=0.437144481261108970238502724308
  1625:     new EFP (P,     -2, 0xd7e89aa6206a8350L, 0x1b035bbL << 36),  //<10^(-24/64)=0.421696503428582248569013359509
  1626:     new EFP (P,     -2, 0xd0475c1c333b3632L, 0x08fe574L << 36),  //<10^(-25/64)=0.406794432108304725128134842000
  1627:     new EFP (P,     -2, 0xc8eb23d732a5e7aeL, 0x9847791L << 36),  //>10^(-26/64)=0.392418975848453586166641294060
  1628:     new EFP (P,     -2, 0xc1d18166d0a533f0L, 0xcfa5875L << 36),  //>10^(-27/64)=0.378551524925862997316336724952
  1629:     new EFP (P,     -2, 0xbaf81a6bcf4b25bdL, 0x3d08e7aL << 36),  //>10^(-28/64)=0.365174127254837705824995256605
  1630:     new EFP (P,     -2, 0xb45ca9d05fccbca0L, 0xa186978L << 36),  //<10^(-29/64)=0.352269465147310144505670477089
  1631:     new EFP (P,     -2, 0xadfcff078f84d41bL, 0x04ea4ecL << 36),  //>10^(-30/64)=0.339820832894255937150660921812
  1632:     new EFP (P,     -2, 0xa7d6fd53831c8536L, 0xe4a4753L << 36),  //>10^(-31/64)=0.327812115139345863868052715836
  1633:     new EFP (P,     -2, 0xa1e89b12424876d9L, 0xb744b68L << 36),  //>10^(-32/64)=0.316227766016837933199889354443
  1634:     new EFP (P,     -2, 0x9c2fe110d8b784dbL, 0x5ef8d17L << 36),  //>10^(-33/64)=0.305052789026702553649413782738
  1635:     new EFP (P,     -2, 0x96aae9e492e86b28L, 0xf06be83L << 36),  //>10^(-34/64)=0.294272717620928181136420323011
  1636:     new EFP (P,     -2, 0x9157e14a1fa26af2L, 0x2a8e23bL << 36),  //>10^(-35/64)=0.283873596475875476410634665940
  1637:     new EFP (P,     -2, 0x8c35038a60c0d7e3L, 0x18cca14L << 36),  //<10^(-36/64)=0.273841963426436129418869698739
  1638:     new EFP (P,     -2, 0x87409ce4b7e3c865L, 0xb8b5203L << 36),  //>10^(-37/64)=0.264164832038609245760602422495
  1639:     new EFP (P,     -2, 0x827908fe9d6965b0L, 0x46cef9dL << 36),  //<10^(-38/64)=0.254829674797934652767525759152
  1640:     new EFP (P,     -3, 0xfbb964b0a3a85258L, 0x7480c6bL << 36),  //>10^(-39/64)=0.245824406892019739301085187675
  1641:     new EFP (P,     -3, 0xf2d4238cf6e6928aL, 0x7e8d989L << 36),  //<10^(-40/64)=0.237137370566165526165175275748
  1642:     new EFP (P,     -3, 0xea3f5be107887ed4L, 0xc470446L << 36),  //>10^(-41/64)=0.228757320031839568693918290553
  1643:     new EFP (P,     -3, 0xe1f835a7132e6ccfL, 0x84a715cL << 36),  //>10^(-42/64)=0.220673406908458980028232378190
  1644:     new EFP (P,     -3, 0xd9fbf2937d09b184L, 0x1945a9bL << 36),  //<10^(-43/64)=0.212875166179637259331084646179
  1645:     new EFP (P,     -3, 0xd247ed2c0f75c668L, 0x7fcb466L << 36),  //>10^(-44/64)=0.205352502645714607460575234830
  1646:     new EFP (P,     -3, 0xcad997e7771d1838L, 0x5752b1cL << 36),  //<10^(-45/64)=0.198095677855033875589271948122
  1647:     new EFP (P,     -3, 0xc3ae7c54ad416abeL, 0x11a1abfL << 36),  //>10^(-46/64)=0.191095297497044051626887333608
  1648:     new EFP (P,     -3, 0xbcc43a4a0960dd7aL, 0xcc40b60L << 36),  //<10^(-47/64)=0.184342299240911047379928682108
  1649:     new EFP (P,     -3, 0xb618871bb4f9f46cL, 0xc2ca13aL << 36),  //<10^(-48/64)=0.177827941003892280122542119519
  1650:     new EFP (P,     -3, 0xafa92cd93ea36d2dL, 0x5463162L << 36),  //>10^(-49/64)=0.171543789634287892263242774792
  1651:     new EFP (P,     -3, 0xa97409920c08ead7L, 0x2c86c19L << 36),  //<10^(-50/64)=0.165481709994318142294561394026
  1652:     new EFP (P,     -3, 0xa3770ea06ca46adcL, 0x46c9790L << 36),  //<10^(-51/64)=0.159633854428794223977352853358
  1653:     new EFP (P,     -3, 0x9db03ffb113ec357L, 0xa2855f5L << 36),  //>10^(-52/64)=0.153992652605949198957048599495
  1654:     new EFP (P,     -3, 0x981db38cae5fdad1L, 0x589974aL << 36),  //<10^(-53/64)=0.148550801717277507269503768560
  1655:     new EFP (P,     -3, 0x92bd909191e28da1L, 0x5455967L << 36),  //<10^(-54/64)=0.143301257023696274155836644455
  1656:     new EFP (P,     -3, 0x8d8e0efaf5d8fb86L, 0xdde55baL << 36),  //>10^(-55/64)=0.138237222735789961915257040197
  1657:     new EFP (P,     -3, 0x888d76d7dcd4e7f2L, 0x4fadcb8L << 36),  //<10^(-56/64)=0.133352143216332402567593171530
  1658:     new EFP (P,     -3, 0x83ba1fc3457d9242L, 0x3c2ae0cL << 36),  //>10^(-57/64)=0.128639694493697450748440704963
  1659:     new EFP (P,     -4, 0xfe24e0af0a431903L, 0x30631faL << 36),  //<10^(-58/64)=0.124093776075171956609870735535
  1660:     new EFP (P,     -4, 0xf529bb4d35506a69L, 0x092bc07L << 36),  //<10^(-59/64)=0.119708503049572996552827088892
  1661:     new EFP (P,     -4, 0xec7fd56e99d848a3L, 0xc43ae5bL << 36),  //<10^(-60/64)=0.115478198468945817966648288730
  1662:     new EFP (P,     -4, 0xe424500dd23d40ceL, 0x7e01d5dL << 36),  //<10^(-61/64)=0.111397385999480237628676508624
  1663:     new EFP (P,     -4, 0xdc14661eeeb92bc1L, 0xfa0fd1cL << 36),  //>10^(-62/64)=0.107460782832131749721594153196
  1664:     new EFP (P,     -4, 0xd44d6ba47a302328L, 0xb34edaeL << 36),  //<10^(-63/64)=0.103663292843769799729165172493
  1665:   };  //EXP10_M_T
  1666: 
  1667:   //------------------------------------------------------------------------
  1668:   //exp2
  1669:   //  echo read("efp.gp");eval("exp2(x)=2^x");efpchebyshev("EXP2P_C",exp2,0,1/64,8) | gp -q
  1670:   public final EFP     EXP2P_C0 = new EFP (P,      0, 0x8000000000000000L, 0x0000000L << 36);  //=1.00000000000000000000000000000
  1671:   public final EFP     EXP2P_C1 = new EFP (P,     -1, 0xb17217f7d1cf79abL, 0xc9e3289L << 36);  //=0.693147180559945309417231672224
  1672:   public final EFP     EXP2P_C2 = new EFP (P,     -3, 0xf5fdeffc162c7543L, 0x87306ceL << 36);  //=0.240226506959100712334317834550
  1673:   public final EFP     EXP2P_C3 = new EFP (P,     -5, 0xe35846b82505fbc4L, 0xf77c6dfL << 36);  //=0.0555041086648215794495051454975
  1674:   public final EFP     EXP2P_C4 = new EFP (P,     -7, 0x9d955b7dd276b5acL, 0xbf41024L << 36);  //=0.00961812910762864290798786714666
  1675:   public final EFP     EXP2P_C5 = new EFP (P,    -10, 0xaec3ff3c41fa05ceL, 0xd0dbae7L << 36);  //=0.00133335581461220558296277742225
  1676:   public final EFP     EXP2P_C6 = new EFP (P,    -13, 0xa18489b6bbee153cL, 0x79516f1L << 36);  //=1.54035307260420586747761266932e-4
  1677:   public final EFP     EXP2P_C7 = new EFP (P,    -17, 0xffe516c43da39259L, 0x7cbaceaL << 36);  //=1.52525233411920778640460590036e-5
  1678:   public final EFP     EXP2P_C8 = new EFP (P,    -20, 0xb256aa5495805ceeL, 0xb4df34eL << 36);  //=1.32872563999697042645099045935e-6
  1679:   //  93.22bit
  1680:   //  echo read("efp.gp");eval("exp2(x)=2^x");efpchebyshev("EXP2M_C",exp2,-1/64,0,8) | gp -q
  1681:   public final EFP     EXP2M_C0 = new EFP (P,      0, 0x8000000000000000L, 0x0000000L << 36);  //=1.00000000000000000000000000000
  1682:   public final EFP     EXP2M_C1 = new EFP (P,     -1, 0xb17217f7d1cf79abL, 0xc9e32a0L << 36);  //=0.693147180559945309417231676869
  1683:   public final EFP     EXP2M_C2 = new EFP (P,     -3, 0xf5fdeffc162c7543L, 0x6a5f7f6L << 36);  //=0.240226506959100712332792321650
  1684:   public final EFP     EXP2M_C3 = new EFP (P,     -5, 0xe35846b82505fbc6L, 0x6a8d50cL << 36);  //=0.0555041086648215794544161625987
  1685:   public final EFP     EXP2M_C4 = new EFP (P,     -7, 0x9d955b7dd270c42fL, 0x60d628cL << 36);  //=0.00961812910762831298749547774027
  1686:   public final EFP     EXP2M_C5 = new EFP (P,    -10, 0xaec3ff3c422238b3L, 0x26278f5L << 36);  //=0.00133335581461248451814736607925
  1687:   public final EFP     EXP2M_C6 = new EFP (P,    -13, 0xa184894230721e7bL, 0x5e05decL << 36);  //=1.54035300635612277279514659537e-4
  1688:   public final EFP     EXP2M_C7 = new EFP (P,    -17, 0xffe518860467684dL, 0x1c0262cL << 36);  //=1.52525249391189379086239626896e-5
  1689:   public final EFP     EXP2M_C8 = new EFP (P,    -20, 0xb06adfb7eea07e61L, 0xba36904L << 36);  //=1.31441262493409658027106967485e-6
  1690:   //  93.24bit
  1691:   public final EFP[] EXP2P_T = {
  1692:     //  echo read("efp.gp");for(n=0,63,efpmem([Str("2^(",n,"/64)")])) | gp -q
  1693:     new EFP (P,      0, 0x8000000000000000L, 0x0000000L << 36),  //=2^(0/64)=1.00000000000000000000000000000
  1694:     new EFP (P,      0, 0x8164d1f3bc030773L, 0x7be5652L << 36),  //<2^(1/64)=1.01088928605170046002040979056
  1695:     new EFP (P,      0, 0x82cd8698ac2ba1d7L, 0x3e2a476L << 36),  //>2^(2/64)=1.02189714865411667823448013478
  1696:     new EFP (P,      0, 0x843a28c3acde4046L, 0x1af92edL << 36),  //>2^(3/64)=1.03302487902122842250010828397
  1697:     new EFP (P,      0, 0x85aac367cc487b14L, 0xc5c95b9L << 36),  //>2^(4/64)=1.04427378242741384032196647874
  1698:     new EFP (P,      0, 0x871f61969e8d1010L, 0x3a1727cL << 36),  //<2^(5/64)=1.05564517836055715880834132515
  1699:     new EFP (P,      0, 0x88980e8092da8527L, 0x5df8d77L << 36),  //>2^(6/64)=1.06714040067682361816952112099
  1700:     new EFP (P,      0, 0x8a14d575496efd9aL, 0x080ca1eL << 36),  //>2^(7/64)=1.07876079775711979374068003744
  1701:     new EFP (P,      0, 0x8b95c1e3ea8bd6e6L, 0xfbe4628L << 36),  //<2^(8/64)=1.09050773266525765920701065576
  1702:     new EFP (P,      0, 0x8d1adf5b7e5ba9e5L, 0xb4c7b49L << 36),  //<2^(9/64)=1.10238258330784094355641420943
  1703:     new EFP (P,      0, 0x8ea4398b45cd53c0L, 0x2dc0145L << 36),  //>2^(10/64)=1.11438674259589253630881295692
  1704:     new EFP (P,      0, 0x9031dc431466b1dcL, 0x775814bL << 36),  //>2^(11/64)=1.12652161860824189979479864379
  1705:     new EFP (P,      0, 0x91c3d373ab11c336L, 0x0fd6d8eL << 36),  //<2^(12/64)=1.13878863475669165370383028384
  1706:     new EFP (P,      0, 0x935a2b2f13e6e92bL, 0xd339941L << 36),  //>2^(13/64)=1.15118922995298270581775963520
  1707:     new EFP (P,      0, 0x94f4efa8fef70961L, 0x2e8afadL << 36),  //<2^(14/64)=1.16372485877757751381357359909
  1708:     new EFP (P,      0, 0x96942d3720185a00L, 0x48ea9b7L << 36),  //>2^(15/64)=1.17639699165028127628464572848
  1709:     new EFP (P,      0, 0x9837f0518db8a96fL, 0x46ad232L << 36),  //>2^(16/64)=1.18920711500272106671749997056
  1710:     new EFP (P,      0, 0x99e0459320b7fa64L, 0xe43086dL << 36),  //>2^(17/64)=1.20215673145270314209639695750
  1711:     new EFP (P,      0, 0x9b8d39b9d54e5538L, 0xa2a817aL << 36),  //<2^(18/64)=1.21524735998046887811652025134
  1712:     new EFP (P,      0, 0x9d3ed9a72cffb750L, 0xde494cfL << 36),  //<2^(19/64)=1.22848053610687000569400895779
  1713:     new EFP (P,      0, 0x9ef5326091a111adL, 0xa0911f1L << 36),  //>2^(20/64)=1.24185781207348404859367746873
  1714:     new EFP (P,      0, 0xa0b0510fb9714fc2L, 0x192dc7aL << 36),  //>2^(21/64)=1.25538075702469108957939065744
  1715:     new EFP (P,      0, 0xa27043030c496818L, 0x9b7a04fL << 36),  //>2^(22/64)=1.26905095719173322255441908103
  1716:     new EFP (P,      0, 0xa43515ae09e6809eL, 0x0d1db48L << 36),  //<2^(23/64)=1.28287001607877828072666978102
  1717:     new EFP (P,      0, 0xa5fed6a9b15138eaL, 0x1cbd7f6L << 36),  //<2^(24/64)=1.29683955465100966593375411779
  1718:     new EFP (P,      0, 0xa7cd93b4e9653569L, 0x9ec5b4dL << 36),  //<2^(25/64)=1.31096121152476434192299178633
  1719:     new EFP (P,      0, 0xa9a15ab4ea7c0ef8L, 0x541e24fL << 36),  //>2^(26/64)=1.32523664315974129462953709550
  1720:     new EFP (P,      0, 0xab7a39b5a93ed337L, 0x658023bL << 36),  //<2^(27/64)=1.33966752405330300536003066972
  1721:     new EFP (P,      0, 0xad583eea42a14ac6L, 0x4980a8dL << 36),  //>2^(28/64)=1.35425554693689272829801474014
  1722:     new EFP (P,      0, 0xaf3b78ad690a4374L, 0xdf26102L << 36),  //>2^(29/64)=1.36900242297459061192960113298
  1723:     new EFP (P,      0, 0xb123f581d2ac258fL, 0x87d037fL << 36),  //>2^(30/64)=1.38390988196383195487265952727
  1724:     new EFP (P,      0, 0xb311c412a9112489L, 0x3ecf14eL << 36),  //>2^(31/64)=1.39897967253831114020952813672
  1725:     new EFP (P,      0, 0xb504f333f9de6484L, 0x597d89bL << 36),  //<2^(32/64)=1.41421356237309504880168872421
  1726:     new EFP (P,      0, 0xb6fd91e328d17791L, 0x07165f1L << 36),  //>2^(33/64)=1.42961333839197001123506577828
  1727:     new EFP (P,      0, 0xb8fbaf4762fb9ee9L, 0x1b87978L << 36),  //>2^(34/64)=1.44518080697704662003700624147
  1728:     new EFP (P,      0, 0xbaff5ab2133e45fbL, 0x74d519dL << 36),  //<2^(35/64)=1.46091779418064698865130289031
  1729:     new EFP (P,      0, 0xbd08a39f580c36beL, 0xa8811fbL << 36),  //<2^(36/64)=1.47682614593949931138690748037
  1730:     new EFP (P,      0, 0xbf1799b67a731082L, 0xe815d0bL << 36),  //>2^(37/64)=1.49290772829126484920064353149
  1731:     new EFP (P,      0, 0xc12c4cca66709456L, 0x7c457d6L << 36),  //>2^(38/64)=1.50916442759342273976601955103
  1732:     new EFP (P,      0, 0xc346ccda24976407L, 0x20ec856L << 36),  //<2^(39/64)=1.52559815074453830685125368952
  1733:     new EFP (P,      0, 0xc5672a115506daddL, 0x3e2ad0dL << 36),  //>2^(40/64)=1.54221082540794082361229186209
  1734:     new EFP (P,      0, 0xc78d74c8abb9b15cL, 0xc13a2e4L << 36),  //>2^(41/64)=1.55900440023783696703372808947
  1735:     new EFP (P,      0, 0xc9b9bd866e2f27a2L, 0x80e1f93L << 36),  //>2^(42/64)=1.57598084510788648645527016018
  1736:     new EFP (P,      0, 0xcbec14fef2727c5cL, 0xf4907c9L << 36),  //>2^(43/64)=1.59314215134226689793724864312
  1737:     new EFP (P,      0, 0xce248c151f8480e3L, 0xe235839L << 36),  //>2^(44/64)=1.61049033194925430817952066736
  1738:     new EFP (P,      0, 0xd06333daef2b2594L, 0xd6d45c6L << 36),  //<2^(45/64)=1.62802742185734776684821852201
  1739:     new EFP (P,      0, 0xd2a81d91f12ae45aL, 0x12248e5L << 36),  //<2^(46/64)=1.64575547815396484451875672473
  1740:     new EFP (P,      0, 0xd4f35aabcfedfa1fL, 0x5921df0L << 36),  //>2^(47/64)=1.66367658032673643504633645698
  1741:     new EFP (P,      0, 0xd744fccad69d6af4L, 0x39a68bcL << 36),  //>2^(48/64)=1.68179283050742908606225095247
  1742:     new EFP (P,      0, 0xd99d15c278afd7b5L, 0xfe873dfL << 36),  //>2^(49/64)=1.70010635371852346950136257350
  1743:     new EFP (P,      0, 0xdbfbb797daf23755L, 0x3d840d6L << 36),  //>2^(50/64)=1.71861929812247791562934437646
  1744:     new EFP (P,      0, 0xde60f4825e0e9123L, 0xdd07a2eL << 36),  //>2^(51/64)=1.73733383527370624899420208187
  1745:     new EFP (P,      0, 0xe0ccdeec2a94e111L, 0x0658950L << 36),  //<2^(52/64)=1.75625216037329948311216061938
  1746:     new EFP (P,      0, 0xe33f8972be8a5a51L, 0x09bfe90L << 36),  //<2^(53/64)=1.77537649252652125255055920020
  1747:     new EFP (P,      0, 0xe5b906e77c8348a8L, 0x1e5e8f5L << 36),  //>2^(54/64)=1.79470907500310718642770324213
  1748:     new EFP (P,      0, 0xe8396a503c4bdc68L, 0x791790dL << 36),  //<2^(55/64)=1.81425217550039875624983460036
  1749:     new EFP (P,      0, 0xeac0c6e7dd24392eL, 0xd02d75bL << 36),  //<2^(56/64)=1.83400808640934246348708318959
  1750:     new EFP (P,      0, 0xed4f301ed9942b84L, 0x600d2dbL << 36),  //<2^(57/64)=1.85397912508338556839245307034
  1751:     new EFP (P,      0, 0xefe4b99bdcdaf5cbL, 0x46561cfL << 36),  //<2^(58/64)=1.87416763411029990132999894995
  1752:     new EFP (P,      0, 0xf281773c59ffb139L, 0xe8980aaL << 36),  //>2^(59/64)=1.89457598158696564134021865343
  1753:     new EFP (P,      0, 0xf5257d152486cc2cL, 0x7b9d0c8L << 36),  //>2^(60/64)=1.91520656139714729387261127030
  1754:     new EFP (P,      0, 0xf7d0df730ad13bb8L, 0xfe90d49L << 36),  //<2^(61/64)=1.93606179349229445059805590457
  1755:     new EFP (P,      0, 0xfa83b2db722a033aL, 0x7c25bb1L << 36),  //<2^(62/64)=1.95714412417540026901832225163
  1756:     new EFP (P,      0, 0xfd3e0c0cf486c174L, 0x853f3a6L << 36),  //>2^(63/64)=1.97845602638795096825824991813
  1757:   };  //EXP2P_T
  1758:   public final EFP[] EXP2M_T = {
  1759:     //  echo read("efp.gp");for(n=0,63,efpmem([Str("2^(-",n,"/64)")])) | gp -q
  1760:     new EFP (P,      0, 0x8000000000000000L, 0x0000000L << 36),  //=2^(-0/64)=1.00000000000000000000000000000
  1761:     new EFP (P,     -1, 0xfd3e0c0cf486c174L, 0x853f3a6L << 36),  //>2^(-1/64)=0.989228013193975484129124959066
  1762:     new EFP (P,     -1, 0xfa83b2db722a033aL, 0x7c25bb1L << 36),  //<2^(-2/64)=0.978572062087700134509161125813
  1763:     new EFP (P,     -1, 0xf7d0df730ad13bb8L, 0xfe90d49L << 36),  //<2^(-3/64)=0.968030896746147225299027952283
  1764:     new EFP (P,     -1, 0xf5257d152486cc2cL, 0x7b9d0c8L << 36),  //>2^(-4/64)=0.957603280698573646936305635148
  1765:     new EFP (P,     -1, 0xf281773c59ffb139L, 0xe8980aaL << 36),  //>2^(-5/64)=0.947287990793482820670109326713
  1766:     new EFP (P,     -1, 0xefe4b99bdcdaf5cbL, 0x46561cfL << 36),  //<2^(-6/64)=0.937083817055149950664999474977
  1767:     new EFP (P,     -1, 0xed4f301ed9942b84L, 0x600d2dbL << 36),  //<2^(-7/64)=0.926989562541692784196226535169
  1768:     new EFP (P,     -1, 0xeac0c6e7dd24392eL, 0xd02d75bL << 36),  //<2^(-8/64)=0.917004043204671231743541594794
  1769:     new EFP (P,     -1, 0xe8396a503c4bdc68L, 0x791790dL << 36),  //<2^(-9/64)=0.907126087750199378124917300181
  1770:     new EFP (P,     -1, 0xe5b906e77c8348a8L, 0x1e5e8f5L << 36),  //>2^(-10/64)=0.897354537501553593213851621064
  1771:     new EFP (P,     -1, 0xe33f8972be8a5a51L, 0x09bfe90L << 36),  //<2^(-11/64)=0.887688246263260626275279600100
  1772:     new EFP (P,     -1, 0xe0ccdeec2a94e111L, 0x0658950L << 36),  //<2^(-12/64)=0.878126080186649741556080309688
  1773:     new EFP (P,     -1, 0xde60f4825e0e9123L, 0xdd07a2eL << 36),  //>2^(-13/64)=0.868666917636853124497101040936
  1774:     new EFP (P,     -1, 0xdbfbb797daf23755L, 0x3d840d6L << 36),  //>2^(-14/64)=0.859309649061238957814672188228
  1775:     new EFP (P,     -1, 0xd99d15c278afd7b5L, 0xfe873dfL << 36),  //>2^(-15/64)=0.850053176859261734750681286749
  1776:     new EFP (P,     -1, 0xd744fccad69d6af4L, 0x39a68bcL << 36),  //>2^(-16/64)=0.840896415253714543031125476233
  1777:     new EFP (P,     -1, 0xd4f35aabcfedfa1fL, 0x5921df0L << 36),  //>2^(-17/64)=0.831838290163368217523168228488
  1778:     new EFP (P,     -1, 0xd2a81d91f12ae45aL, 0x12248e5L << 36),  //<2^(-18/64)=0.822877739076982422259378362363
  1779:     new EFP (P,     -1, 0xd06333daef2b2594L, 0xd6d45c6L << 36),  //<2^(-19/64)=0.814013710928673883424109261007
  1780:     new EFP (P,     -1, 0xce248c151f8480e3L, 0xe235839L << 36),  //>2^(-20/64)=0.805245165974627154089760333679
  1781:     new EFP (P,     -1, 0xcbec14fef2727c5cL, 0xf4907c9L << 36),  //>2^(-21/64)=0.796571075671133448968624321560
  1782:     new EFP (P,     -1, 0xc9b9bd866e2f27a2L, 0x80e1f93L << 36),  //>2^(-22/64)=0.787990422553943243227635080091
  1783:     new EFP (P,     -1, 0xc78d74c8abb9b15cL, 0xc13a2e4L << 36),  //>2^(-23/64)=0.779502200118918483516864044737
  1784:     new EFP (P,     -1, 0xc5672a115506daddL, 0x3e2ad0dL << 36),  //>2^(-24/64)=0.771105412703970411806145931045
  1785:     new EFP (P,     -1, 0xc346ccda24976407L, 0x20ec856L << 36),  //<2^(-25/64)=0.762799075372269153425626844758
  1786:     new EFP (P,     -1, 0xc12c4cca66709456L, 0x7c457d6L << 36),  //>2^(-26/64)=0.754582213796711369883009775517
  1787:     new EFP (P,     -1, 0xbf1799b67a731082L, 0xe815d0bL << 36),  //>2^(-27/64)=0.746453864145632424600321765743
  1788:     new EFP (P,     -1, 0xbd08a39f580c36beL, 0xa8811fbL << 36),  //<2^(-28/64)=0.738413072969749655693453740187
  1789:     new EFP (P,     -1, 0xbaff5ab2133e45fbL, 0x74d519dL << 36),  //<2^(-29/64)=0.730458897090323494325651445155
  1790:     new EFP (P,     -1, 0xb8fbaf4762fb9ee9L, 0x1b87978L << 36),  //>2^(-30/64)=0.722590403488523310018503120736
  1791:     new EFP (P,     -1, 0xb6fd91e328d17791L, 0x07165f1L << 36),  //>2^(-31/64)=0.714806669195985005617532889138
  1792:     new EFP (P,     -1, 0xb504f333f9de6484L, 0x597d89bL << 36),  //<2^(-32/64)=0.707106781186547524400844362105
  1793:     new EFP (P,     -1, 0xb311c412a9112489L, 0x3ecf14eL << 36),  //>2^(-33/64)=0.699489836269155570104764068358
  1794:     new EFP (P,     -1, 0xb123f581d2ac258fL, 0x87d037fL << 36),  //>2^(-34/64)=0.691954940981915977436329763633
  1795:     new EFP (P,     -1, 0xaf3b78ad690a4374L, 0xdf26102L << 36),  //>2^(-35/64)=0.684501211487295305964800566491
  1796:     new EFP (P,     -1, 0xad583eea42a14ac6L, 0x4980a8dL << 36),  //>2^(-36/64)=0.677127773468446364149007370070
  1797:     new EFP (P,     -1, 0xab7a39b5a93ed337L, 0x658023bL << 36),  //<2^(-37/64)=0.669833762026651502680015334862
  1798:     new EFP (P,     -1, 0xa9a15ab4ea7c0ef8L, 0x541e24fL << 36),  //>2^(-38/64)=0.662618321579870647314768547749
  1799:     new EFP (P,     -1, 0xa7cd93b4e9653569L, 0x9ec5b4dL << 36),  //<2^(-39/64)=0.655480605762382170961495893165
  1800:     new EFP (P,     -1, 0xa5fed6a9b15138eaL, 0x1cbd7f6L << 36),  //<2^(-40/64)=0.648419777325504832966877058896
  1801:     new EFP (P,     -1, 0xa43515ae09e6809eL, 0x0d1db48L << 36),  //<2^(-41/64)=0.641435008039389140363334890511
  1802:     new EFP (P,     -1, 0xa27043030c496818L, 0x9b7a04fL << 36),  //>2^(-42/64)=0.634525478595866611277209540516
  1803:     new EFP (P,     -1, 0xa0b0510fb9714fc2L, 0x192dc7aL << 36),  //>2^(-43/64)=0.627690378512345544789695328721
  1804:     new EFP (P,     -1, 0x9ef5326091a111adL, 0xa0911f1L << 36),  //>2^(-44/64)=0.620928906036742024296838734363
  1805:     new EFP (P,     -1, 0x9d3ed9a72cffb750L, 0xde494cfL << 36),  //<2^(-45/64)=0.614240268053435002847004478896
  1806:     new EFP (P,     -1, 0x9b8d39b9d54e5538L, 0xa2a817aL << 36),  //<2^(-46/64)=0.607623679990234439058260125669
  1807:     new EFP (P,     -1, 0x99e0459320b7fa64L, 0xe43086dL << 36),  //>2^(-47/64)=0.601078365726351571048198478749
  1808:     new EFP (P,     -1, 0x9837f0518db8a96fL, 0x46ad232L << 36),  //>2^(-48/64)=0.594603557501360533358749985280
  1809:     new EFP (P,     -1, 0x96942d3720185a00L, 0x48ea9b7L << 36),  //>2^(-49/64)=0.588198495825140638142322864242
  1810:     new EFP (P,     -1, 0x94f4efa8fef70961L, 0x2e8afadL << 36),  //<2^(-50/64)=0.581862429388788756906786799546
  1811:     new EFP (P,     -1, 0x935a2b2f13e6e92bL, 0xd339941L << 36),  //>2^(-51/64)=0.575594614976491352908879817601
  1812:     new EFP (P,     -1, 0x91c3d373ab11c336L, 0x0fd6d8eL << 36),  //<2^(-52/64)=0.569394317378345826851915141921
  1813:     new EFP (P,     -1, 0x9031dc431466b1dcL, 0x775814bL << 36),  //>2^(-53/64)=0.563260809304120949897399321894
  1814:     new EFP (P,     -1, 0x8ea4398b45cd53c0L, 0x2dc0145L << 36),  //>2^(-54/64)=0.557193371297946268154406478460
  1815:     new EFP (P,     -1, 0x8d1adf5b7e5ba9e5L, 0xb4c7b49L << 36),  //<2^(-55/64)=0.551191291653920471778207104713
  1816:     new EFP (P,     -1, 0x8b95c1e3ea8bd6e6L, 0xfbe4628L << 36),  //<2^(-56/64)=0.545253866332628829603505327880
  1817:     new EFP (P,     -1, 0x8a14d575496efd9aL, 0x080ca1eL << 36),  //>2^(-57/64)=0.539380398878559896870340018719
  1818:     new EFP (P,     -1, 0x88980e8092da8527L, 0x5df8d77L << 36),  //>2^(-58/64)=0.533570200338411809084760560496
  1819:     new EFP (P,     -1, 0x871f61969e8d1010L, 0x3a1727cL << 36),  //<2^(-59/64)=0.527822589180278579404170662576
  1820:     new EFP (P,     -1, 0x85aac367cc487b14L, 0xc5c95b9L << 36),  //>2^(-60/64)=0.522136891213706920160983239370
  1821:     new EFP (P,     -1, 0x843a28c3acde4046L, 0x1af92edL << 36),  //>2^(-61/64)=0.516512439510614211250054141985
  1822:     new EFP (P,     -1, 0x82cd8698ac2ba1d7L, 0x3e2a476L << 36),  //>2^(-62/64)=0.510948574327058339117240067392
  1823:     new EFP (P,     -1, 0x8164d1f3bc030773L, 0x7be5652L << 36),  //<2^(-63/64)=0.505444643025850230010204895281
  1824:   };  //EXP2M_T
  1825: 
  1826:   //------------------------------------------------------------------------
  1827:   //exp2m1
  1828:   //  echo read("efp.gp");eval("exp2m1(x)=2^x-1");efppoly("EXP2M1_C",exp2m1,sum(n=1,17,eval("efp(log(2)^n/factorial(n))*x^n")),-1/4,1/4) | gp -q
  1829:   public final EFP    EXP2M1_C1 = new EFP (P,     -1, 0xb17217f7d1cf79abL, 0xc9e3b3aL << 36);  //=0.693147180559945309417232121559
  1830:   public final EFP    EXP2M1_C2 = new EFP (P,     -3, 0xf5fdeffc162c7543L, 0x78b5837L << 36);  //=0.240226506959100712333551263143
  1831:   public final EFP    EXP2M1_C3 = new EFP (P,     -5, 0xe35846b82505fc59L, 0x9d3b15eL << 36);  //=0.0555041086648215799531422637737
  1832:   public final EFP    EXP2M1_C4 = new EFP (P,     -7, 0x9d955b7dd273b94eL, 0x65df05bL << 36);  //=0.00961812910762847716197907157485
  1833:   public final EFP    EXP2M1_C5 = new EFP (P,    -10, 0xaec3ff3c53398883L, 0x8bfb4d3L << 36);  //=0.00133335581464284434234122219898
  1834:   public final EFP    EXP2M1_C6 = new EFP (P,    -13, 0xa184897c363c3b7aL, 0x58544c3L << 36);  //=1.54035303933816099544370973310e-4
  1835:   public final EFP    EXP2M1_C7 = new EFP (P,    -17, 0xffe5fe2c45863435L, 0x8a8e644L << 36);  //=1.52527338040598402800254390122e-5
  1836:   public final EFP    EXP2M1_C8 = new EFP (P,    -20, 0xb160111d2e411fecL, 0x7ff3037L << 36);  //=1.32154867901443094884037582290e-6
  1837:   public final EFP    EXP2M1_C9 = new EFP (P,    -24, 0xda929e9caf3e1ed2L, 0x53872d2L << 36);  //=1.01780860092396997274900075965e-7
  1838:   public final EFP   EXP2M1_C10 = new EFP (P,    -28, 0xf267a8ac5c764fb7L, 0xed0eca9L << 36);  //=7.05491162080112332987539218087e-9
  1839:   public final EFP   EXP2M1_C11 = new EFP (P,    -32, 0xf465639a8dd92607L, 0xabccaf2L << 36);  //=4.44553827187081149759640855868e-10
  1840:   public final EFP   EXP2M1_C12 = new EFP (P,    -36, 0xe1deb287e14c2f15L, 0xab43f0cL << 36);  //=2.56784359934882051419948023929e-11
  1841:   public final EFP   EXP2M1_C13 = new EFP (P,    -40, 0xc0b0c98b3687cb14L, 0x0d61808L << 36);  //=1.36914888539041288808919539964e-12
  1842:   public final EFP   EXP2M1_C14 = new EFP (P,    -44, 0x98a4b26ac3c54b9fL, 0x8a1b12bL << 36);  //=6.77872635482254563344910431422e-14
  1843:   public final EFP   EXP2M1_C15 = new EFP (P,    -49, 0xe1b7421d82010f33L, 0xd8abf8dL << 36);  //=3.13243670708842862163494444075e-15
  1844:   public final EFP   EXP2M1_C16 = new EFP (P,    -53, 0x9c744d73cfc59c91L, 0xc7f2765L << 36);  //=1.35702479487551471931129662273e-16
  1845:   public final EFP   EXP2M1_C17 = new EFP (P,    -58, 0xcc2225a0e12d3eabL, 0x0ec4008L << 36);  //=5.53304653245824204348554609564e-18
  1846:   //  92.12bit
  1847: 
  1848:   //------------------------------------------------------------------------
  1849:   //expm1
  1850:   //  echo read("efp.gp");efppoly("EXPM1_C",expm1,sum(n=1,18,eval("efp(1/factorial(n))*x^n")),-1/4,1/4) | gp -q
  1851:   public final EFP     EXPM1_C1 = new EFP (P,      0, 0x8000000000000000L, 0x0000000L << 36);  //=1.00000000000000000000000000000
  1852:   public final EFP     EXPM1_C2 = new EFP (P,     -1, 0x8000000000000000L, 0x0000000L << 36);  //=0.500000000000000000000000000000
  1853:   public final EFP     EXPM1_C3 = new EFP (P,     -3, 0xaaaaaaaaaaaaaaaaL, 0xaaaaaabL << 36);  //=0.166666666666666666666666666683
  1854:   public final EFP     EXPM1_C4 = new EFP (P,     -5, 0xaaaaaaaaaaaaaaaaL, 0xaaaaaabL << 36);  //=0.0416666666666666666666666666709
  1855:   public final EFP     EXPM1_C5 = new EFP (P,     -7, 0x8888888888888888L, 0x8888889L << 36);  //=0.00833333333333333333333333333481
  1856:   public final EFP     EXPM1_C6 = new EFP (P,    -10, 0xb60b60b60b60b60bL, 0x60b60b6L << 36);  //=0.00138888888888888888888888888887
  1857:   public final EFP     EXPM1_C7 = new EFP (P,    -13, 0xd00d00d00d00d00dL, 0x00d00d0L << 36);  //=1.98412698412698412698412698410e-4
  1858:   public final EFP     EXPM1_C8 = new EFP (P,    -16, 0xd00d00d00d00d00dL, 0x00d00d0L << 36);  //=2.48015873015873015873015873013e-5
  1859:   public final EFP     EXPM1_C9 = new EFP (P,    -19, 0xb8ef1d2ab6399c7dL, 0x560e447L << 36);  //=2.75573192239858906525573192228e-6
  1860:   public final EFP    EXPM1_C10 = new EFP (P,    -22, 0x93f27dbbc4fae397L, 0x780b69fL << 36);  //=2.75573192239858906525573192209e-7
  1861:   public final EFP    EXPM1_C11 = new EFP (P,    -26, 0xd7322b3faa271c7fL, 0x3a3f25cL << 36);  //=2.50521083854417187750521083848e-8
  1862:   public final EFP    EXPM1_C12 = new EFP (P,    -29, 0x8f76c77fc6c4bdaaL, 0x26d4c3dL << 36);  //=2.08767569878680989792100903181e-9
  1863:   public final EFP    EXPM1_C13 = new EFP (P,    -33, 0xb092309d43684be5L, 0x1c198e9L << 36);  //=1.60590438368216145993923771696e-10
  1864:   public final EFP    EXPM1_C14 = new EFP (P,    -37, 0xc9cba54603e4e905L, 0xd6f8a2fL << 36);  //=1.14707455977297247138516979787e-11
  1865:   public final EFP    EXPM1_C15 = new EFP (P,    -41, 0xd73f9f399dc0f88eL, 0xc32b587L << 36);  //=7.64716373181981647590113198495e-13
  1866:   public final EFP    EXPM1_C16 = new EFP (P,    -45, 0xd73f9f399dc0f88eL, 0xc32b587L << 36);  //=4.77947733238738529743820749060e-14
  1867:   public final EFP    EXPM1_C17 = new EFP (P,    -49, 0xca963b81856a5359L, 0x3028cbcL << 36);  //=2.81145725434552076319894558321e-15
  1868:   public final EFP    EXPM1_C18 = new EFP (P,    -53, 0xb413c31dcbecbbddL, 0x8024435L << 36);  //=1.56192069685862264622163643497e-16
  1869:   //  92.61bit
  1870: 
  1871:   //------------------------------------------------------------------------
  1872:   //ieeerempi2
  1873:   public static final int[] TWO_PI_ARRAY = {
  1874:     //  perl ../misc/two_pi.pl
  1875:     0x00000000, 0x00000000, 0x00000000, 0x517cc1b7, 0x1391054a, 0x3f84eafa, 0x1f534ddc, 0x06db14ac, 0x64f10e41, 0x03fca2c7,
  1876:     0x2bdebbc5, 0x30db9237, 0x0e909374, 0x5c00c925, 0x6ea09d19, 0x10e7f0ef, 0x2c72c4a6, 0x4e7dd104, 0x35f52ebb, 0x224274ce,
  1877:     0x1c09ad17, 0x6fc82732, 0x1d639835, 0x19cfa4e4, 0x117e2ef7, 0x7250763f, 0x7897ffde, 0x02cc07f7, 0x4bc462d6, 0x414da3ed,
  1878:     0x5367ecf2, 0x3e584dba, 0x3d18fd9a, 0x3cbfd45a, 0x7527bac7, 0x75f2f8bd, 0x4f41ce7d, 0x714a525d, 0x26bfb5fb, 0x08fc6ae8,
  1879:     0x21580cc1, 0x0df8f6d7, 0x2bf0cfbc, 0x104d7a1b, 0x076a78e4, 0x2c2bdcc3, 0x30865998, 0x2af8a503, 0x210237ff, 0x31009ae6,
  1880:     0x27310606, 0x0aab6539, 0x6a325838, 0x4f78118d, 0x347c419c, 0x1b3e6ee7, 0x2024aa0d, 0x3388ed17, 0x161ca6dd, 0x57a268ab,
  1881:     0x46414fa9, 0x3fe0e0a7, 0x77e33e83, 0x1616f27c, 0x60c9f6ef, 0x067a4dde, 0x6b1e5ef8, 0x4f9d0f9a, 0x72bc9fc7, 0x30fe2432,
  1882:     0x07c7c246, 0x57d376ab, 0x5cb4c10c, 0x762b8c29, 0x359d19c3, 0x616256a0, 0x534b1740, 0x0188cfb0, 0x62d71e39, 0x5634d803,
  1883:     0x08cdf34a, 0x692f4f69, 0x555537f6, 0x1f6b8c08, 0x28ff1d93, 0x2553ac95, 0x3d770f87, 0x631abd83, 0x6b9c545d, 0x2c9381b3,
  1884:     0x563b3884, 0x53e59192, 0x1de2b588, 0x6a8b5723, 0x7001b0af, 0x0efe70cf, 0x7cc67da8, 0x3cccc2af, 0x1947fbac, 0x6c3fbf5b,
  1885:     0x5948a27a, 0x064c17fc, 0x6cdc4ef0, 0x49b366a1, 0x7d775f78, 0x2dbc76b1, 0x129bde28, 0x11697443, 0x0a135638, 0x465958c2,
  1886:     0x6e308cb7, 0x6f028600, 0x5e9c77cd, 0x37c03068, 0x132e6212, 0x4180a441, 0x56e3bd5f, 0x7615be5d, 0x11e434a4, 0x469b3886,
  1887:     0x6376a909, 0x3f5d9cc2, 0x6aa4280a, 0x5a4ce9f9, 0x29819fdd, 0x6b907854, 0x3883c617, 0x439c52d4, 0x32bef75d, 0x5ec74c5b,
  1888:     0x4bbff4ef, 0x40c6b3e0, 0x49917295, 0x26db395a, 0x2a8288d6, 0x0e13be48, 0x48509812, 0x368c2588, 0x59c444c5, 0x6448d926,
  1889:     0x7cc5c02b, 0x287a9ca9, 0x12910d5f, 0x6fe5f006, 0x32507bbb, 0x1ce1ea7c, 0x1380f1ec, 0x61f3d994, 0x3e31e501, 0x3267ce38,
  1890:     0x1b3092ef, 0x1a285ce0, 0x4a21ec82, 0x573f6a5d, 0x4292472f, 0x193db6aa, 0x432429dc, 0x43fced72, 0x6cb314a1, 0x33cf13ca,
  1891:     0x06277fd2, 0x2f29d109, 0x66e29731, 0x4cb5f6c4, 0x0d97d7c3, 0x5fb77693, 0x2486ca46, 0x3a139389, 0x497636e0, 0x2b3e13cb,
  1892:     0x3c25318d, 0x1cba7b8e, 0x014c0043, 0x01ad0109, 0x358ee2c9, 0x05523817, 0x1dd0935a, 0x7b4cfbee, 0x72486eef, 0x0b4fd34a,
  1893:     0x23bda46d, 0x0a2a7a3e, 0x20acf339, 0x4103f25f, 0x55a18ec9, 0x3e7dba06, 0x5d407f89, 0x4294a92a, 0x70190dc4, 0x1b0da649,
  1894:     0x032754c5, 0x5ea38a73, 0x39511704, 0x1216d3ea, 0x2ad56614, 0x4e8393a8, 0x011776ce, 0x7698aedd, 0x217f9877, 0x6b5a4dd1,
  1895:     0x1c74a5a6, 0x2d59998c, 0x5414ad6a, 0x714844ec, 0x62141c8b, 0x17d48092, 0x40777703, 0x07993fe0, 0x02a1c7a9, 0x1384cc7b,
  1896:     0x606483dd, 0x4bcb9fd1, 0x7f6510e3, 0x10c1bbc8, 0x1319d399, 0x146386ef, 0x1edc5cef, 0x3e10566e, 0x15a0805c, 0x49c02d49,
  1897:     0x0444363a, 0x01f5f00d, 0x44bffdb0, 0x7c81c3b0, 0x61645695, 0x457796c3, 0x3989c7bd, 0x20080279, 0x3489dd52, 0x3ed6dd77,
  1898:     0x322dbaa1, 0x20517934, 0x25da0d90, 0x66761235, 0x140eaa3a, 0x28e1518e, 0x6bbb6bc4, 0x44cb89b8, 0x26d9c7a2, 0x6cbab604,
  1899:     0x0cfc0fdb, 0x60131880, 0x2b99316d, 0x03da1c8a, 0x480316f0, 0x7b18925e, 0x54badc6a, 0x2e527669, 0x5e9cdaa7, 0x4d292556,
  1900:     0x6842ddde, 0x318cf7c6, 0x1d94a2da, 0x06fb7f95, 0x3a1ae311, 0x2efd0d70, 0x036bec31, 0x4c9ac96e, 0x05ed3065, 0x14dfab2b,
  1901:     0x4ebfd1ee, 0x3f2d5e77, 0x675df932, 0x4184055f, 0x5a319857, 0x16080c45, 0x7a1de4d9, 0x52599ec7, 0x46d5c273, 0x26dd2849,
  1902:     0x6a4be13b, 0x291998d5, 0x2bc2a195, 0x1f4b83a4, 0x0f3f0bcd, 0x3c2dbb7c, 0x48c122de, 0x6e42f12a, 0x3a6c6e26, 0x7378075f,
  1903:     0x3d612a6e, 0x6fb58974, 0x66aacfcf, 0x3b0e8168, 0x4b7c6c70, 0x33318ef5, 0x5c3da488, 0x3502efbf, 0x520318bf, 0x615935d9,
  1904:     0x5dbc5c3f, 0x36ef680f, 0x71e42db6, 0x654744b4, 0x39aaf009, 0x1a9d6822, 0x5edad0b4, 0x52fd0097, 0x2707da0e, 0x553b50ac,
  1905:     0x5eca8485, 0x45b6fb9f, 0x5e5fafed, 0x5c4fedf4, 0x25b1db93, 0x79520ce1, 0x003e156e, 0x42ffc3fe, 0x41cf8a0c, 0x6cec30c3,
  1906:     0x02aeabd4, 0x6d7f3d9b, 0x39b63ce5, 0x4f2ab77e, 0x3148d784, 0x0b6f9821, 0x4b71cd58, 0x24b9ce19, 0x1b8cb30f, 0x6b65fd10,
  1907:     0x029391b0, 0x0b41bab4, 0x476f21d2, 0x0931422e, 0x2e52585c, 0x1c0acd60, 0x15299375, 0x2a85bea8, 0x7b13c4cd, 0x3edc27c8,
  1908:     0x305da92e, 0x42e1d90e, 0x4d8ca869, 0x16e11a96, 0x1ea21f71, 0x37234c7b, 0x5ffc9e00, 0x06185a81, 0x0da0cd4f, 0x4cd29069,
  1909:     0x68acc297, 0x25e85f36, 0x4cbda11d, 0x05f3ee0e, 0x6e6ef45e, 0x57034594, 0x5c6a0817, 0x2a972a80, 0x09fc051f, 0x70c0fc2c,
  1910:     0x40b148d4, 0x0cb6f5f4, 0x1cabf76a, 0x6c4ad669, 0x097bfef3, 0x02cf5fdc, 0x53da9a2a, 0x05494b58, 0x44fbcf82, 0x6cc2d6bc,
  1911:     0x571fd235, 0x1a1b4c74, 0x205f57a4, 0x589f8a4a, 0x4e200048, 0x1990dbae, 0x1b6dec9f, 0x2b05f88b, 0x1535ac1c, 0x03596119,
  1912:     0x50c0b248, 0x2aa8877d, 0x47b0dca5, 0x2760d466, 0x540c07bd, 0x6036622f, 0x03e8a53b, 0x1195ac83, 0x73e8de64, 0x3e6c324d,
  1913:     0x4c6fb670, 0x72f49a8b, 0x077c5e36, 0x489ed781, 0x70eae918, 0x308cbeea, 0x55f5bdd2, 0x6349372e, 0x4bab3b51, 0x01c847c3,
  1914:     0x487c461e, 0x4fe94f9e, 0x5b9f29f0, 0x446b22df, 0x45e0088d, 0x6bfff135, 0x1bb1bf6c, 0x1821126e, 0x45d7cb2a, 0x6b5ceb76,
  1915:     0x35edc8f9, 0x54238d53, 0x4ff7df73, 0x14dd64da, 0x54402dc3, 0x365c4497, 0x274607de, 0x2c56c3a1, 0x30543430, 0x310328cc,
  1916:     0x7e162901, 0x3b3d4fdf, 0x3f7f7bd1, 0x2ac6cfdb, 0x113d9ecb, 0x4dd45fe4, 0x5f109ea0, 0x6386dde2, 0x36c59456, 0x546c5ad4,
  1917:     0x2d03b333, 0x65b12246, 0x4576f895, 0x31671e74, 0x66e4835a, 0x54bcd738, 0x2a3ecc5f, 0x08a505fe, 0x7efd385b, 0x2771c590,
  1918:     0x6e284d4e, 0x4d4da7e6, 0x47bbbf24, 0x6a5cc272, 0x2f442138, 0x646c8d85, 0x3f205a92, 0x5f7b0385, 0x784b4538, 0x64ca7661,
  1919:     0x09537154, 0x55ad8d81, 0x16190bb8, 0x380d324a, 0x5a581689, 0x5dca47e1, 0x7117f11b, 0x2fa7ae5f, 0x70b6f0d3, 0x5d786998,
  1920:     0x5de8605e, 0x6ecdc733, 0x7bcce4ae, 0x02f9336b, 0x061bc57e, 0x0e341a88, 0x40fb6121, 0x63bbba38, 0x2da118af, 0x231610eb,
  1921:     0x7cd6661e, 0x5b380a93, 0x6fa864ff, 0x6032b573, 0x6794d88a, 0x12455a71, 0x5c9367aa, 0x742a9c13, 0x20a6f9f2, 0x5481aa36,
  1922:     0x133990ed, 0x3d4a402b, 0x27c2c996, 0x4f10ff2e, 0x4c8836d1, 0x7cd9c910, 0x52a09ec8, 0x39f31b93, 0x7405547d, 0x61d3a70a,
  1923:     0x0bad9f7e, 0x3bfcbfa8, 0x5ea4677b, 0x3d565d51, 0x3d9548e2, 0x056ab748, 0x1086e598, 0x31510c1a, 0x1ce79b8e, 0x13a93dca,
  1924:     0x40fb49e9, 0x2b7fe507, 0x47229671, 0x257f5298, 0x5c1d3cfc, 0x287d72d6, 0x6e1b151d, 0x44870a77, 0x06219479, 0x1643b088,
  1925:     0x1ed30a86, 0x45900257, 0x74390268, 0x4449e3c7, 0x1312a1ef, 0x37cb8475, 0x44eaf426, 0x4533fbdf, 0x64834ae8, 0x6cb63267,
  1926:     0x50b7cbdd, 0x628d231e, 0x749f7785, 0x52332935, 0x1529a828, 0x67345a76, 0x424827d1, 0x195309cc, 0x38270237, 0x63f195c8,
  1927:     0x3e3bd69f, 0x4eac2811, 0x71212a9d, 0x5aa6bf37, 0x5446696a, 0x7f36badb, 0x78261dd9, 0x3011b0b4, 0x7ceb1286, 0x4506dbda,
  1928:     0x727a8d39, 0x54dc412e, 0x0c9ad6c9, 0x68dda680, 0x07700d25, 0x2fa7e26a, 0x640601c7, 0x41c27f13, 0x3295f364, 0x5478d753,
  1929:     0x52ce3f13, 0x1d565768, 0x7270babc, 0x1d39a5d3, 0x014b74d3, 0x70ac75d6, 0x7e8a31bb, 0x1b2c4adb, 0x51fdea65, 0x18755a72,
  1930:     0x2251e7f3, 0x76c4ba75, 0x6ea53f62, 0x5c03ccc3, 0x34393d8e, 0x5291d519, 0x41a3858c, 0x76a77631, 0x01d3a9d4, 0x009e8660,
  1931:     0x6f97e18b, 0x4e77e51e, 0x39b5bf0b, 0x611a913a, 0x1fa891f0, 0x1aa5a3e3, 0x1add3909, 0x26fc988e, 0x42d0ac95, 0x12db65c4,
  1932:     0x64b25ef1, 0x1a9de352, 0x0692b42a, 0x5925cc9d, 0x08657309, 0x0cc167d9, 0x446c6821, 0x65177b9d, 0x6160e142, 0x75b20ee8,
  1933:     0x2ee8f956, 0x3a8b2f71, 0x42a4483f, 0x1995d7c2, 0x219cb234, 0x365f5360, 0x50f3ddf9, 0x7ab9edb0, 0x6d3f88cf, 0x4d8834dd,
  1934:     0x6a318775, 0x5135e2f2, 0x733a9c22, 0x29b8afc4, 0x0196f1e8, 0x1cdf2428, 0x574b4bd3, 0x52aabb2d, 0x6c2e7d75, 0x2b182706,
  1935:     0x00b83bf1, 0x014177f3, 0x337125a7, 0x1116fdfb, 0x067620e3, 0x038cc33c, 0x6b20d55b, 0x5a89bbcf, 0x2026be45, 0x121ae7bc,
  1936:     0x0b0da5ce, 0x3fac560c, 0x4d1c9199, 0x6f434273, 0x626bc455, 0x2f3ac2e5, 0x55c47451, 0x10d32290, 0x0d6056ad, 0x55eb17b2,
  1937:     0x25bb8308, 0x25fe6bad, 0x588a6768, 0x24ab28f5, 0x2e782937, 0x3dfcae20, 0x10836a39, 0x7c7518cf, 0x0e077ab2, 0x1639592d,
  1938:     0x337f21ed, 0x282f4cc2, 0x1d0e7f15, 0x5806636e, 0x3b8bf886, 0x72b546e1, 0x50d88c39, 0x7279faad, 0x28f2d733, 0x0028d781,
  1939:     0x06827f2d, 0x682b43aa, 0x6b236ff7, 0x1297a5e3, 0x6e29645f, 0x758b2b8a, 0x5de212c3, 0x458994b2, 0x73fd40d9, 0x44c5f4f6,
  1940:     0x16f4d9a6, 0x1567f3f8, 0x1d00f535, 0x408dfb22, 0x631b1bfc, 0x5da282de, 0x5f203386, 0x28d7ac86, 0x4fd91cdf, 0x22a1af9a,
  1941:     0x14f8ad6a, 0x5935d902, 0x31485f9d, 0x15fdd6dc, 0x79dbd6e6, 0x5e2b9f94, 0x318214b5, 0x36f4ff26, 0x543f0d7d, 0x35dab45a,
  1942:     0x0c1c9605, 0x38c975b7, 0x2476481f, 0x22895d47, 0x46343566, 0x136ada18, 0x58788dfc, 0x344413df, 0x7958e234, 0x49bcc1af,
  1943:     0x52992f70, 0x05857c27, 0x3e80a00b, 0x395188ae, 0x17c786f4, 0x21b69a70, 0x69e85969, 0x3b595648, 0x7e289b08, 0x60e1e008,
  1944:     0x1412fc9f, 0x52fb951c, 0x271a1e38, 0x554eca19, 0x7e155927, 0x249a71c0, 0x2a4bdd54, 0x67e14c7b, 0x34399971, 0x715baad4,
  1945:     0x629f0023, 0x63358a9a, 0x22ea0b4f, 0x2f9f0306, 0x2127ff49, 0x535ca59c, 0x7a5fdde9, 0x67037d85, 0x3a294333, 0x5d53a7c6,
  1946:     0x766ddb83, 0x27a86d04, 0x4211be21, 0x15c7aa13, 0x1a032eae, 0x16fe5a05, 0x3ee6ccf8, 0x503ba362, 0x6bad8c0a, 0x7ecb5cbd,
  1947:     0x54b72670, 0x4efeb2a3, 0x5521ccd6, 0x5b24b5ac, 0x1158acee, 0x5e5434b8, 0x47ca2cfa, 0x4dc9ebdb, 0x6e2520f4, 0x712d6079,
  1948:     0x479cb1d0, 0x412ec476, 0x6df4e0ce, 0x218dccdd, 0x112dc112, 0x01a06f3c, 0x0a83fb99, 0x4cf103b8, 0x0ae80abf, 0x669460db,
  1949:     0x6b378631, 0x1f046ecc, 0x6b9959db, 0x21603fd5, 0x2f580e29, 0x2ae0ad5d, 0x6bf5b0bd, 0x4af4a5f0, 0x02e7ace9, 0x43c47e49,
  1950:     0x2d62c9ac, 0x278d6bae, 0x104be4ed, 0x5c16985d, 0x546c0ed2, 0x72af0b2a, 0x61e1a03e, 0x7eced683, 0x6698ec3a, 0x7142ea4b,
  1951:     0x5f24a858, 0x6e9c3272, 0x06f911c9, 0x0d5513a3, 0x1fc36964, 0x67ed3ad4, 0x2578ec29, 0x7cfd545a, 0x2b766f3e, 0x76b83a17,
  1952:     0x688dd533, 0x7f6f1b7b, 0x7bd82cc2, 0x16398030, 0x29ebb591, 0x28bd8e64, 0x5adfbbc3, 0x1bc4cf94, 0x73d1a019, 0x21dc51ba,
  1953:     0x258a3a9a, 0x46e4c4c5, 0x6928185e, 0x530afef7, 0x2d875f8b, 0x1f4f5d6f, 0x148d28b4, 0x463d8e26, 0x00bc57e7, 0x30a17145,
  1954:     0x5b016cdd, 0x2b1c719f, 0x52ced170, 0x525ea256, 0x04b90d6f, 0x6c1ccaef, 0x2b714760, 0x4c558061, 0x1a2a9160, 0x12d57856,
  1955:     0x4f909d7d, 0x32160cfc, 0x774b63e8, 0x5580957f, 0x3f205106, 0x6cf7f633, 0x76d4d795, 0x2bffd269, 0x6c2ca700, 0x4c9bac8e,
  1956:     0x34a1ad86, 0x19f38439, 0x16f7e283, 0x77df8d0a, 0x251e13b6, 0x32e8b8c3, 0x46a1068a, 0x1e9c5c29, 0x5b2fa425, 0x02e01623,
  1957:     0x51ce180d, 0x66090a25, 0x5df2cab5, 0x552ac91c, 0x2e89ef09, 0x0c000db6, 0x6951b1e0, 0x789a0cbc, 0x6ae6f080, 0x197c594d,
  1958:     0x10fa6934, 0x798f992f, 0x4bfbe442, 0x665adf98, 0x0215d378, 0x367fd774, 0x574985bf, 0x447087e5, 0x4828acdf, 0x26924cf7,
  1959:     0x0f3ac27c, 0x0df67285, 0x60d6c4e2, 0x260b1d34, 0x22381ff4, 0x019645ba, 0x531bc9b6, 0x1e29e4a7, 0x2cb63fe8, 0x3c34ff74,
  1960:     0x45e57b7c, 0x131273c5, 0x24ab0a65, 0x4683a26a, 0x2f7d5a42, 0x0c8e8918, 0x68b0e425, 0x2ede222c, 0x1fffc690, 0x1951ff6c,
  1961:     0x390fa5f7, 0x72db49bf, 0x1a472a23, 0x3edb35f5, 0x2c822c06, 0x7b751e95, 0x20b4c1e8, 0x7201c30a, 0x1a568076, 0x3a3229c0,
  1962:     0x0e8de742, 0x11c7a6ac, 0x0108583f, 0x61b495f1, 0x20f7527e, 0x2f65cc0e, 0x412fb7e9, 0x0f43e808, 0x5dc68477, 0x7a9463f7,
  1963:     0x5fc162d6, 0x6949775c, 0x0a355126, 0x3f132edb, 0x7166ef0a, 0x4d1d3a6f, 0x61ad61d1, 0x4fdab592, 0x71a3b69c, 0x35df937d,
  1964:     0x137af459, 0x4a907aed, 0x3ac1d542, 0x18e3e8d7, 0x5e8fac78, 0x14a4ae49, 0x6aabefb6, 0x77e37c4c, 0x3e4f0dde, 0x7ed7dccf,
  1965:     0x3bac1d8a, 0x758937b9, 0x773b8d06, 0x44928857, 0x36123085, 0x6cfe74b3, 0x542cde0f, 0x75489536, 0x0bed8292, 0x2413fd2b,
  1966:     0x5a2b596b, 0x5802b312, 0x1466722c, 0x5fd5e188, 0x2cfc3e6c, 0x457efa07, 0x7ca7008b, 0x30042951, 0x4d63ead1, 0x1dd4a4df,
  1967:     0x3fb0dc1e, 0x49a31414, 0x4325445a, 0x5d3b0f83, 0x33285b53, 0x22a6d56b, 0x60ce333d, 0x261489f9, 0x206fdd19, 0x0473cf16,
  1968:     0x12aff801, 0x3afc227c, 0x60cb396d, 0x71adb49d, 0x24f0aed6, 0x60dec1f8, 0x74bbf1d8, 0x6317b251, 0x7ddc3bf1, 0x39715e5c,
  1969:     0x5dd12bf8, 0x0b70339b, 0x1751f725, 0x25cf2702, 0x66ad9d94, 0x5c36fbf7, 0x2cd904e7, 0x1705954c, 0x6522c5ae, 0x34701d5f,
  1970:     0x1d1f3539, 0x4e5ac6f3, 0x58b21a8d, 0x5604296f, 0x59f20834, 0x71553e1c, 0x645dcd7a, 0x75f00a6f, 0x2dd36c8a, 0x2b16683e,
  1971:     0x5217a178, 0x14afab5a, 0x78298160, 0x1561f22d, 0x44c17ce8, 0x7de4db61, 0x50910214, 0x513bc866, 0x478f0860, 0x5bea3878,
  1972:     0x2001c11d, 0x1c94c363, 0x4f10f050, 0x4c8e924f, 0x4e6ce03d, 0x5d1db956, 0x796b4a2b, 0x76bbf110, 0x6f4060ad, 0x209f4870,
  1973:     0x020eed54, 0x0003cfb4, 0x01b409a1, 0x1cd56a51, 0x5e1a1f1b, 0x0ad47bed, 0x0cc38b4a, 0x5bd71ce4, 0x76b45f98, 0x2f10a374,
  1974:     0x345d3ab0, 0x6d3f6a7c, 0x7d00e32a, 0x5790fb34, 0x6a007a58, 0x2631f0a8, 0x53537781, 0x47e6d0a0, 0x1ef295fa, 0x12cb2e53,
  1975:     0x1cc6f20c, 0x1f08d6aa, 0x4e0bd445, 0x0107ab02, 0x7692436d, 0x3c67f4e8, 0x04a2717c, 0x270b82ce, 0x284fedd0, 0x5856f438,
  1976:     0x2dd7e754, 0x54aa2e82, 0x009d1952, 0x433b5bf8, 0x79923e89, 0x6e4a9f6e, 0x4173ab12, 0x06c14fa3, 0x1a1800a9, 0x04e69bb2,
  1977:     0x56165d57, 0x432db958, 0x7e07141f, 0x15435c6f, 0x52777a77, 0x33496069, 0x3c48a10c, 0x0cd25a95, 0x0a91f166, 0x265bc1be,
  1978:     0x67f67d7a, 0x719c9e48, 0x3e44fddd, 0x292e3d83, 0x46297725, 0x55068553, 0x3e829c3a, 0x02de9ef9, 0x2f4cf771, 0x0f7af4b0,
  1979:     0x2a4a6256, 0x2c1f745d, 0x1b3c5c63, 0x415065a9, 0x144eec3f, 0x10adfef5, 0x7a8dd087, 0x5ba28ec9, 0x1e715b24, 0x2e781501,
  1980:     0x196aafdb, 0x6ddc0ff5, 0x6a7db0b8, 0x2922c055, 0x1769411c, 0x7434d29c, 0x557218d4, 0x4d8688d7, 0x1fbe0ab7, 0x4e7d4e64,
  1981:     0x2d3d2515, 0x7780f9d5, 0x701dfb6b, 0x4d9b6fed, 0x010dfebe, 0x7fecdbf5, 0x4882d11f, 0x276ba7ec, 0x7bb0cd6c, 0x259938b0,
  1982:   };
  1983: 
  1984:   //------------------------------------------------------------------------
  1985:   //log
  1986:   //  echo read("efp.gp");eval("f(x)=log((1+x)/(1-x))");efpchebyshev("LOG_C",f,2*sqrt(2)-3,3-2*sqrt(2),27) | gp -q
  1987:   public final EFP       LOG_C1 = new EFP (P,      1, 0x8000000000000000L, 0x0000000L << 36);  //=2.00000000000000000000000000000
  1988:   public final EFP       LOG_C3 = new EFP (P,     -1, 0xaaaaaaaaaaaaaaaaL, 0xaaaaafaL << 36);  //=0.666666666666666666666666682688
  1989:   public final EFP       LOG_C5 = new EFP (P,     -2, 0xccccccccccccccccL, 0xcc9635cL << 36);  //=0.399999999999999999999977422089
  1990:   public final EFP       LOG_C7 = new EFP (P,     -2, 0x9249249249249249L, 0xb11c709L << 36);  //=0.285714285714285714300594501439
  1991:   public final EFP       LOG_C9 = new EFP (P,     -3, 0xe38e38e38e38e1f4L, 0xa08ab7fL << 36);  //=0.222222222222222216671173431320
  1992:   public final EFP      LOG_C11 = new EFP (P,     -3, 0xba2e8ba2e8bba550L, 0x957b4b0L << 36);  //=0.181818181818183118424115217462
  1993:   public final EFP      LOG_C13 = new EFP (P,     -3, 0x9d89d89d88f3a6b4L, 0xb83ee9bL << 36);  //=0.153846153845950485101802426447
  1994:   public final EFP      LOG_C15 = new EFP (P,     -3, 0x88888888e97610a0L, 0x018bbc5L << 36);  //=0.133333333355372176624252479880
  1995:   public final EFP      LOG_C17 = new EFP (P,     -4, 0xf0f0f0b6e98b6c2fL, 0x176ec78L << 36);  //=0.117647057134666354102829804155
  1996:   public final EFP      LOG_C19 = new EFP (P,     -4, 0xd79442422528c14bL, 0xdacdc08L << 36);  //=0.105263250011052968996816802164
  1997:   public final EFP      LOG_C21 = new EFP (P,     -4, 0xc30a54423d395d6dL, 0xa2f5188L << 36);  //=0.0952345450129114490041764123058
  1998:   public final EFP      LOG_C23 = new EFP (P,     -4, 0xb247b3a940a7a020L, 0x5cb7483L << 36);  //=0.0870508228327542823405094334272
  1999:   public final EFP      LOG_C25 = new EFP (P,     -4, 0xa07d6fb3e1085165L, 0x68590abL << 36);  //=0.0783642508287167052010634682520
  2000:   public final EFP      LOG_C27 = new EFP (P,     -4, 0xb976c8a2f3029b2dL, 0xa0b471bL << 36);  //=0.0905585932472388526925818403382
  2001:   //  98.60bit
  2002: 
  2003:   //------------------------------------------------------------------------
  2004:   //log10
  2005:   //  echo read("efp.gp");eval("f(x)=log((1+x)/(1-x))/log(10)");efpchebyshev("LOG10_C",f,2*sqrt(2)-3,3-2*sqrt(2),27) | gp -q
  2006:   public final EFP     LOG10_C1 = new EFP (P,     -1, 0xde5bd8a937287195L, 0x355baabL << 36);  //=0.868588963806503655302257837837
  2007:   public final EFP     LOG10_C3 = new EFP (P,     -2, 0x943d3b1b7a1af663L, 0x78e7cb7L << 36);  //=0.289529654602167885100752619580
  2008:   public final EFP     LOG10_C5 = new EFP (P,     -3, 0xb1e313ba9286c144L, 0x2a80513L << 36);  //=0.173717792761300731060441762115
  2009:   public final EFP     LOG10_C7 = new EFP (P,     -4, 0xfe1fd30a882e38abL, 0x7a44130L << 36);  //=0.124084137686643379335356372423
  2010:   public final EFP     LOG10_C9 = new EFP (P,     -4, 0xc5a6f979f823f1cbL, 0x86cedb8L << 36);  //=0.0965098848673892926227943455482
  2011:   public final EFP    LOG10_C11 = new EFP (P,     -4, 0xa1b729353f6480daL, 0x7d9f583L << 36);  //=0.0789626330733190788064418159654
  2012:   public final EFP    LOG10_C13 = new EFP (P,     -4, 0x88d60f2d0d7965b3L, 0x533de4bL << 36);  //=0.0668145356773350395174370490118
  2013:   public final EFP    LOG10_C15 = new EFP (P,     -5, 0xed2ec4f96bbfdbfdL, 0xfddb370L << 36);  //=0.0579059309300049250489272107676
  2014:   public final EFP    LOG10_C17 = new EFP (P,     -5, 0xd147624ebd9efe71L, 0xccd7fdfL << 36);  //=0.0510934677257421907379148609296
  2015:   public final EFP    LOG10_C19 = new EFP (P,     -5, 0xbb3fe99c80f7032eL, 0x107f05cL << 36);  //=0.0457152486270027163909629543765
  2016:   public final EFP    LOG10_C21 = new EFP (P,     -5, 0xa968eecf07930e0cL, 0xbd58cd0L << 36);  //=0.0413598373856742928826627330520
  2017:   public final EFP    LOG10_C23 = new EFP (P,     -5, 0x9ada242bfa9153a2L, 0x1833fc8L << 36);  //=0.0378056920014027856718189387863
  2018:   public final EFP    LOG10_C25 = new EFP (P,     -5, 0x8b665b489db905f7L, 0x74ec677L << 36);  //=0.0340331617133939941648757175539
  2019:   public final EFP    LOG10_C27 = new EFP (P,     -5, 0xa1178c2d7152670fL, 0x3d41c7cL << 36);  //=0.0393290973361969170732439582255
  2020:   //  96.83bit
  2021:   public final EFP[] ACCURATE_LOG10_BASE = {
  2022:     //  echo read("efp.gp");p=0;for(n=0,39,q=floor(log(10)/log(2)*n);for(i=p+1,q-1,print("    null,  //",i));p=q;efpmem([Str("10^",n)])) | gp -q
  2023:     new EFP (P,      0, 0x8000000000000000L, 0x0000000L << 36),  //=10^0=1.00000000000000000000000000000
  2024:     null,  //1
  2025:     null,  //2
  2026:     new EFP (P,      3, 0xa000000000000000L, 0x0000000L << 36),  //=10^1=10.0000000000000000000000000000
  2027:     null,  //4
  2028:     null,  //5
  2029:     new EFP (P,      6, 0xc800000000000000L, 0x0000000L << 36),  //=10^2=100.000000000000000000000000000
  2030:     null,  //7
  2031:     null,  //8
  2032:     new EFP (P,      9, 0xfa00000000000000L, 0x0000000L << 36),  //=10^3=1000.00000000000000000000000000
  2033:     null,  //10
  2034:     null,  //11
  2035:     null,  //12
  2036:     new EFP (P,     13, 0x9c40000000000000L, 0x0000000L << 36),  //=10^4=10000.0000000000000000000000000
  2037:     null,  //14
  2038:     null,  //15
  2039:     new EFP (P,     16, 0xc350000000000000L, 0x0000000L << 36),  //=10^5=100000.000000000000000000000000
  2040:     null,  //17
  2041:     null,  //18
  2042:     new EFP (P,     19, 0xf424000000000000L, 0x0000000L << 36),  //=10^6=1000000.00000000000000000000000
  2043:     null,  //20
  2044:     null,  //21
  2045:     null,  //22
  2046:     new EFP (P,     23, 0x9896800000000000L, 0x0000000L << 36),  //=10^7=10000000.0000000000000000000000
  2047:     null,  //24
  2048:     null,  //25
  2049:     new EFP (P,     26, 0xbebc200000000000L, 0x0000000L << 36),  //=10^8=100000000.000000000000000000000
  2050:     null,  //27
  2051:     null,  //28
  2052:     new EFP (P,     29, 0xee6b280000000000L, 0x0000000L << 36),  //=10^9=1000000000.00000000000000000000
  2053:     null,  //30
  2054:     null,  //31
  2055:     null,  //32
  2056:     new EFP (P,     33, 0x9502f90000000000L, 0x0000000L << 36),  //=10^10=10000000000.0000000000000000000
  2057:     null,  //34
  2058:     null,  //35
  2059:     new EFP (P,     36, 0xba43b74000000000L, 0x0000000L << 36),  //=10^11=100000000000.000000000000000000
  2060:     null,  //37
  2061:     null,  //38
  2062:     new EFP (P,     39, 0xe8d4a51000000000L, 0x0000000L << 36),  //=10^12=1000000000000.00000000000000000
  2063:     null,  //40
  2064:     null,  //41
  2065:     null,  //42
  2066:     new EFP (P,     43, 0x9184e72a00000000L, 0x0000000L << 36),  //=10^13=10000000000000.0000000000000000
  2067:     null,  //44
  2068:     null,  //45
  2069:     new EFP (P,     46, 0xb5e620f480000000L, 0x0000000L << 36),  //=10^14=100000000000000.000000000000000
  2070:     null,  //47
  2071:     null,  //48
  2072:     new EFP (P,     49, 0xe35fa931a0000000L, 0x0000000L << 36),  //=10^15=1000000000000000.00000000000000
  2073:     null,  //50
  2074:     null,  //51
  2075:     null,  //52
  2076:     new EFP (P,     53, 0x8e1bc9bf04000000L, 0x0000000L << 36),  //=10^16=10000000000000000.0000000000000
  2077:     null,  //54
  2078:     null,  //55
  2079:     new EFP (P,     56, 0xb1a2bc2ec5000000L, 0x0000000L << 36),  //=10^17=100000000000000000.000000000000
  2080:     null,  //57
  2081:     null,  //58
  2082:     new EFP (P,     59, 0xde0b6b3a76400000L, 0x0000000L << 36),  //=10^18=1000000000000000000.00000000000
  2083:     null,  //60
  2084:     null,  //61
  2085:     null,  //62
  2086:     new EFP (P,     63, 0x8ac7230489e80000L, 0x0000000L << 36),  //=10^19=10000000000000000000.0000000000
  2087:     null,  //64
  2088:     null,  //65
  2089:     new EFP (P,     66, 0xad78ebc5ac620000L, 0x0000000L << 36),  //=10^20=100000000000000000000.000000000
  2090:     null,  //67
  2091:     null,  //68
  2092:     new EFP (P,     69, 0xd8d726b7177a8000L, 0x0000000L << 36),  //=10^21=1000000000000000000000.00000000
  2093:     null,  //70
  2094:     null,  //71
  2095:     null,  //72
  2096:     new EFP (P,     73, 0x878678326eac9000L, 0x0000000L << 36),  //=10^22=10000000000000000000000.0000000
  2097:     null,  //74
  2098:     null,  //75
  2099:     new EFP (P,     76, 0xa968163f0a57b400L, 0x0000000L << 36),  //=10^23=100000000000000000000000.000000
  2100:     null,  //77
  2101:     null,  //78
  2102:     new EFP (P,     79, 0xd3c21bcecceda100L, 0x0000000L << 36),  //=10^24=1000000000000000000000000.00000
  2103:     null,  //80
  2104:     null,  //81
  2105:     null,  //82
  2106:     new EFP (P,     83, 0x84595161401484a0L, 0x0000000L << 36),  //=10^25=10000000000000000000000000.0000
  2107:     null,  //84
  2108:     null,  //85
  2109:     new EFP (P,     86, 0xa56fa5b99019a5c8L, 0x0000000L << 36),  //=10^26=100000000000000000000000000.000
  2110:     null,  //87
  2111:     null,  //88
  2112:     new EFP (P,     89, 0xcecb8f27f4200f3aL, 0x0000000L << 36),  //=10^27=1000000000000000000000000000.00
  2113:     null,  //90
  2114:     null,  //91
  2115:     null,  //92
  2116:     new EFP (P,     93, 0x813f3978f8940984L, 0x4000000L << 36),  //=10^28=10000000000000000000000000000.0
  2117:     null,  //94
  2118:     null,  //95
  2119:     new EFP (P,     96, 0xa18f07d736b90be5L, 0x5000000L << 36),  //=10^29=100000000000000000000000000000
  2120:     null,  //97
  2121:     null,  //98
  2122:     new EFP (P,     99, 0xc9f2c9cd04674edeL, 0xa400000L << 36),  //=10^30=1.00000000000000000000000000000e+30
  2123:     null,  //100
  2124:     null,  //101
  2125:     new EFP (P,    102, 0xfc6f7c4045812296L, 0x4d00000L << 36),  //=10^31=1.00000000000000000000000000000e+31
  2126:     null,  //103
  2127:     null,  //104
  2128:     null,  //105
  2129:     new EFP (P,    106, 0x9dc5ada82b70b59dL, 0xf020000L << 36),  //=10^32=1.00000000000000000000000000000e+32
  2130:     null,  //107
  2131:     null,  //108
  2132:     new EFP (P,    109, 0xc5371912364ce305L, 0x6c28000L << 36),  //=10^33=1.00000000000000000000000000000e+33
  2133:     null,  //110
  2134:     null,  //111
  2135:     new EFP (P,    112, 0xf684df56c3e01bc6L, 0xc732000L << 36),  //=10^34=1.00000000000000000000000000000e+34
  2136:     null,  //113
  2137:     null,  //114
  2138:     null,  //115
  2139:     new EFP (P,    116, 0x9a130b963a6c115cL, 0x3c7f400L << 36),  //=10^35=1.00000000000000000000000000000e+35
  2140:     null,  //117
  2141:     null,  //118
  2142:     new EFP (P,    119, 0xc097ce7bc90715b3L, 0x4b9f100L << 36),  //=10^36=1.00000000000000000000000000000e+36
  2143:     null,  //120
  2144:     null,  //121
  2145:     new EFP (P,    122, 0xf0bdc21abb48db20L, 0x1e86d40L << 36),  //=10^37=1.00000000000000000000000000000e+37
  2146:     null,  //123
  2147:     null,  //124
  2148:     null,  //125
  2149:     new EFP (P,    126, 0x96769950b50d88f4L, 0x1314448L << 36),  //=10^38=1.00000000000000000000000000000e+38
  2150:     null,  //127
  2151:     null,  //128
  2152:     new EFP (P,    129, 0xbc143fa4e250eb31L, 0x17d955aL << 36),  //=10^39=1.00000000000000000000000000000e+39
  2153:   };
  2154: 
  2155:   //------------------------------------------------------------------------
  2156:   //log1p
  2157:   //  echo read("efp.gp");efppub(["LOG1P_A","sqrt(2)/2-1"],["LOG1P_B","sqrt(2)-1"]) | gp -q
  2158:   public final EFP      LOG1P_A = new EFP (M,     -2, 0x95f619980c4336f7L, 0x4d04ecaL << 36);  //<sqrt(2)/2-1=-0.292893218813452475599155637895
  2159:   public final EFP      LOG1P_B = new EFP (P,     -2, 0xd413cccfe7799211L, 0x65f626dL << 36);  //>sqrt(2)-1=0.414213562373095048801688724210
  2160: 
  2161:   //------------------------------------------------------------------------
  2162:   //log2
  2163:   //  echo read("efp.gp");eval("f(x)=log((1+x)/(1-x))/log(2)");efpchebyshev("LOG2_C",f,2*sqrt(2)-3,3-2*sqrt(2),27) | gp -q
  2164:   public final EFP      LOG2_C1 = new EFP (P,      1, 0xb8aa3b295c17f0bbL, 0xbe87fedL << 36);  //=2.88539008177792681471984936198
  2165:   public final EFP      LOG2_C3 = new EFP (P,     -1, 0xf6384ee1d01feba4L, 0xfe0ab04L << 36);  //=0.961796693925975604906616477151
  2166:   public final EFP      LOG2_C5 = new EFP (P,     -1, 0x93bb62877cdff3c9L, 0x651237dL << 36);  //=0.577078016355585362943937299454
  2167:   public final EFP      LOG2_C7 = new EFP (P,     -2, 0xd30bb153d6f6c9fbL, 0xeda6121L << 36);  //=0.412198583111132402124303236615
  2168:   public final EFP      LOG2_C9 = new EFP (P,     -2, 0xa42589ebe015469bL, 0xde296e2L << 36);  //=0.320598897975325193627068255683
  2169:   public final EFP     LOG2_C11 = new EFP (P,     -2, 0x864d424ca0127799L, 0x7cdb742L << 36);  //=0.262308189252540677191282011266
  2170:   public final EFP     LOG2_C13 = new EFP (P,     -3, 0xe347ab469770ad93L, 0x0c89676L << 36);  //=0.221953083213393290074079579936
  2171:   public final EFP     LOG2_C15 = new EFP (P,     -3, 0xc4f9d8b532564b9eL, 0x7d50b7aL << 36);  //=0.192359338816990450904061345775
  2172:   public final EFP     LOG2_C17 = new EFP (P,     -3, 0xadcd64b1c6112030L, 0x2abb956L << 36);  //=0.169728825903363689895336947859
  2173:   public final EFP     LOG2_C19 = new EFP (P,     -3, 0x9b81e9e58a334402L, 0x0adf93dL << 36);  //=0.151862768778801240948586652949
  2174:   public final EFP     LOG2_C21 = new EFP (P,     -3, 0x8cb11e7e743a9994L, 0xf74da62L << 36);  //=0.137394405811444109070588133256
  2175:   public final EFP     LOG2_C23 = new EFP (P,     -3, 0x809a15f248e3a311L, 0x83d14aaL << 36);  //=0.125587790406118348750302928355
  2176:   public final EFP     LOG2_C25 = new EFP (P,     -4, 0xe789c1589b85b20fL, 0xbe84fc9L << 36);  //=0.113055716053568431590620272062
  2177:   public final EFP     LOG2_C27 = new EFP (P,     -3, 0x85c8b3f2b1daf78cL, 0x52db8eeL << 36);  //=0.130648433387672262093665382456
  2178:   //  96.81bit
  2179: 
  2180:   //------------------------------------------------------------------------
  2181:   //lgamma
  2182:   //  echo read("efp.gp");n=14;c=vector(n,k,bernfrac(2*k)/(2*k*(2*k-1)));for(k=1,n,efppub([Str("LGAMMA_C",k),Str(c[k])]));efpclose(lngamma,"(x-1/2)*log(x)-x+log(2*Pi)/2+sum(k=1,n,c[k]/x^(2*k-1))",13,100) | gp -q
  2183:   public final EFP    LGAMMA_C1 = new EFP (P,     -4, 0xaaaaaaaaaaaaaaaaL, 0xaaaaaabL << 36);  //>1/12=0.0833333333333333333333333333333
  2184:   public final EFP    LGAMMA_C2 = new EFP (M,     -9, 0xb60b60b60b60b60bL, 0x60b60b6L << 36);  //>-1/360=-0.00277777777777777777777777777778
  2185:   public final EFP    LGAMMA_C3 = new EFP (P,    -11, 0xd00d00d00d00d00dL, 0x00d00d0L << 36);  //<1/1260=7.93650793650793650793650793651e-4
  2186:   public final EFP    LGAMMA_C4 = new EFP (M,    -11, 0x9c09c09c09c09c09L, 0xc09c09cL << 36);  //>-1/1680=-5.95238095238095238095238095238e-4
  2187:   public final EFP    LGAMMA_C5 = new EFP (P,    -11, 0xdca8f158c7f91ab8L, 0x7539c03L << 36);  //<1/1188=8.41750841750841750841750841751e-4
  2188:   public final EFP    LGAMMA_C6 = new EFP (M,    -10, 0xfb5586ccc9e3e40fL, 0xb5586cdL << 36);  //<-691/360360=-0.00191752691752691752691752691753
  2189:   public final EFP    LGAMMA_C7 = new EFP (P,     -8, 0xd20d20d20d20d20dL, 0x20d20d2L << 36);  //<1/156=0.00641025641025641025641025641026
  2190:   public final EFP    LGAMMA_C8 = new EFP (M,     -6, 0xf21436587a9cbee1L, 0x0325477L << 36);  //<-3617/122400=-0.0295506535947712418300653594771
  2191:   public final EFP    LGAMMA_C9 = new EFP (P,     -3, 0xb7f4b1c0f033ffd0L, 0xc3b7f4bL << 36);  //<43867/244188=0.179644372368830573164938490016
  2192:   public final EFP   LGAMMA_C10 = new EFP (M,      0, 0xb23b3808c0f9cf6dL, 0xedce731L << 36);  //>-174611/125400=-1.39243221690590111642743221691
  2193:   public final EFP   LGAMMA_C11 = new EFP (P,      3, 0xd672219167002d3aL, 0x7a9c886L << 36);  //<77683/5796=13.4028640441683919944789510007
  2194:   public final EFP   LGAMMA_C12 = new EFP (M,      7, 0x9cd9292e6660d55bL, 0x3f712ecL << 36);  //<-236364091/1506960=-156.848284626002017306365132452
  2195:   public final EFP   LGAMMA_C13 = new EFP (P,     11, 0x8911a740da740da7L, 0x40da741L << 36);  //>657931/300=2193.10333333333333333333333333
  2196:   public final EFP   LGAMMA_C14 = new EFP (M,     15, 0x8d0cc570e255bf59L, 0xff6eec2L << 36);  //>-3392780147/93960=-36108.7712537249893571732652192
  2197:   //  92.41bit
  2198:   //  echo read("efp.gp");efppub(["LOGTWOPI_2",log(2*Pi)/2]) | gp -q
  2199:   public final EFP   LOGTWOPI_2 = new EFP (P,     -1, 0xeb3f8e4325f5a534L, 0x94bc900L << 36);  //<0.918938533204672741780329736406
  2200: 
  2201:   //------------------------------------------------------------------------
  2202:   //setapery
  2203:   public final EFP[] ROUNDED_APERY = {
  2204:     //  echo read("efp.gp");for(rm=RN,RP,efpmem([zeta(3),rm,strrmf(rm,"ζ(3)")])) | gp -q
  2205:     new EFP (P,      0, 0x99dd0027803109c1L, 0xb8b8ae3L << 36),  //>RN(ζ(3))=1.20205690315959428539973816151
  2206:     new EFP (P,      0, 0x99dd0027803109c1L, 0xb8b8ae2L << 36),  //<RZ(ζ(3))=1.20205690315959428539973816151
  2207:     new EFP (P,      0, 0x99dd0027803109c1L, 0xb8b8ae2L << 36),  //<RM(ζ(3))=1.20205690315959428539973816151
  2208:     new EFP (P,      0, 0x99dd0027803109c1L, 0xb8b8ae3L << 36),  //>RP(ζ(3))=1.20205690315959428539973816151
  2209:   };
  2210: 
  2211:   //------------------------------------------------------------------------
  2212:   //setcatalan
  2213:   public final EFP[] ROUNDED_CATALAN = {
  2214:     //  echo read("efp.gp");for(rm=RN,RP,efpmem([Catalan,rm,strrmf(rm,"G")])) | gp -q
  2215:     new EFP (P,     -1, 0xea7cb89f409ae845L, 0x215822eL << 36),  //<RN(G)=0.915965594177219015054603514932
  2216:     new EFP (P,     -1, 0xea7cb89f409ae845L, 0x215822eL << 36),  //<RZ(G)=0.915965594177219015054603514932
  2217:     new EFP (P,     -1, 0xea7cb89f409ae845L, 0x215822eL << 36),  //<RM(G)=0.915965594177219015054603514932
  2218:     new EFP (P,     -1, 0xea7cb89f409ae845L, 0x215822fL << 36),  //>RP(G)=0.915965594177219015054603514932
  2219:   };
  2220: 
  2221:   //------------------------------------------------------------------------
  2222:   //seteuler
  2223:   public final EFP[] ROUNDED_EULER = {
  2224:     //  echo read("efp.gp");for(rm=RN,RP,efpmem([Euler,rm,strrmf(rm,"γ")])) | gp -q
  2225:     new EFP (P,     -1, 0x93c467e37db0c7a4L, 0xd1be3f8L << 36),  //<RN(γ)=0.577215664901532860606512090082
  2226:     new EFP (P,     -1, 0x93c467e37db0c7a4L, 0xd1be3f8L << 36),  //<RZ(γ)=0.577215664901532860606512090082
  2227:     new EFP (P,     -1, 0x93c467e37db0c7a4L, 0xd1be3f8L << 36),  //<RM(γ)=0.577215664901532860606512090082
  2228:     new EFP (P,     -1, 0x93c467e37db0c7a4L, 0xd1be3f9L << 36),  //>RP(γ)=0.577215664901532860606512090082
  2229:   };
  2230: 
  2231:   //------------------------------------------------------------------------
  2232:   //setnapier
  2233:   public final EFP[] ROUNDED_NAPIER = {
  2234:     //  echo read("efp.gp");for(rm=RN,RP,efpmem([exp(1),rm,strrmf(rm,"e")])) | gp -q
  2235:     new EFP (P,      1, 0xadf85458a2bb4a9aL, 0xafdc562L << 36),  //<RN(e)=2.71828182845904523536028747135
  2236:     new EFP (P,      1, 0xadf85458a2bb4a9aL, 0xafdc562L << 36),  //<RZ(e)=2.71828182845904523536028747135
  2237:     new EFP (P,      1, 0xadf85458a2bb4a9aL, 0xafdc562L << 36),  //<RM(e)=2.71828182845904523536028747135
  2238:     new EFP (P,      1, 0xadf85458a2bb4a9aL, 0xafdc563L << 36),  //>RP(e)=2.71828182845904523536028747135
  2239:   };
  2240: 
  2241:   //------------------------------------------------------------------------
  2242:   //setpi
  2243:   public final EFP[] ROUNDED_PI = {
  2244:     //  echo read("efp.gp");for(rm=RN,RP,efpmem([Pi,rm,strrmf(rm,"π")])) | gp -q
  2245:     new EFP (P,      1, 0xc90fdaa22168c234L, 0xc4c6629L << 36),  //>RN(π)=3.14159265358979323846264338328
  2246:     new EFP (P,      1, 0xc90fdaa22168c234L, 0xc4c6628L << 36),  //<RZ(π)=3.14159265358979323846264338328
  2247:     new EFP (P,      1, 0xc90fdaa22168c234L, 0xc4c6628L << 36),  //<RM(π)=3.14159265358979323846264338328
  2248:     new EFP (P,      1, 0xc90fdaa22168c234L, 0xc4c6629L << 36),  //>RP(π)=3.14159265358979323846264338328
  2249:   };
  2250:   public final EFP[] ROUNDED_NEGPI = {
  2251:     //  echo read("efp.gp");for(rm=RN,RP,efpmem([-Pi,rm,strrmf(rm,"-π")])) | gp -q
  2252:     new EFP (M,      1, 0xc90fdaa22168c234L, 0xc4c6629L << 36),  //<RN(-π)=-3.14159265358979323846264338328
  2253:     new EFP (M,      1, 0xc90fdaa22168c234L, 0xc4c6628L << 36),  //>RZ(-π)=-3.14159265358979323846264338328
  2254:     new EFP (M,      1, 0xc90fdaa22168c234L, 0xc4c6629L << 36),  //<RM(-π)=-3.14159265358979323846264338328
  2255:     new EFP (M,      1, 0xc90fdaa22168c234L, 0xc4c6628L << 36),  //>RP(-π)=-3.14159265358979323846264338328
  2256:   };
  2257:   public final EFP[] ROUNDED_PI_2 = {
  2258:     //  echo read("efp.gp");for(rm=RN,RP,efpmem([Pi/2,rm,strrmf(rm,"π/2")])) | gp -q
  2259:     new EFP (P,      0, 0xc90fdaa22168c234L, 0xc4c6629L << 36),  //>RN(π/2)=1.57079632679489661923132169164
  2260:     new EFP (P,      0, 0xc90fdaa22168c234L, 0xc4c6628L << 36),  //<RZ(π/2)=1.57079632679489661923132169164
  2261:     new EFP (P,      0, 0xc90fdaa22168c234L, 0xc4c6628L << 36),  //<RM(π/2)=1.57079632679489661923132169164
  2262:     new EFP (P,      0, 0xc90fdaa22168c234L, 0xc4c6629L << 36),  //>RP(π/2)=1.57079632679489661923132169164
  2263:   };
  2264:   public final EFP[] ROUNDED_NEGPI_2 = {
  2265:     //  echo read("efp.gp");for(rm=RN,RP,efpmem([-Pi/2,rm,strrmf(rm,"-π/2")])) | gp -q
  2266:     new EFP (M,      0, 0xc90fdaa22168c234L, 0xc4c6629L << 36),  //<RN(-π/2)=-1.57079632679489661923132169164
  2267:     new EFP (M,      0, 0xc90fdaa22168c234L, 0xc4c6628L << 36),  //>RZ(-π/2)=-1.57079632679489661923132169164
  2268:     new EFP (M,      0, 0xc90fdaa22168c234L, 0xc4c6629L << 36),  //<RM(-π/2)=-1.57079632679489661923132169164
  2269:     new EFP (M,      0, 0xc90fdaa22168c234L, 0xc4c6628L << 36),  //>RP(-π/2)=-1.57079632679489661923132169164
  2270:   };
  2271: 
  2272:   //------------------------------------------------------------------------
  2273:   //sinh
  2274:   //  echo read("efp.gp");efpchebyshev("SINH_C",sinh,-1/8,1/8,13) | gp -q
  2275:   public final EFP      SINH_C1 = new EFP (P,      0, 0x8000000000000000L, 0x0000000L << 36);  //=1.00000000000000000000000000000
  2276:   public final EFP      SINH_C3 = new EFP (P,     -3, 0xaaaaaaaaaaaaaaaaL, 0xaaa8d3bL << 36);  //=0.166666666666666666666666286213
  2277:   public final EFP      SINH_C5 = new EFP (P,     -7, 0x8888888888888888L, 0xd801ef0L << 36);  //=0.00833333333333333333359629146849
  2278:   public final EFP      SINH_C7 = new EFP (P,    -13, 0xd00d00d00d00b865L, 0xe08a011L << 36);  //=1.98412698412698332559486447243e-4
  2279:   public final EFP      SINH_C9 = new EFP (P,    -19, 0xb8ef1d2ab9d6b01dL, 0x54d1cf9L << 36);  //=2.75573192241112619181294637312e-6
  2280:   public final EFP     SINH_C11 = new EFP (P,    -26, 0xd7322aa84ab102a5L, 0xf1b3e2aL << 36);  //=2.50521073350812546986376674718e-8
  2281:   public final EFP     SINH_C13 = new EFP (P,    -33, 0xb09ecdc339d62e71L, 0x8115862L << 36);  //=1.60635251803005018933289429222e-10
  2282:   //  92.06bit
  2283: 
  2284:   //------------------------------------------------------------------------
  2285:   //sqrt1pm1
  2286:   //  echo read("efp.gp");eval("sqrt1pm1(x)=sqrt(1+x)-1");efppoly("SQRT1PM1_C",sqrt1pm1,sum(n=1,11,eval("efp((-1)^(n-1)/2^(2*n-1)*factorial(2*n-2)/factorial(n-1)/factorial(n))*x^n")),-1/256,1/256) | gp -q
  2287:   public final EFP  SQRT1PM1_C1 = new EFP (P,     -1, 0x8000000000000000L, 0x0000000L << 36);  //=0.500000000000000000000000000000
  2288:   public final EFP  SQRT1PM1_C2 = new EFP (M,     -3, 0x8000000000000000L, 0x0000000L << 36);  //=-0.125000000000000000000000000000
  2289:   public final EFP  SQRT1PM1_C3 = new EFP (P,     -4, 0x8000000000000000L, 0x0000000L << 36);  //=0.0625000000000000000000000000000
  2290:   public final EFP  SQRT1PM1_C4 = new EFP (M,     -5, 0xa000000000000000L, 0x0000000L << 36);  //=-0.0390625000000000000000000000000
  2291:   public final EFP  SQRT1PM1_C5 = new EFP (P,     -6, 0xe000000000000000L, 0x0000000L << 36);  //=0.0273437500000000000000000000000
  2292:   public final EFP  SQRT1PM1_C6 = new EFP (M,     -6, 0xa800000000000000L, 0x0000000L << 36);  //=-0.0205078125000000000000000000000
  2293:   public final EFP  SQRT1PM1_C7 = new EFP (P,     -6, 0x8400000000000000L, 0x0000000L << 36);  //=0.0161132812500000000000000000000
  2294:   public final EFP  SQRT1PM1_C8 = new EFP (M,     -7, 0xd680000000000000L, 0x0000000L << 36);  //=-0.0130920410156250000000000000000
  2295:   public final EFP  SQRT1PM1_C9 = new EFP (P,     -7, 0xb2c0000000000000L, 0x0000000L << 36);  //=0.0109100341796875000000000000000
  2296:   public final EFP SQRT1PM1_C10 = new EFP (M,     -7, 0x97f0000000000000L, 0x0000000L << 36);  //=-0.00927352905273437500000000000000
  2297:   public final EFP SQRT1PM1_C11 = new EFP (P,     -7, 0x8338000000000000L, 0x0000000L << 36);  //=0.00800895690917968750000000000000
  2298:   //  94.15bit
  2299: 
  2300:   //------------------------------------------------------------------------
  2301:   //tan
  2302:   //  echo read("efp.gp");efpchebyshev("TAN_C",tan,-Pi/8,Pi/8,33) | gp -q
  2303:   public final EFP       TAN_C1 = new EFP (P,      0, 0x8000000000000000L, 0x0000000L << 36);  //=1.00000000000000000000000000000
  2304:   public final EFP       TAN_C3 = new EFP (P,     -2, 0xaaaaaaaaaaaaaaaaL, 0xaaaaa29L << 36);  //=0.333333333333333333333333320240
  2305:   public final EFP       TAN_C5 = new EFP (P,     -3, 0x8888888888888888L, 0x88a184aL << 36);  //=0.133333333333333333333338500055
  2306:   public final EFP       TAN_C7 = new EFP (P,     -5, 0xdd0dd0dd0dd0dd0dL, 0x88b7614L << 36);  //=0.0539682539682539682530133941980
  2307:   public final EFP       TAN_C9 = new EFP (P,     -6, 0xb327a4416087cfd4L, 0xf296a40L << 36);  //=0.0218694885361552029227142001132
  2308:   public final EFP      TAN_C11 = new EFP (P,     -7, 0x91371aaf3611c538L, 0x2426582L << 36);  //=0.00886323552990218979030206294531
  2309:   public final EFP      TAN_C13 = new EFP (P,     -9, 0xeb69e870ac055209L, 0xe907d72L << 36);  //=0.00359212803657279090096708386671
  2310:   public final EFP      TAN_C15 = new EFP (P,    -10, 0xbed1b229560565dcL, 0x00f1ae8L << 36);  //=0.00145583438704125904461672464275
  2311:   public final EFP      TAN_C17 = new EFP (P,    -11, 0x9aac124127c7ff13L, 0xd521318L << 36);  //=5.90027441184109978354508200940e-4
  2312:   public final EFP      TAN_C19 = new EFP (P,    -13, 0xfabebb506d37becdL, 0x7712cf3L << 36);  //=2.39129110038142690434570082910e-4
  2313:   public final EFP      TAN_C21 = new EFP (P,    -14, 0xcb3f13fd9e491aeeL, 0xb4ecd04L << 36);  //=9.69154352110963087881307906904e-5
  2314:   public final EFP      TAN_C23 = new EFP (P,    -15, 0xa4be2f633cfa3709L, 0x2c90e93L << 36);  //=3.92777706570966668331421947349e-5
  2315:   public final EFP      TAN_C25 = new EFP (P,    -16, 0x859266daac37850cL, 0xcb7028bL << 36);  //=1.59230091488831402827144234198e-5
  2316:   public final EFP      TAN_C27 = new EFP (P,    -18, 0xd7bbef57337218a7L, 0x4e73cafL << 36);  //=6.42937781805301206613497744639e-6
  2317:   public final EFP      TAN_C29 = new EFP (P,    -19, 0xb53ca49c91cc2ce0L, 0x289f9c2L << 36);  //=2.70064006408567688822953124006e-6
  2318:   public final EFP      TAN_C31 = new EFP (P,    -21, 0xe1a12ebdc4e0aba8L, 0x6c3a02cL << 36);  //=8.40535832440159769242845888336e-7
  2319:   public final EFP      TAN_C33 = new EFP (P,    -21, 0xc9eb997dffc9ad78L, 0x01e7a8fL << 36);  //=7.52211775090032809509059318805e-7
  2320:   //  96.07bit
  2321:   //  echo read("efp.gp");efpchebyshev("TAN7_C",tan,-Pi/256,Pi/256,11) | gp -q
  2322:   public final EFP      TAN7_C1 = new EFP (P,     -1, 0xffffffffffffffffL, 0xfffffffL << 36);  //=0.999999999999999999999999999798
  2323:   public final EFP      TAN7_C3 = new EFP (P,     -2, 0xaaaaaaaaaaaaaaaaL, 0xaae677dL << 36);  //=0.333333333333333333333358066592
  2324:   public final EFP      TAN7_C5 = new EFP (P,     -3, 0x8888888888888827L, 0x9679788L << 36);  //=0.133333333333333332019476238145
  2325:   public final EFP      TAN7_C7 = new EFP (P,     -5, 0xdd0dd0dd0e579281L, 0x2b6ed88L << 36);  //=0.0539682539682838796143366171397
  2326:   public final EFP      TAN7_C9 = new EFP (P,     -6, 0xb327a413e1bf5c5dL, 0x5ebd854L << 36);  //=0.0218694882051337203598644737927
  2327:   public final EFP     TAN7_C11 = new EFP (P,     -7, 0x913e7ab6529ea4edL, 0x6ea7f3bL << 36);  //=0.00886499389279463946555596271447
  2328:   //  92.00bit
  2329:   public final EFP[] TAN7_T = {
  2330:     //  echo read("efp.gp");for(n=0,63,efpmem([Str("tan(",n,"*Pi/128)")])) | gp -q
  2331:     new EFP (),  //=tan(0*Pi/128)=0.00000000000000000000000000000
  2332:     new EFP (P,     -6, 0xc91a3123d48f7fddL, 0x894dd4bL << 36),  //>tan(1*Pi/128)=0.0245486221089254441045797539609
  2333:     new EFP (P,     -5, 0xc9393c51d88b101aL, 0xda13cefL << 36),  //>tan(2*Pi/128)=0.0491268497694672541053433212713
  2334:     new EFP (P,     -4, 0x9711ce67f9c18b0fL, 0x459611fL << 36),  //<tan(3*Pi/128)=0.0737644315224492888923977217788
  2335:     new EFP (P,     -4, 0xc9b5dc62d96d130fL, 0xa0a9ed1L << 36),  //<tan(4*Pi/128)=0.0984914033571642530771975212913
  2336:     new EFP (P,     -4, 0xfc98c1d46dcf46edL, 0xdf92d54L << 36),  //>tan(5*Pi/128)=0.123338236136738677947004130613
  2337:     new EFP (P,     -3, 0x97e5639d3032012cL, 0xfb5a747L << 36),  //>tan(6*Pi/128)=0.148335987538347428753676511487
  2338:     new EFP (P,     -3, 0xb1ae4c867069ae62L, 0x1454a67L << 36),  //<tan(7*Pi/128)=0.173516460137855760223211669841
  2339:     new EFP (P,     -3, 0xcbafaf02a98ac03dL, 0xeba6ce9L << 36),  //>tan(8*Pi/128)=0.198912367379658006911597622645
  2340:     new EFP (P,     -3, 0xe5f2675a5a679294L, 0xb7c658cL << 36),  //<tan(9*Pi/128)=0.224557509317129320242538359449
  2341:     new EFP (P,     -2, 0x803fd3ac3135715aL, 0x6d6c3c9L << 36),  //>tan(10*Pi/128)=0.250486960191305461595702160125
  2342:     new EFP (P,     -2, 0x8db081e9acbf49cbL, 0xda4f636L << 36),  //<tan(11*Pi/128)=0.276737270140414338944617036500
  2343:     new EFP (P,     -2, 0x9b5041aae31ede28L, 0xfb2e402L << 36),  //<tan(12*Pi/128)=0.303346683607342391675883946941
  2344:     new EFP (P,     -2, 0xa924570b80d8bb7dL, 0x2ec70f1L << 36),  //>tan(13*Pi/128)=0.330355377344333924545492908196
  2345:     new EFP (P,     -2, 0xb7324fbebc324978L, 0xe945dc4L << 36),  //>tan(14*Pi/128)=0.357805721314524104672487743774
  2346:     new EFP (P,     -2, 0xc5800cb59e810e8cL, 0xd859b1fL << 36),  //>tan(15*Pi/128)=0.385742566271121235453424624094
  2347:     new EFP (P,     -2, 0xd413cccfe7799211L, 0x65f626dL << 36),  //>tan(16*Pi/128)=0.414213562373095048801688724210
  2348:     new EFP (P,     -2, 0xe2f438c2f33db07fL, 0xd5fe854L << 36),  //>tan(17*Pi/128)=0.443269513890864334105794704813
  2349:     new EFP (P,     -2, 0xf228706939f3d282L, 0xa45e2bdL << 36),  //>tan(18*Pi/128)=0.472964775891319928124438237973
  2350:     new EFP (P,     -1, 0x80dc0cdad3e7ba17L, 0xf9dd77dL << 36),  //<tan(19*Pi/128)=0.503357699799294262733245622354
  2351:     new EFP (P,     -1, 0x88d5b8c841a75c35L, 0x36865c3L << 36),  //<tan(20*Pi/128)=0.534511135950791641089685961295
  2352:     new EFP (P,     -1, 0x9105af7823c1286bL, 0xb5bee4cL << 36),  //<tan(21*Pi/128)=0.566493002730343981076271533491
  2353:     new EFP (P,     -1, 0x9970c44823ffe5deL, 0x977bc33L << 36),  //>tan(22*Pi/128)=0.599376933681923766271389869014
  2354:     new EFP (P,     -1, 0xa21c36dce72ed4b0L, 0x5750623L << 36),  //<tan(23*Pi/128)=0.633243016177569127534323438301
  2355:     new EFP (P,     -1, 0xab0dc155bfcc82f5L, 0x18a42e5L << 36),  //<tan(24*Pi/128)=0.668178637919298919997757686523
  2356:     new EFP (P,     -1, 0xb44ba8a3a8edb143L, 0x9bc2d44L << 36),  //>tan(25*Pi/128)=0.704279460865044244278980120940
  2357:     new EFP (P,     -1, 0xbddccf694c8674abL, 0x158e376L << 36),  //<tan(26*Pi/128)=0.741650546272035369581266691172
  2358:     new EFP (P,     -1, 0xc7c8cbdfc2f75687L, 0x408e56bL << 36),  //>tan(27*Pi/128)=0.780407659653943632354200451174
  2359:     new EFP (P,     -1, 0xd218015721427e59L, 0x247f018L << 36),  //<tan(28*Pi/128)=0.820678790828660330972281985331
  2360:     new EFP (P,     -1, 0xdcd3be0c60d7916fL, 0xc7e578dL << 36),  //<tan(29*Pi/128)=0.862605932256739891215212659727
  2361:     new EFP (P,     -1, 0xe8065e39c269718dL, 0xcad85e6L << 36),  //<tan(30*Pi/128)=0.906347169019147157946142717269
  2362:     new EFP (P,     -1, 0xf3bb757e48b83322L, 0xbd576feL << 36),  //<tan(31*Pi/128)=0.952079146700925348585664892261
  2363:     new EFP (P,      0, 0x8000000000000000L, 0x0000000L << 36),  //=tan(32*Pi/128)=1.00000000000000000000000000000
  2364:     new EFP (P,      0, 0x86714e8441e4ca93L, 0x0c4cf4eL << 36),  //<tan(33*Pi/128)=1.05033284623985985679635153480
  2365:     new EFP (P,      0, 0x8d39eaa93c625b28L, 0xd9816cdL << 36),  //<tan(34*Pi/128)=1.10332997573347566410053775985
  2366:     new EFP (P,      0, 0x946337ed7c784903L, 0x22c9598L << 36),  //<tan(35*Pi/128)=1.15927790733343474872256568270
  2367:     new EFP (P,      0, 0x9bf7ec6c3b03ef3cL, 0x0d29346L << 36),  //<tan(36*Pi/128)=1.21850352558797634479547723062
  2368:     new EFP (P,      0, 0xa4044fc5fa1663f0L, 0xd6fd49aL << 36),  //>tan(37*Pi/128)=1.28138158003655455554560477142
  2369:     new EFP (P,      0, 0xac96888a17d2a96aL, 0x085e3bcL << 36),  //<tan(38*Pi/128)=1.34834391348672015293303458505
  2370:     new EFP (P,      0, 0xb5befc31328ffd5eL, 0x4284584L << 36),  //>tan(39*Pi/128)=1.41989090349409245362395560849
  2371:     new EFP (P,      0, 0xbf90c712d3a30a83L, 0x3f4d2a9L << 36),  //<tan(40*Pi/128)=1.49660576266548901760113513494
  2372:     new EFP (P,      0, 0xca2253a310915399L, 0x7dd7470L << 36),  //<tan(41*Pi/128)=1.57917256796020898378319991425
  2373:     new EFP (P,      0, 0xd58e1aec53a74f24L, 0x82443ddL << 36),  //>tan(42*Pi/128)=1.66839920558350704845076179161
  2374:     new EFP (P,      0, 0xe1f39c0435e07a14L, 0x725b359L << 36),  //>tan(43*Pi/128)=1.76524687009419151361905127152
  2375:     new EFP (P,      0, 0xef789db9e0a0310fL, 0xb3e75c7L << 36),  //<tan(44*Pi/128)=1.87086841178938948108520133434
  2376:     new EFP (P,      0, 0xfe4ad5d6b67a51b7L, 0x127cf35L << 36),  //>tan(45*Pi/128)=1.98665879234336500189577900470
  2377:     new EFP (P,      1, 0x87510eb8b7dfb97cL, 0xe6cb464L << 36),  //>tan(46*Pi/128)=2.11432235754864059006900220864
  2378:     new EFP (P,      1, 0x9061b6353f9c6ed6L, 0xe02bffdL << 36),  //<tan(47*Pi/128)=2.25596385192915864999808013935
  2379:     new EFP (P,      1, 0x9a827999fcef3242L, 0x2cbec4eL << 36),  //>tan(48*Pi/128)=2.41421356237309504880168872421
  2380:     new EFP (P,      1, 0xa5e9ec3ff0327cfaL, 0x748ca31L << 36),  //<tan(49*Pi/128)=2.59240251773807256365450014380
  2381:     new EFP (P,      1, 0xb2de3664128a386bL, 0x2a51effL << 36),  //>tan(50*Pi/128)=2.79481277249047679426344220502
  2382:     new EFP (P,      1, 0xc1bb136b87edc0d9L, 0xae371daL << 36),  //<tan(51*Pi/128)=3.02704320431777423041156207831
  2383:     new EFP (P,      1, 0xd2facf483006e648L, 0x5eb2f29L << 36),  //<tan(52*Pi/128)=3.29655820893832042687815421683
  2384:     new EFP (P,      1, 0xe7442b29893f385dL, 0xfd8e2a3L << 36),  //<tan(53*Pi/128)=3.61353568130742843584614061971
  2385:     new EFP (P,      1, 0xff80982f66c6df3bL, 0x0194e40L << 36),  //<tan(54*Pi/128)=3.99222378377008442376610482881
  2386:     new EFP (P,      2, 0x8e80a1f38ab2f611L, 0x8c89790L << 36),  //<tan(55*Pi/128)=4.45320222441441050038054277672
  2387:     new EFP (P,      2, 0xa0dff712123b8844L, 0x1c1bfb5L << 36),  //>tan(56*Pi/128)=5.02733949212584810451497507106
  2388:     new EFP (P,      2, 0xb86ba8c8460d85deL, 0x3af4952L << 36),  //<tan(57*Pi/128)=5.76314200511880934875009607987
  2389:     new EFP (P,      2, 0xd7b9fa6519887651L, 0xc68dc64L << 36),  //>tan(58*Pi/128)=6.74145240541498828250998494514
  2390:     new EFP (P,      3, 0x81b97d9b5c3f0e2bL, 0x5c8997bL << 36),  //>tan(59*Pi/128)=8.10778580367690752547921378823
  2391:     new EFP (P,      3, 0xa27362cad7ee626aL, 0x3b5d4f3L << 36),  //>tan(60*Pi/128)=10.1531703876088604621071476634
  2392:     new EFP (P,      3, 0xd8e81e01e97bf967L, 0xe518f26L << 36),  //>tan(61*Pi/128)=13.5566692423524258539123676121
  2393:     new EFP (P,      4, 0xa2d7ff6900daa7f2L, 0x48ca591L << 36),  //>tan(62*Pi/128)=20.3554676249871881783196386481
  2394:     new EFP (P,      5, 0xa2f122af255539e2L, 0x447b82dL << 36),  //>tan(63*Pi/128)=40.7354838720833018007438570502
  2395:   };  //TAN7_T
  2396:   //  echo read("efp.gp");efppub(["TAN7_X",Pi/256],["TAN7_Y",128/Pi]) | gp -q
  2397:   public final EFP       TAN7_X = new EFP (P,     -7, 0xc90fdaa22168c234L, 0xc4c6629L << 36);  //>0.0122718463030851298377447007159
  2398:   public final EFP       TAN7_Y = new EFP (P,      5, 0xa2f9836e4e441529L, 0xfc2757dL << 36);  //<40.7436654315252059568342434234
  2399:   //  echo read("efp.gp");efppub2(["TAN7_Z",Pi/128]) | gp -q
  2400:   public final EFP       TAN7_Z = new EFP (P,     -6, 0xc90fdaa22168c234L, 0xc4c6629L << 36);  //>0.0245436926061702596754894014319
  2401:   public final EFP      TAN7_ZA = new EFP (M,    -99, 0x8fe47c65dadfb63eL, 0xeeb3067L << 36);  //>-1.77361228242534392160702072478e-30
  2402:   //  echo read("efp.gp");efpchebyshev("TAN8_C",tan,-1/8,1/8,21) | gp -q
  2403:   public final EFP      TAN8_C1 = new EFP (P,      0, 0x8000000000000000L, 0x0000000L << 36);  //=1.00000000000000000000000000000
  2404:   public final EFP      TAN8_C3 = new EFP (P,     -2, 0xaaaaaaaaaaaaaaaaL, 0xaaaaa02L << 36);  //=0.333333333333333333333333316302
  2405:   public final EFP      TAN8_C5 = new EFP (P,     -3, 0x8888888888888888L, 0x8911d7aL << 36);  //=0.133333333333333333333361728159
  2406:   public final EFP      TAN8_C7 = new EFP (P,     -5, 0xdd0dd0dd0dd0dd07L, 0x61e9558L << 36);  //=0.0539682539682539682321710253282
  2407:   public final EFP      TAN8_C9 = new EFP (P,     -6, 0xb327a4416087e508L, 0x1c05687L << 36);  //=0.0218694885361552121166839881208
  2408:   public final EFP     TAN8_C11 = new EFP (P,     -7, 0x91371aaf35e647d2L, 0x9bd741cL << 36);  //=0.00886323552989977561974347061451
  2409:   public final EFP     TAN8_C13 = new EFP (P,     -9, 0xeb69e8711de22b89L, 0x087ca38L << 36);  //=0.00359212803697731245050214719004
  2410:   public final EFP     TAN8_C15 = new EFP (P,    -10, 0xbed1b1c7d2310830L, 0x871a5a7L << 36);  //=0.00145583434269658967823487137542
  2411:   public final EFP     TAN8_C17 = new EFP (P,    -11, 0x9aac48a4e5208639L, 0x1e07899L << 36);  //=5.90030607075966038694572991909e-4
  2412:   public final EFP     TAN8_C19 = new EFP (P,    -13, 0xfa98b158590773f4L, 0xfa72a4eL << 36);  //=2.38987403937913425869285486804e-4
  2413:   public final EFP     TAN8_C21 = new EFP (P,    -14, 0xd2cd5a371c03b30eL, 0x42cac1cL << 36);  //=1.00518301880738120215681257530e-4
  2414:   //  97.78bit
  2415: 
  2416:   //------------------------------------------------------------------------
  2417:   //tanh
  2418:   //  echo read("efp.gp");efpchebyshev("TANH_C",tanh,-1/4,1/4,27) | gp -q
  2419:   public final EFP      TANH_C1 = new EFP (P,      0, 0x8000000000000000L, 0x0000000L << 36);  //=1.00000000000000000000000000000
  2420:   public final EFP      TANH_C3 = new EFP (M,     -2, 0xaaaaaaaaaaaaaaaaL, 0xaaaaa63L << 36);  //=-0.333333333333333333333333326097
  2421:   public final EFP      TANH_C5 = new EFP (P,     -3, 0x8888888888888888L, 0x88710efL << 36);  //=0.133333333333333333333328478820
  2422:   public final EFP      TANH_C7 = new EFP (M,     -5, 0xdd0dd0dd0dd0dd0dL, 0x5eb1c0fL << 36);  //=-0.0539682539682539682524572379576
  2423:   public final EFP      TANH_C9 = new EFP (P,     -6, 0xb327a4416087cefcL, 0x3226807L << 36);  //=0.0218694885361552025555225187555
  2424:   public final EFP     TANH_C11 = new EFP (M,     -7, 0x91371aaf36115c72L, 0x1057753L << 36);  //=-0.00886323552990216707111881201890
  2425:   public final EFP     TANH_C13 = new EFP (P,     -9, 0xeb69e870ab51ac87L, 0xbc93275L << 36);  //=0.00359212803657029780471621830554
  2426:   public final EFP     TANH_C15 = new EFP (M,    -10, 0xbed1b2291c9448e3L, 0x025162cL << 36);  //=-0.00145583438693922182445491583494
  2427:   public final EFP     TANH_C17 = new EFP (P,    -11, 0x9aac122e2d563679L, 0x7f53bd9L << 36);  //=5.90027436868944449269862181218e-4
  2428:   public final EFP     TANH_C19 = new EFP (M,    -13, 0xfabeb45554b7f61dL, 0xed9a4e5L << 36);  //=-2.39129008453513280762151644074e-4
  2429:   public final EFP     TANH_C21 = new EFP (P,    -14, 0xcb3e00a83f1f1703L, 0x594e12fL << 36);  //=9.69134318963417667915644434482e-5
  2430:   public final EFP     TANH_C23 = new EFP (M,    -15, 0xa4a40e3c50e76340L, 0x922c2ccL << 36);  //=-3.92534356637388369814427537735e-5
  2431:   public final EFP     TANH_C25 = new EFP (P,    -16, 0x83c53e40035eb57fL, 0x80a5513L << 36);  //=1.57082654369358742080398893111e-5
  2432:   public final EFP     TANH_C27 = new EFP (M,    -18, 0xb47b24ce1d988d76L, 0xa0271b7L << 36);  //=-5.37875385140937293082445934922e-6
  2433:   //  97.70bit
  2434: 
  2435:   //------------------------------------------------------------------------
  2436:   //toString
  2437:   public final EFP[] EFP_TEN_P16QR = {
  2438:     //  echo read("efp.gp");for(i=0,50,q=eval("i>>4");r=bitand(i,15);efpmem([Str("10^(16^",q,"*",r,")")])) | gp -q
  2439:     new EFP (P,      0, 0x8000000000000000L, 0x0000000L << 36),  //=10^(16^0*0)=1.00000000000000000000000000000
  2440:     new EFP (P,      3, 0xa000000000000000L, 0x0000000L << 36),  //=10^(16^0*1)=10.0000000000000000000000000000
  2441:     new EFP (P,      6, 0xc800000000000000L, 0x0000000L << 36),  //=10^(16^0*2)=100.000000000000000000000000000
  2442:     new EFP (P,      9, 0xfa00000000000000L, 0x0000000L << 36),  //=10^(16^0*3)=1000.00000000000000000000000000
  2443:     new EFP (P,     13, 0x9c40000000000000L, 0x0000000L << 36),  //=10^(16^0*4)=10000.0000000000000000000000000
  2444:     new EFP (P,     16, 0xc350000000000000L, 0x0000000L << 36),  //=10^(16^0*5)=100000.000000000000000000000000
  2445:     new EFP (P,     19, 0xf424000000000000L, 0x0000000L << 36),  //=10^(16^0*6)=1000000.00000000000000000000000
  2446:     new EFP (P,     23, 0x9896800000000000L, 0x0000000L << 36),  //=10^(16^0*7)=10000000.0000000000000000000000
  2447:     new EFP (P,     26, 0xbebc200000000000L, 0x0000000L << 36),  //=10^(16^0*8)=100000000.000000000000000000000
  2448:     new EFP (P,     29, 0xee6b280000000000L, 0x0000000L << 36),  //=10^(16^0*9)=1000000000.00000000000000000000
  2449:     new EFP (P,     33, 0x9502f90000000000L, 0x0000000L << 36),  //=10^(16^0*10)=10000000000.0000000000000000000
  2450:     new EFP (P,     36, 0xba43b74000000000L, 0x0000000L << 36),  //=10^(16^0*11)=100000000000.000000000000000000
  2451:     new EFP (P,     39, 0xe8d4a51000000000L, 0x0000000L << 36),  //=10^(16^0*12)=1000000000000.00000000000000000
  2452:     new EFP (P,     43, 0x9184e72a00000000L, 0x0000000L << 36),  //=10^(16^0*13)=10000000000000.0000000000000000
  2453:     new EFP (P,     46, 0xb5e620f480000000L, 0x0000000L << 36),  //=10^(16^0*14)=100000000000000.000000000000000
  2454:     new EFP (P,     49, 0xe35fa931a0000000L, 0x0000000L << 36),  //=10^(16^0*15)=1000000000000000.00000000000000
  2455:     new EFP (P,      0, 0x8000000000000000L, 0x0000000L << 36),  //=10^(16^1*0)=1.00000000000000000000000000000
  2456:     new EFP (P,     53, 0x8e1bc9bf04000000L, 0x0000000L << 36),  //=10^(16^1*1)=10000000000000000.0000000000000
  2457:     new EFP (P,    106, 0x9dc5ada82b70b59dL, 0xf020000L << 36),  //=10^(16^1*2)=1.00000000000000000000000000000e+32
  2458:     new EFP (P,    159, 0xaf298d050e4395d6L, 0x9670b13L << 36),  //>10^(16^1*3)=1.00000000000000000000000000000e+48
  2459:     new EFP (P,    212, 0xc2781f49ffcfa6d5L, 0x3cbf6b7L << 36),  //<10^(16^1*4)=1.00000000000000000000000000000e+64
  2460:     new EFP (P,    265, 0xd7e77a8f87daf7fbL, 0xdc33746L << 36),  //>10^(16^1*5)=1.00000000000000000000000000000e+80
  2461:     new EFP (P,    318, 0xefb3ab16c59b14a2L, 0xc5cfe95L << 36),  //>10^(16^1*6)=1.00000000000000000000000000000e+96
  2462:     new EFP (P,    372, 0x850fadc09923329eL, 0x03e2cf7L << 36),  //>10^(16^1*7)=1.00000000000000000000000000000e+112
  2463:     new EFP (P,    425, 0x93ba47c980e98cdfL, 0xc66f337L << 36),  //>10^(16^1*8)=1.00000000000000000000000000000e+128
  2464:     new EFP (P,    478, 0xa402b9c5a8d3a6e7L, 0x5f16207L << 36),  //>10^(16^1*9)=1.00000000000000000000000000000e+144
  2465:     new EFP (P,    531, 0xb616a12b7fe617aaL, 0x577b987L << 36),  //>10^(16^1*10)=1.00000000000000000000000000000e+160
  2466:     new EFP (P,    584, 0xca28a291859bbf93L, 0x7d7b8f7L << 36),  //<10^(16^1*11)=1.00000000000000000000000000000e+176
  2467:     new EFP (P,    637, 0xe070f78d3927556aL, 0x85bbe25L << 36),  //<10^(16^1*12)=1.00000000000000000000000000000e+192
  2468:     new EFP (P,    690, 0xf92e0c3537826145L, 0xa7709a5L << 36),  //<10^(16^1*13)=1.00000000000000000000000000000e+208
  2469:     new EFP (P,    744, 0x8a5296ffe33cc92fL, 0x82bd6b7L << 36),  //<10^(16^1*14)=1.00000000000000000000000000000e+224
  2470:     new EFP (P,    797, 0x9991a6f3d6bf1765L, 0xacca6daL << 36),  //<10^(16^1*15)=1.00000000000000000000000000000e+240
  2471:     new EFP (P,      0, 0x8000000000000000L, 0x0000000L << 36),  //=10^(16^2*0)=1.00000000000000000000000000000
  2472:     new EFP (P,    850, 0xaa7eebfb9df9de8dL, 0xddbb902L << 36),  //>10^(16^2*1)=1.00000000000000000000000000000e+256
  2473:     new EFP (P,   1700, 0xe319a0aea60e91c6L, 0xcc655c5L << 36),  //<10^(16^2*2)=1.00000000000000000000000000000e+512
  2474:     new EFP (P,   2551, 0x973f9ca8cd00a68cL, 0x6c8d3fdL << 36),  //>10^(16^2*3)=1.00000000000000000000000000000e+768
  2475:     new EFP (P,   3401, 0xc976758681750c17L, 0x650d3d3L << 36),  //>10^(16^2*4)=1.00000000000000000000000000000e+1024
  2476:     new EFP (P,   4252, 0x862c8c0eeb856ecbL, 0x085bccdL << 36),  //<10^(16^2*5)=1.00000000000000000000000000000e+1280
  2477:     new EFP (P,   5102, 0xb2b8353b3993a7e4L, 0x4257ac4L << 36),  //>10^(16^2*6)=1.00000000000000000000000000000e+1536
  2478:     new EFP (P,   5952, 0xee0ddd84924ab88cL, 0x2d4070fL << 36),  //<10^(16^2*7)=1.00000000000000000000000000000e+1792
  2479:     new EFP (P,   6803, 0x9e8b3b5dc53d5de4L, 0xa74d28dL << 36),  //>10^(16^2*8)=1.00000000000000000000000000000e+2048
  2480:     new EFP (P,   7653, 0xd32e203241f4806fL, 0x3f50c80L << 36),  //<10^(16^2*9)=1.00000000000000000000000000000e+2304
  2481:     new EFP (P,   8504, 0x8ca554c020a1f0a6L, 0x5dfed0aL << 36),  //>10^(16^2*10)=1.00000000000000000000000000000e+2560
  2482:     new EFP (P,   9354, 0xbb570a9a9bd977ccL, 0x4c80875L << 36),  //<10^(16^2*11)=1.00000000000000000000000000000e+2816
  2483:     new EFP (P,  10204, 0xf9895d25d88b5a8aL, 0xfdd08c5L << 36),  //>10^(16^2*12)=1.00000000000000000000000000000e+3072
  2484:     new EFP (P,  11055, 0xa630ef7d5699fe45L, 0x50e3660L << 36),  //<10^(16^2*13)=1.00000000000000000000000000000e+3328
  2485:     new EFP (P,  11905, 0xdd5dc8a2bf27f3f7L, 0x95aa119L << 36),  //>10^(16^2*14)=1.00000000000000000000000000000e+3584
  2486:     new EFP (P,  12756, 0x936e07737dc64f6dL, 0x8c474bbL << 36),  //<10^(16^2*15)=1.00000000000000000000000000000e+3840
  2487:     new EFP (P,      0, 0x8000000000000000L, 0x0000000L << 36),  //=10^(16^3*0)=1.00000000000000000000000000000
  2488:     new EFP (P,  13606, 0xc46052028a20979aL, 0xc94c154L << 36),  //>10^(16^3*1)=1.00000000000000000000000000000e+4096
  2489:     new EFP (P,  27213, 0x96a3a1d17faf211aL, 0x0c7c289L << 36),  //<10^(16^3*2)=1.00000000000000000000000000000e+8192
  2490:   };
  2491:   public final EFP[] EFP_TEN_M16QR = {
  2492:     //  echo read("efp.gp");for(i=0,50,q=eval("i>>4");r=bitand(i,15);efpmem([Str("10^(-16^",q,"*",r,")")])) | gp -q
  2493:     new EFP (P,      0, 0x8000000000000000L, 0x0000000L << 36),  //=10^(-16^0*0)=1.00000000000000000000000000000
  2494:     new EFP (P,     -4, 0xccccccccccccccccL, 0xccccccdL << 36),  //>10^(-16^0*1)=0.100000000000000000000000000000
  2495:     new EFP (P,     -7, 0xa3d70a3d70a3d70aL, 0x3d70a3dL << 36),  //<10^(-16^0*2)=0.0100000000000000000000000000000
  2496:     new EFP (P,    -10, 0x83126e978d4fdf3bL, 0x645a1cbL << 36),  //>10^(-16^0*3)=0.00100000000000000000000000000000
  2497:     new EFP (P,    -14, 0xd1b71758e219652bL, 0xd3c3611L << 36),  //<10^(-16^0*4)=1.00000000000000000000000000000e-4
  2498:     new EFP (P,    -17, 0xa7c5ac471b478423L, 0x0fcf80eL << 36),  //>10^(-16^0*5)=1.00000000000000000000000000000e-5
  2499:     new EFP (P,    -20, 0x8637bd05af6c69b5L, 0xa63f9a5L << 36),  //>10^(-16^0*6)=1.00000000000000000000000000000e-6
  2500:     new EFP (P,    -24, 0xd6bf94d5e57a42bcL, 0x3d32907L << 36),  //<10^(-16^0*7)=1.00000000000000000000000000000e-7
  2501:     new EFP (P,    -27, 0xabcc77118461cefcL, 0xfdc20d3L << 36),  //>10^(-16^0*8)=1.00000000000000000000000000000e-8
  2502:     new EFP (P,    -30, 0x89705f4136b4a597L, 0x31680a9L << 36),  //>10^(-16^0*9)=1.00000000000000000000000000000e-9
  2503:     new EFP (P,    -34, 0xdbe6fecebdedd5beL, 0xb573441L << 36),  //>10^(-16^0*10)=1.00000000000000000000000000000e-10
  2504:     new EFP (P,    -37, 0xafebff0bcb24aafeL, 0xf78f69aL << 36),  //<10^(-16^0*11)=1.00000000000000000000000000000e-11
  2505:     new EFP (P,    -40, 0x8cbccc096f5088cbL, 0xf93f87bL << 36),  //<10^(-16^0*12)=1.00000000000000000000000000000e-12
  2506:     new EFP (P,    -44, 0xe12e13424bb40e13L, 0x2865a5fL << 36),  //<10^(-16^0*13)=1.00000000000000000000000000000e-13
  2507:     new EFP (P,    -47, 0xb424dc35095cd80fL, 0x538484cL << 36),  //<10^(-16^0*14)=1.00000000000000000000000000000e-14
  2508:     new EFP (P,    -50, 0x901d7cf73ab0acd9L, 0x0f9d370L << 36),  //<10^(-16^0*15)=1.00000000000000000000000000000e-15
  2509:     new EFP (P,      0, 0x8000000000000000L, 0x0000000L << 36),  //=10^(-16^1*0)=1.00000000000000000000000000000
  2510:     new EFP (P,    -54, 0xe69594bec44de15bL, 0x4c2ebe7L << 36),  //>10^(-16^1*1)=1.00000000000000000000000000000e-16
  2511:     new EFP (P,   -107, 0xcfb11ead453994baL, 0x67de18fL << 36),  //>10^(-16^1*2)=1.00000000000000000000000000000e-32
  2512:     new EFP (P,   -160, 0xbb127c53b17ec159L, 0x5560c02L << 36),  //>10^(-16^1*3)=1.00000000000000000000000000000e-48
  2513:     new EFP (P,   -213, 0xa87fea27a539e9a5L, 0x3f2398dL << 36),  //<10^(-16^1*4)=1.00000000000000000000000000000e-64
  2514:     new EFP (P,   -266, 0x97c560ba6b0919a5L, 0xdccd87aL << 36),  //>10^(-16^1*5)=1.00000000000000000000000000000e-80
  2515:     new EFP (P,   -319, 0x88b402f7fd75539bL, 0x11dbcb0L << 36),  //<10^(-16^1*6)=1.00000000000000000000000000000e-96
  2516:     new EFP (P,   -373, 0xf64335bcf065d37dL, 0x4d4617bL << 36),  //<10^(-16^1*7)=1.00000000000000000000000000000e-112
  2517:     new EFP (P,   -426, 0xddd0467c64bce4a0L, 0xac7cb3fL << 36),  //<10^(-16^1*8)=1.00000000000000000000000000000e-128
  2518:     new EFP (P,   -479, 0xc7caba6e7c5382c8L, 0xfe64a53L << 36),  //>10^(-16^1*9)=1.00000000000000000000000000000e-144
  2519:     new EFP (P,   -532, 0xb3f4e093db73a093L, 0x59ed216L << 36),  //<10^(-16^1*10)=1.00000000000000000000000000000e-160
  2520:     new EFP (P,   -585, 0xa21727db38cb002fL, 0xb8ada01L << 36),  //>10^(-16^1*11)=1.00000000000000000000000000000e-176
  2521:     new EFP (P,   -638, 0x91ff83775423cc06L, 0x7b6306aL << 36),  //<10^(-16^1*12)=1.00000000000000000000000000000e-192
  2522:     new EFP (P,   -691, 0x8380dea93da4bc60L, 0x4247cbaL << 36),  //>10^(-16^1*13)=1.00000000000000000000000000000e-208
  2523:     new EFP (P,   -745, 0xece53cec4a314ebdL, 0xa4f8bf5L << 36),  //<10^(-16^1*14)=1.00000000000000000000000000000e-224
  2524:     new EFP (P,   -798, 0xd5605fcdcf32e1d6L, 0xfb1e4aaL << 36),  //>10^(-16^1*15)=1.00000000000000000000000000000e-240
  2525:     new EFP (P,      0, 0x8000000000000000L, 0x0000000L << 36),  //=10^(-16^2*0)=1.00000000000000000000000000000
  2526:     new EFP (P,   -851, 0xc0314325637a1939L, 0xfa91115L << 36),  //<10^(-16^2*1)=1.00000000000000000000000000000e-256
  2527:     new EFP (P,  -1701, 0x9049ee32db23d21cL, 0x7132d33L << 36),  //<10^(-16^2*2)=1.00000000000000000000000000000e-512
  2528:     new EFP (P,  -2552, 0xd8a66d4a505de96bL, 0x5ae1b26L << 36),  //>10^(-16^2*3)=1.00000000000000000000000000000e-768
  2529:     new EFP (P,  -3402, 0xa2a682a5da57c0bdL, 0x87a6016L << 36),  //>10^(-16^2*4)=1.00000000000000000000000000000e-1024
  2530:     new EFP (P,  -4253, 0xf4385d0975edbabeL, 0x1f4bf66L << 36),  //<10^(-16^2*5)=1.00000000000000000000000000000e-1280
  2531:     new EFP (P,  -5103, 0xb759449f52a711b2L, 0x68e1eb7L << 36),  //<10^(-16^2*6)=1.00000000000000000000000000000e-1536
  2532:     new EFP (P,  -5953, 0x89a63ba4c497b50eL, 0x6c83ad1L << 36),  //<10^(-16^2*7)=1.00000000000000000000000000000e-1792
  2533:     new EFP (P,  -6804, 0xceae534f34362de4L, 0x492512dL << 36),  //<10^(-16^2*8)=1.00000000000000000000000000000e-2048
  2534:     new EFP (P,  -7654, 0x9b2a840f28a1638fL, 0xe393a9cL << 36),  //<10^(-16^2*9)=1.00000000000000000000000000000e-2304
  2535:     new EFP (P,  -8505, 0xe8fb7dc2dec0a404L, 0x598eec8L << 36),  //>10^(-16^2*10)=1.00000000000000000000000000000e-2560
  2536:     new EFP (P,  -9355, 0xaee973911228abcaL, 0xe3187c3L << 36),  //<10^(-16^2*11)=1.00000000000000000000000000000e-2816
  2537:     new EFP (P, -10205, 0x8350bf3c91575a87L, 0xe79e237L << 36),  //>10^(-16^2*12)=1.00000000000000000000000000000e-3072
  2538:     new EFP (P, -11056, 0xc52ba8a6aeb15d92L, 0x9e98cbaL << 36),  //>10^(-16^2*13)=1.00000000000000000000000000000e-3328
  2539:     new EFP (P, -11906, 0x9406af8f83fd6265L, 0x4b4de35L << 36),  //>10^(-16^2*14)=1.00000000000000000000000000000e-3584
  2540:     new EFP (P, -12757, 0xde42ff8d37cad87fL, 0x1463ef5L << 36),  //>10^(-16^2*15)=1.00000000000000000000000000000e-3840
  2541:     new EFP (P,      0, 0x8000000000000000L, 0x0000000L << 36),  //=10^(-16^3*0)=1.00000000000000000000000000000
  2542:     new EFP (P, -13607, 0xa6dd04c8d2ce9fdeL, 0x2de3812L << 36),  //<10^(-16^3*1)=1.00000000000000000000000000000e-4096
  2543:     new EFP (P, -27214, 0xd986c20b686da869L, 0x5d1d4feL << 36),  //>10^(-16^3*2)=1.00000000000000000000000000000e-8192
  2544:   };
  2545:   //  echo read("efp.gp");efppub(["TENTO28","10^28"]) | gp -q
  2546:   public final EFP      TENTO28 = new EFP (P,     93, 0x813f3978f8940984L, 0x4000000L << 36);  //=10^28=10000000000000000000000000000.0
  2547: 
  2548: 
  2549: 
  2550:   //========================================================================
  2551:   //$$EFP 92bit浮動小数点数
  2552:   //  class EFP
  2553:   //
  2554:   //  フラグ flg
  2555:   //    bit31  M  -
  2556:   //    bit30  Z  ±0
  2557:   //    bit29  I  ±Inf
  2558:   //    bit28  N  NaN
  2559:   //      flg==P      +x
  2560:   //      flg==M      -x
  2561:   //      flg==(P|Z)  +0
  2562:   //      flg==(M|Z)  -0
  2563:   //      flg==(P|I)  +Inf
  2564:   //      flg==(M|I)  -Inf
  2565:   //      flg==N      NaN
  2566:   //      flg==0      +x
  2567:   //      flg!=0      -x,±0,±Inf,NaN
  2568:   //      flg>=0      +x,+0,+Inf,NaN
  2569:   //      flg<0       -x,-0,-Inf
  2570:   //      flg<<1==0   ±x
  2571:   //      flg<<1!=0   ±0,±Inf,NaN
  2572:   //      flg<<1>=0   ±x,±Inf,NaN
  2573:   //      flg<<1<0    ±0
  2574:   //      flg<<2==0   ±x,±0
  2575:   //      flg<<2!=0   ±Inf,NaN
  2576:   //      flg<<2>=0   ±x,±0,NaN
  2577:   //      flg<<2<0    ±Inf
  2578:   //      flg<<3==0   ±x,±0,±Inf
  2579:   //      flg<<3!=0   NaN
  2580:   //      flg<<3>=0   ±x,±0,±Inf
  2581:   //      flg<<3<0    NaN
  2582:   //    インスタンスのフラグがコンディションコードを兼ねる
  2583:   //    ±0,±Inf,NaNの表現を仮数部に組み込まない理由
  2584:   //      ±0,±Inf,NaNをflg<<1!=0でまとめて分離することで±0,±Inf,NaN以外の処理のオーバーヘッドを減らす
  2585:   //      ±0,±Inf,NaNの仮数部を不定にすることで±0,±Inf,NaNを返す処理を短くする
  2586:   //    -NaNを設けない理由
  2587:   //      例外的な値のためにコードを冗長にしたくない
  2588:   //      doubleの場合
  2589:   //        負符号でNaNの符号が反転しない場合と反転する場合がある
  2590:   //        System.out.printf("%016x\n",Double.doubleToRawLongBits(Double.NaN));
  2591:   //        7ff8000000000000
  2592:   //        System.out.printf("%016x\n",Double.doubleToRawLongBits(-Double.NaN));
  2593:   //        7ff8000000000000
  2594:   //        System.out.printf("%016x\n",Double.doubleToRawLongBits(-Double.longBitsToDouble(0x7ff8000000000000L)));
  2595:   //        fff8000000000000
  2596:   //        加算で片方がNaNのときはその符号が使用される
  2597:   //        System.out.printf("%016x\n",Double.doubleToRawLongBits(Double.longBitsToDouble(0xfff8000000000000L)+0.0));
  2598:   //        fff8000000000000
  2599:   //        System.out.printf("%016x\n",Double.doubleToRawLongBits(0.0+Double.longBitsToDouble(0xfff8000000000000L)));
  2600:   //        fff8000000000000
  2601:   //        加算で両方がNaNのときは後者の符号が使用される
  2602:   //        System.out.printf("%016x\n",Double.doubleToRawLongBits(Double.NaN+Double.longBitsToDouble(0xfff8000000000000L)));
  2603:   //        fff8000000000000
  2604:   //        System.out.printf("%016x\n",Double.doubleToRawLongBits(Double.longBitsToDouble(0xfff8000000000000L)+Double.NaN));
  2605:   //        7ff8000000000000
  2606:   //
  2607:   //  指数部 epp
  2608:   //    符号あり16bit(-32768~32767)
  2609:   //    内部32bit
  2610:   //      高速化のため内部では指数部が符号あり16bitに収まっているかどうかを確認せずに処理を進める
  2611:   //    浮動小数点数の値が1のとき指数部は0
  2612:   //    ±0,±Inf,NaNのときは不定
  2613:   //    下駄履き16bitゼロ拡張ではなくて16bit符号拡張にする理由
  2614:   //      乗算、除算、累乗などで下駄が邪魔にならない
  2615:   //      オーバーフローまたはアンダーフローの判定は(short)epp!=eppでできる
  2616:   //        下駄履き16bitゼロ拡張のときのepp>>16!=0または(char)epp!=eppと比較しても大きく遅くなることはない
  2617:   //
  2618:   //  仮数部 dvl,cvl
  2619:   //    LEN=92bit
  2620:   //      (92bitに限定する必要がない場所では65bit<=LEN<=95bitの範囲で調整できるようにする)
  2621:   //      整数部は1bitで常に1
  2622:   //        ±0,±Inf,NaN以外はすべて正規化数であり、仮数部について非正規化数は存在しない
  2623:   //      小数部は91bit
  2624:   //      2個のlongに左詰めで格納する
  2625:   //      余った領域は0で埋める
  2626:   //      表現できる正規化数の範囲は2^-32768から(2-2^(1-LEN))*2^32767まで
  2627:   //                    2^-32768 = 10^-9864.1508979173358047637961023321875012
  2628:   //        (2-2^(1-92))*2^32767 = 10^9864.1508979173358047637961023320997960
  2629:   //      連続して正確に表現できる整数の範囲は-2^92から2^92まで。10進数で27桁まで
  2630:   //        2^92 = 4951760157141521099596496896
  2631:   //             = 10^27.694759601086269959663978314653358463
  2632:   //      26桁まで出力する
  2633:   //        単一の演算では26桁までは正確であることを期待できる
  2634:   //    ±0,±Inf,NaNのときは不定
  2635:   //    65bit以上にする理由
  2636:   //      64bit以下では超越関数などでextendedの精度を確保できない
  2637:   //    92bit以下にする理由
  2638:   //      乗算を効率よく行える
  2639:   //        32bit,30bit,30bitに3分割して掛けると中間の加算が最大で62bit*2+60bit*3となって64bitに収まるのでキャリーの処理が簡単になる
  2640:   //    91bit以下にする理由
  2641:   //      除算を効率よく行える
  2642:   //        91bitの被除数を右に1bitずらしてから基数2^31で3分割して割ると
  2643:   //        2^29<=被除数の1桁目(30bit)<2^30<=除数の1桁目(31bit)<2^31
  2644:   //        なので3回の操作で92bitまたは93bitの商が得られる
  2645:   //        商に92bit目のguard bitが含まれるので丸めの処理が簡単になる
  2646:   //    整数部を1に固定する(非正規化数を設けない)理由
  2647:   //      非正規化数を設けないことで正規化数の処理のオーバーヘッドを減らす
  2648:   //      float,double,extendedの非正規化数はEFPでは正規化数として表現できる
  2649:   //        extendedの指数部は15bit
  2650:   //
  2651:   //  丸めの処理
  2652:   //    演算結果を最も近い表現可能な値に丸める
  2653:   //    演算結果に最も近い表現可能な値が2つあるときはLSBが0の方(最近接偶数)に丸める
  2654:   //      他の丸めはfloat,double,extendedへ変換するときだけ用いる
  2655:   //    最近接偶数への丸めにする理由
  2656:   //      最近接偶数への丸めは符号を考慮する必要がないので高速
  2657:   //      丸めてから符号反転したときと符号反転してから丸めたときの結果が異なるのは気持ち悪い
  2658:   //    条件
  2659:   //      65bit<=LEN<=95bitであること
  2660:   //      演算結果がze,zd,zc,zbに入っているとする
  2661:   //        ze  指数部
  2662:   //        zd  仮数部の上位(64bit)
  2663:   //        zc  仮数部の下位(1~31bit),guard bit(1bit),round bit(1bit),sticky bit(61~31bit)
  2664:   //        zb  sticky bit(64bit)
  2665:   //    手順
  2666:   //      guard bitが0またはLSBとround bitとsticky bitがすべて0のときは切り捨てる
  2667:   //      guard bitが1かつLSBとround bitとsticky bitのいずれかが0でないときは切り上げて、溢れたときはMSBだけセットして指数部を1増やす
  2668:   //    コード
  2669:   //      if ((zc << LEN - 64 | zb) != 0L) {  //端数が0でないとき
  2670:   //        this.epbFpsr |= X2;  //不正確な結果
  2671:   //        if (zc << LEN - 64 >= 0L || (zc & (LSB | RBM | SBM) | zb) == 0L) {  //guard bitが0またはLSBとround bitとsticky bitがすべて0のとき
  2672:   //          zc &= -LSB;  //切り捨てる
  2673:   //        } else if ((zc = zc + LSB & -LSB) == 0L && ++zd == 0L) {  //切り上げて、溢れたとき
  2674:   //          zd = MSB;  //MSBだけセットして
  2675:   //          ze++;  //指数部を1増やす
  2676:   //        }
  2677:   //      }
  2678:   //
  2679:   //  超越関数の多項式展開
  2680:   //    テイラー展開
  2681:   //        f(x) = sum[n=0..∞]{f'n(a)/n!*(x-a)^n}
  2682:   //      a=0のとき(マクローリン展開)
  2683:   //        f(x) = sum[n=0..∞]{f'n(0)/n!*x^n}
  2684:   //        偶関数の奇数次の係数と奇関数の偶数次の係数は自動的に0になる
  2685:   //    cosの多倍角の公式
  2686:   //        cos(0*t) = 1
  2687:   //        cos(1*t) = cos(t)
  2688:   //        cos(n*t) = 2*cos(t)*cos((n-1)*t)-cos((n-2)*t)
  2689:   //    チェビシェフ多項式
  2690:   //        T(0,x) = 1
  2691:   //        T(1,x) = x
  2692:   //        T(n,x) = 2*x*T(n-1,x)-T(n-2,x)
  2693:   //               = ((x-sqrt(x^2-1))^n+(x+sqrt(x^2-1))^n)/2
  2694:   //      echo for(n=0,10,printf("T(%d,x) = %s\n",n,polchebyshev(n))) | gp -q
  2695:   //        T(0,x) = 1
  2696:   //        T(1,x) = x
  2697:   //        T(2,x) = 2*x^2 - 1
  2698:   //        T(3,x) = 4*x^3 - 3*x
  2699:   //        T(4,x) = 8*x^4 - 8*x^2 + 1
  2700:   //        T(5,x) = 16*x^5 - 20*x^3 + 5*x
  2701:   //        T(6,x) = 32*x^6 - 48*x^4 + 18*x^2 - 1
  2702:   //        T(7,x) = 64*x^7 - 112*x^5 + 56*x^3 - 7*x
  2703:   //        T(8,x) = 128*x^8 - 256*x^6 + 160*x^4 - 32*x^2 + 1
  2704:   //        T(9,x) = 256*x^9 - 576*x^7 + 432*x^5 - 120*x^3 + 9*x
  2705:   //        T(10,x) = 512*x^10 - 1280*x^8 + 1120*x^6 - 400*x^4 + 50*x^2 - 1
  2706:   //    チェビシェフ展開
  2707:   //        f(x) = sum[k=0..∞]{(k==0?1:2)/pi*int[t=0..pi]{cos(k*t)*f(cos(t))}*T(k,x)}
  2708:   //        定義域が[-1,1]なので目的の関数に応じて変数変換を行う
  2709:   //        偶関数の奇数次の係数と奇関数の偶数次の係数は自動的に0になる
  2710:   //      台形積分を用いる場合
  2711:   //        f(x) ≒ sum[k=0..n]{(k==0?1:2)/n*sum[j=0..n]{(j==0||j==n?1/2:1)*cos(pi*j*k/n)*f(cos(pi*j/n))}*T(k,x)}
  2712:   //    テイラー展開vsチェビシェフ展開
  2713:   //      多項式近似の所要時間は項数と各項の次数と係数の有無が同じであれば係数の値は関係ない
  2714:   //      係数の値を調整することで真の値と一致する桁数を増やすことができれば同じ桁数を得るのに必要な項数が少なくて済む分所要時間が短くなる
  2715:   //      無限に続けることが前提のテイラー展開を途中で打ち切った多項式よりも項数を任意に設定できるチェビシェフ展開の方が同じ項数でも真の値と一致する桁数が多くなる
  2716:   //    多項式の次数の選択
  2717:   //      定義域を10000分割して10001箇所すべてで必要なbit数よりも8bit以上余分に求められる最短の多項式を選択する
  2718:   //      ほぼ全域で誤差が129/256ulp未満となる
  2719:   //        全域で誤差を1/2ulp未満にする(常に真の値に最も近い表現可能な値を返す)多項式を構築することは困難である
  2720:   //        真の値の端数が0.5に近くて近似値の端数が0.5を挟んで反対側にあるとそれらの差がどれだけ小さくても真の値から遠い方に丸められてしまう
  2721:   //        例: atan()の23次のチェビシェフ展開の精度は55bitだが53bitに丸めると53bit目が真の値に最も近い表現可能な値と異なってしまう例
  2722:   //        echo read("efp.gp");x=dbltonum(0x3f8cf097f3a42000);y0=atan(x);y1=eval("-2722284370390831588490114173/158456325028528675187087900672*x^23 + 739739927556278187039881021/19807040628566084398385987584*x^21 - 992045672314533323023892321/19807040628566084398385987584*x^19 + 2313610503890582509205873157/39614081257132168796771975168*x^17 - 1319535373237619650487539135/19807040628566084398385987584*x^15 + 3047093318219389825184024421/39614081257132168796771975168*x^13 - 3601272632870709965040963617/39614081257132168796771975168*x^11 + 1100391082127852704923599513/9903520314283042199192993792*x^9 - 2829577229944316543631260919/19807040628566084398385987584*x^7 + 1980704062840506309069283499/9903520314283042199192993792*x^5 - 3301173438094258430826284729/9903520314283042199192993792*x^3 + 154742504910672532084711661/154742504910672534362390528*x")*1.0;printf("%.30g,%016x",y0,floor(y0*eval("2^59")+0.5));print();printf("%.30g,%016x",y1,floor(y1*eval("2^59")+0.5));print();printf("%.30g",log(abs((y1-y0)/y0))/log(2));print() | gp -q
  2723:   //        0.0141298303751989210010080821653,001cf019bae04517  真の値
  2724:   //        0.0141298303751989208174624059843,001cf019bae04516  近似値
  2725:   //        -56.0953826306895581110391156901  精度
  2726:   //        真の値の端数は0.10010…なので本来は切り上げなければならないが近似値の端数が0.01110…なので切り捨てられてしまっている
  2727:   //
  2728:   //    多項式の計算
  2729:   //      多項式の計算にはホーナー法(Horner's method)を用いる
  2730:   //        c(n)*x^n+c(n-1)*x^(n-1)+...+c1*x+c0 = ((c(n)*x+c(n-1))*x+...+c1)*x+c0
  2731:   //        c(n)*x+c(n-1)が0に近いときすなわちxが-c(n-1)/c(n)に近いとき桁落ち誤差が大きくなることに注意する
  2732:   //
  2733:   //  余談
  2734:   //    SPARC64 VIIIfx(京のプロセッサ)の三角関数補助演算命令は[-π/4,π/4]の範囲のsinを7項、cosを8項の多項式で近似している
  2735:   //    特にsinは53bitの係数×7項で57bitまで一致させるという超絶技巧が使われており、この係数をどうやって選択したのか興味深い
  2736:   //      sin(x)=1.0000000000000000000*x-0.16666666666666615781*x^3+0.0083333333333200018678*x^5-0.00019841269828402128715*x^7
  2737:   //            +2.7557313299015053950e-6*x^9-2.5050705846378874749e-8*x^11+1.5894136371952154456e-10*x^13
  2738:   //      echo read("efp.gp");printf("%.4f%c",closeness(sin,((((((dbltonum(0X3DE5D8408868552F)*x*x+dbltonum(0XBE5AE5E2B60F7B91))*x*x+dbltonum(0X3EC71DE351F3D22B))*x*x+dbltonum(0xBF2A01A019B92FC6))*x*x+dbltonum(0x3F8111111110F30C))*x*x+dbltonum(0xBFC5555555555543))*x*x+dbltonum(0x3FF0000000000000))*x,-Pi/4,Pi/4,10000),10) | gp -q
  2739:   //      57.0852
  2740:   //      cos(x)=1.0000000000000000000-0.50000000000000000000*x^2+0.041666666666666449248*x^4-0.0013888888888861107822*x^6
  2741:   //            +2.4801587283886826962e-5*x^8-2.7557313099139499305e-7*x^10+2.0875582539758721897e-9*x^12-1.1353387007200546080e-11*x^14
  2742:   //      echo read("efp.gp");printf("%.4f%c",closeness(cos,((((((dbltonum(0xBDA8F76380FBB401)*x*x+dbltonum(0x3E21EE96D2641B13))*x*x+dbltonum(0xBE927E4F7282F468))*x*x+dbltonum(0x3EFA01A019B1E8D8))*x*x+dbltonum(0xBF56C16C16C13A0B))*x*x+dbltonum(0x3FA5555555555536))*x*x+dbltonum(0xBFE0000000000000))*x*x+dbltonum(0x3FF0000000000000),-Pi/4,Pi/4,10000),10) | gp -q
  2743:   //      56.9315
  2744:   //
  2745:   //  参考
  2746:   //    http://repository.dl.itc.u-tokyo.ac.jp/dspace/handle/2261/31404
  2747:   //      研究解説 : チェビシェフ多項式による関数近似について
  2748:   //    http://www.made.gifu-u.ac.jp/~tanaka/LectureNote/numerical_analysis.pdf
  2749:   //      基礎数値解析‐偏微分方程式の数値シミュレーション技法入門‐
  2750:   //    http://www.fujitsu.com/jp/solutions/business-technology/tc/catalog/
  2751:   //      SPARC64(TM) VIIIfx Extensions 日本語版
  2752:   //
  2753:   //  メモ
  2754:   //    インスタンスを格納する変数がfinalでもフィールドは読み書き自由なので定数インスタンスのフィールドを間違って書き換えないように注意する
  2755:   //    使用頻度が低い処理のための条件分岐(下位が0かどうかの場合分けなど)を使用頻度が高い場所に書くことは極力避ける
  2756:   //
  2757:   //  逆三角関数と逆双曲線関数の名前
  2758:   //    逆三角関数と逆双曲線関数の接頭辞は1文字のa、呼び方はinverse(逆)に統一する
  2759:   //      ISO 80000-2:2009では逆三角関数の接頭辞はarc、逆双曲線関数の接頭辞はar
  2760:   //    Google Ngram Viewerによると、2008年までの逆双曲線関数の接頭辞の使用頻度はa>arc>arである
  2761:   //        https
  2762:   //        ://books.google.com/ngrams/graph?content=acosh%2Casinh%2Catanh%2Carcosh%2Carsinh%2Cartanh%2Carccosh%2Carcsinh%2Carctanh&case_insensitive=on&year_start=1840&year_end=2008&corpus=15&smoothing=6
  2763:   //      ただし、ソースコードの中のasinhと数式の中のarsinhが同程度に満遍なくカウントできているのかどうかは定かではない
  2764:   //    意味的に逆三角関数の返却値はarc(弧)だが逆双曲線関数の返却値はarea(面積)なのだから逆双曲線関数の接頭辞にarcを使うのは誤りということらしい
  2765:   //    コンピュータの関数名は双曲線関数の先頭にarcを付けたのではなく逆三角関数の末尾にhを付けたらarcが付いてきたというパターンも多いと思われる
  2766:   //      Mathematicaの関数名はArcTanhである
  2767:   //        http://reference.wolfram.com/language/ref/ArcTanh.html
  2768:   //      PHPのマニュアル(日本語版)のatanhの説明にカタカナでアークハイパボリックタンジェントと書かれている
  2769:   //        http://php.net/manual/ja/function.atanh.php
  2770:   //        英語版はinverseとしか書かれていない
  2771:   //        http://php.net/manual/en/function.atanh.php
  2772:   //      MC68881UMのFATANHのページにはhyperbolic arc tangentと書かれている
  2773:   //        http://cache.freescale.com/files/32bit/doc/ref_manual/MC68881UM.pdf
  2774:   //      MZ-1500用のHuBASIC Ver2.0のマニュアルにもarc-hyperbolic tangentと書かれていた
  2775:   //      Wikipediaのノートにいろいろな意見がある
  2776:   //        https://en.wikipedia.org/wiki/Talk:Inverse_hyperbolic_function
  2777:   //
  2778:   //  累乗は冪乗またはべき乗とも書くがここでは累乗とする
  2779:   //
  2780:   public class EFP implements Comparable<EFP> {
  2781: 
  2782:     //------------------------------------------------------------------------
  2783:     //定数
  2784:     //  サイズ
  2785:     public static final int LEN = 92;  //仮数部のbit数。65<=LEN<=95
  2786:     public static final long MSB = 1L << 63;  //dの最上位bit。整数部
  2787:     public static final long LSB = 1L << 128 - LEN;  //cの最下位bit。ulp
  2788:     public static final long GBM = LSB >>> 1;  //cのguard bit。1/2*ulp。丸めの処理で使う
  2789:     public static final long RBM = GBM >>> 1;  //cのround bit。1/4*ulp。指数部が異なる数の減算で1bit減ったときにguard bitになる
  2790:     public static final long SBM = RBM - 1L;  //cのsticky bitのマスク。1/4*ulp未満が0か0でないかを示す
  2791: 
  2792:     public static final int EFP_DECIMAL_PREC = 26;  //toStringの出力桁数
  2793: 
  2794:     public static final int EFP_COTH_EPP_MAX = 5;  //floor(log(log(sqrt(2^(LEN+1)+1)))/log(2))
  2795: 
  2796:     //  JavaのNaN            FPCPのNaN
  2797:     //  0x7ff8000000000000L  0x7fffffffffffffffL
  2798:     //  0x7fc00000           0x7fffffff
  2799:     public static final boolean EFP_FPCP_NAN = true;  //doubleまたはfloatで取り出すときNaNをJavaのNaNではなくFPCPのNaNに変換する
  2800: 
  2801:     //------------------------------------------------------------------------
  2802:     //インスタンスフィールド
  2803:     //                  6666555555555544 4444444433333333 3322222222221111 1111110000000000
  2804:     //                  3210987654321098 7654321098765432 1098765432109876 5432109876543210
  2805:     public int flg;   //                                  MZIN000000000000 0000000000000000  f フラグ
  2806:     public int epp;   //                                  ssssssssssssssss seeeeeeeeeeeeeee  e 指数部
  2807:     public long dvl;  //1ddddddddddddddd dddddddddddddddd dddddddddddddddd dddddddddddddddd  d 仮数部の上位64bit
  2808:     //                  └e==0のときの小数点の位置
  2809:     public long cvl;  //cccccccccccccccc cccccccccccc0000 0000000000000000 0000000000000000  c 仮数部の下位LEN-64bit
  2810:     //                                                GRSS SSSSSSSSSSSSSSSS SSSSSSSSSSSSSSSS  guard bit,round bit,sticky bit
  2811: 
  2812:     //------------------------------------------------------------------------
  2813:     //公開コンストラクタ
  2814:     //  丸めの処理が入るので定数の構築には使用できない
  2815:     //y = epb.new EFP ()
  2816:     //y = epb.new EFP (d)
  2817:     //y = epb.new EFP (f)
  2818:     //y = epb.new EFP (i)
  2819:     //y = epb.new EFP (l)
  2820:     //y = epb.new EFP (s)
  2821:     //y = epb.new EFP (e)
  2822:     public EFP () {
  2823:       this.set0 ();
  2824:     }  //EFP()
  2825:     public EFP (double d) {
  2826:       this.setd (d);
  2827:     }  //EFP(double)
  2828:     public EFP (float f) {
  2829:       this.setf (f);
  2830:     }  //EFP(float)
  2831:     public EFP (int i) {
  2832:       this.seti (i);
  2833:     }  //EFP(int)
  2834:     public EFP (long l) {
  2835:       this.setl (l);
  2836:     }  //EFP(long)
  2837:     public EFP (String s) {
  2838:       this.parse (s);
  2839:     }  //EFP(String)
  2840:     public EFP (EFP x) {
  2841:       this.sete (x);
  2842:     }  //EFP(EFP)
  2843: 
  2844:     //------------------------------------------------------------------------
  2845:     //内部コンストラクタ
  2846:     //  定数の構築に使用するので丸めの処理を行ってはならない
  2847:     //  丸めの処理が必要な場所で使う場合は後から丸めの処理を行う必要がある
  2848:     public EFP (int xf, int xe, long xd, long xc) {
  2849:       this.flg = xf;
  2850:       this.epp = xe;
  2851:       this.dvl = xd;
  2852:       this.cvl = xc;
  2853:     }  //EFP(int,int,long,long)
  2854: 
  2855:     //------------------------------------------------------------------------
  2856:     //丸めの処理
  2857: 
  2858:     //efp = efp.inner ()
  2859:     //  一時的に、丸め桁数を92bitに、丸めモードをRNに変更する
  2860:     //  関数が内部で他の関数を複数回呼び出すとき、最初の子を呼び出す『前に』実行する
  2861:     //    最初の子から最大精度で丸めさせる
  2862:     //  EFPBoxの機能だがメソッドチェーンに挟めるようにEFPのメソッドにしてある
  2863:     //    EFPBoxのインスタンスが同じならばどのEFPのインスタンスで呼び出しても同じ
  2864:     //  inner()とouter()の数がずれないように注意すること
  2865:     public final EFP inner () {
  2866:       if (epbRoundingDepth++ == 0) {
  2867:         epbRoundingOuterPrec = epbRoundingPrec;  //丸め桁数を保存する
  2868:         epbRoundingPrec = EPB_PREC_EFP;  //丸め桁数を92bitに変更する
  2869:         epbRoundingOuterMode = epbRoundingMode;  //丸めモードを保存する
  2870:         epbRoundingMode = EPB_MODE_RN;  //丸めモードをRNに変更する
  2871:       }
  2872:       if (false) {
  2873:         if (epbRoundingDepth == 10) {
  2874:           System.out.println ("too many EFP.inner()\n");
  2875:         }
  2876:       }
  2877:       return this;
  2878:     }  //efp.inner()
  2879: 
  2880:     //efp = efp.outer ()
  2881:     //  丸め桁数と丸めモードを元に戻す
  2882:     //  関数が内部で他の関数を複数回呼び出すとき、最後の子を呼び出す『前に』実行する
  2883:     //    最後の子に本来の精度で丸めさせる
  2884:     //  EFPBoxの機能だがメソッドチェーンに挟めるようにEFPのメソッドにしてある
  2885:     //    EFPBoxのインスタンスが同じならばどのEFPのインスタンスで呼び出しても同じ
  2886:     //  inner()とouter()の数がずれないように注意すること
  2887:     public final EFP outer () {
  2888:       if (--epbRoundingDepth == 0) {
  2889:         epbRoundingPrec = epbRoundingOuterPrec;  //丸め桁数を復元する
  2890:         epbRoundingMode = epbRoundingOuterMode;  //丸めモードを復元する
  2891:       }
  2892:       if (false) {
  2893:         if (epbRoundingDepth == -1) {
  2894:           System.out.println ("too many EFP.outer()\n");
  2895:         }
  2896:       }
  2897:       return this;
  2898:     }  //efp.outer()
  2899: 
  2900:     //efp = efp.finish ()
  2901:     //efp = efp.finish (zf, ze, zd, zc, zb)
  2902:     //  丸めの処理とオーバーフローとアンダーフローのチェックを行ってからインスタンスフィールドを設定する
  2903:     //  原則としてすべての関数に設置する
  2904:     //  関数が内部で他の関数を複数回呼び出すときは、最初の子を呼び出す前にinner()を、最後の子を呼び出す前にouter()を実行する
  2905:     public final EFP finish () {
  2906:       int zf = this.flg;
  2907:       if (zf << 1 != 0) {  //±0,±Inf,NaN
  2908:         return this;
  2909:       }
  2910:       switch (epbRoundingPrec) {
  2911:       case EPB_PREC_EXD:
  2912:         return this.roundx (epbRoundingMode);
  2913:       case EPB_PREC_SGL:
  2914:         return this.roundf (epbRoundingMode);
  2915:       case EPB_PREC_DBL:
  2916:       case EPB_PREC_DBL3:
  2917:         return this.roundd (epbRoundingMode);
  2918:       case EPB_PREC_TPL:
  2919:         return this.roundy (epbRoundingMode);
  2920:       case EPB_PREC_XSG:
  2921:         return this.roundg (epbRoundingMode);
  2922:       case EPB_PREC_EFP:
  2923:       default:
  2924:         int ze = this.epp;
  2925:         long zd = this.dvl;
  2926:         long zc = this.cvl;
  2927:         switch (epbRoundingMode) {
  2928:         case EPB_MODE_RN:
  2929:           if (zc << 28 != 0L) {  //端数が0でないとき
  2930:             epbFpsr |= EPB_FPSR_X2;  //不正確な結果
  2931:             if (zc << 28 < 0L && (zc & 0x00000017ffffffffL) != 0L &&  //guard bitが1かつLSBまたはguard bit以外の端数が0ではないとき
  2932:                 (zc += 1L << 36) >>> 36 == 0L && ++zd == 0L) {  //切り上げて溢れたとき
  2933:               zd = MSB;
  2934:               ze++;
  2935:             }
  2936:             zc &= 0xfffffff000000000L;  //端数を切り捨てる
  2937:           }
  2938:           break;
  2939:         case EPB_MODE_RZ:
  2940:           if (zc << 28 != 0L) {  //端数が0でないとき
  2941:             epbFpsr |= EPB_FPSR_X2;  //不正確な結果
  2942:             zc &= 0xfffffff000000000L;  //端数を切り捨てる
  2943:           }
  2944:           break;
  2945:         case EPB_MODE_RM:
  2946:           if (zc << 28 != 0L) {  //端数が0でないとき
  2947:             epbFpsr |= EPB_FPSR_X2;  //不正確な結果
  2948:             if (zf < 0 &&  //-のとき
  2949:                 (zc += 1L << 36) >>> 36 == 0L && ++zd == 0L) {  //切り上げて溢れたとき
  2950:               zd = MSB;
  2951:               ze++;
  2952:             }
  2953:             zc &= 0xfffffff000000000L;  //端数を切り捨てる
  2954:           }
  2955:           break;
  2956:         case EPB_MODE_RP:
  2957:         default:
  2958:           if (zc << 28 != 0L) {  //端数が0でないとき
  2959:             epbFpsr |= EPB_FPSR_X2;  //不正確な結果
  2960:             if (0 <= zf &&  //+のとき
  2961:                 (zc += 1L << 36) >>> 36 == 0L && ++zd == 0L) {  //切り上げて溢れたとき
  2962:               zd = MSB;
  2963:               ze++;
  2964:             }
  2965:             zc &= 0xfffffff000000000L;  //端数を切り捨てる
  2966:           }
  2967:           break;
  2968:         }
  2969:         if ((short) ze != ze) {  //オーバーフローまたはアンダーフロー
  2970:           if (0 <= ze) {  //オーバーフロー
  2971:             epbFpsr |= EPB_FPSR_OF;  //オーバーフロー
  2972:             epbExceptionOperandExponent = zf;
  2973:             epbExceptionOperandMantissa = zd;
  2974:             return this.sete (OVFL_RESULTS[EPB_PREC_EFP << 3 | EPB_MODE_RP << 1 | zf >>> 31]);  //±Inf
  2975:           } else {  //アンダーフロー
  2976:             epbFpsr |= EPB_FPSR_UF;  //アンダーフロー
  2977:             epbExceptionOperandExponent = zf;
  2978:             epbExceptionOperandMantissa = zd;
  2979:             return this.sete (UNFL_RESULTS[EPB_PREC_EFP << 3 | EPB_MODE_RP << 1 | zf >>> 31]);  //±0
  2980:           }
  2981:         }
  2982:         this.flg = zf;
  2983:         this.epp = ze;
  2984:         this.dvl = zd;
  2985:         this.cvl = zc;
  2986:         return this;
  2987:       }  //switch epbRoundingMode
  2988:     }  //efp.finish()
  2989:     public final EFP finish (int zf, int ze, long zd, long zc, long zb) {
  2990:       if (zf << 1 != 0) {  //±0,±Inf,NaN
  2991:         this.flg = zf;
  2992:         return this;
  2993:       }
  2994:       switch (epbRoundingPrec) {
  2995:       case EPB_PREC_EXD:
  2996:         this.flg = zf;
  2997:         this.epp = ze;
  2998:         this.dvl = zd;
  2999:         this.cvl = zc | zb >>> 32 | zb & 0xffffffffL;
  3000:         return this.roundx (epbRoundingMode);
  3001:       case EPB_PREC_SGL:
  3002:         this.flg = zf;
  3003:         this.epp = ze;
  3004:         this.dvl = zd;
  3005:         this.cvl = zc | zb >>> 32 | zb & 0xffffffffL;
  3006:         return this.roundf (epbRoundingMode);
  3007:       case EPB_PREC_DBL:
  3008:       case EPB_PREC_DBL3:
  3009:         this.flg = zf;
  3010:         this.epp = ze;
  3011:         this.dvl = zd;
  3012:         this.cvl = zc | zb >>> 32 | zb & 0xffffffffL;
  3013:         return this.roundd (epbRoundingMode);
  3014:       case EPB_PREC_TPL:
  3015:         this.flg = zf;
  3016:         this.epp = ze;
  3017:         this.dvl = zd;
  3018:         this.cvl = zc | zb >>> 32 | zb & 0xffffffffL;
  3019:         return this.roundy (epbRoundingMode);
  3020:       case EPB_PREC_XSG:
  3021:         this.flg = zf;
  3022:         this.epp = ze;
  3023:         this.dvl = zd;
  3024:         this.cvl = zc | zb >>> 32 | zb & 0xffffffffL;
  3025:         return this.roundg (epbRoundingMode);
  3026:       case EPB_PREC_EFP:
  3027:       default:
  3028:         switch (epbRoundingMode) {
  3029:         case EPB_MODE_RN:
  3030:           if ((zc << 28 | zb) != 0L) {  //端数が0でないとき
  3031:             epbFpsr |= EPB_FPSR_X2;  //不正確な結果
  3032:             if (zc << 28 < 0L && ((zc & 0x00000017ffffffffL) | zb) != 0L &&  //guard bitが1かつLSBまたはguard bit以外の端数が0ではないとき
  3033:                 (zc += 1L << 36) >>> 36 == 0L && ++zd == 0L) {  //切り上げて溢れたとき
  3034:               zd = MSB;
  3035:               ze++;
  3036:             }
  3037:             zc &= 0xfffffff000000000L;  //端数を切り捨てる
  3038:           }
  3039:           break;
  3040:         case EPB_MODE_RZ:
  3041:           if ((zc << 28 | zb) != 0L) {  //端数が0でないとき
  3042:             epbFpsr |= EPB_FPSR_X2;  //不正確な結果
  3043:             zc &= 0xfffffff000000000L;  //端数を切り捨てる
  3044:           }
  3045:           break;
  3046:         case EPB_MODE_RM:
  3047:           if ((zc << 28 | zb) != 0L) {  //端数が0でないとき
  3048:             epbFpsr |= EPB_FPSR_X2;  //不正確な結果
  3049:             if (zf < 0 &&  //-のとき
  3050:                 (zc += 1L << 36) >>> 36 == 0L && ++zd == 0L) {  //切り上げて溢れたとき
  3051:               zd = MSB;
  3052:               ze++;
  3053:             }
  3054:             zc &= 0xfffffff000000000L;  //端数を切り捨てる
  3055:           }
  3056:           break;
  3057:         case EPB_MODE_RP:
  3058:         default:
  3059:           if ((zc << 28 | zb) != 0L) {  //端数が0でないとき
  3060:             epbFpsr |= EPB_FPSR_X2;  //不正確な結果
  3061:             if (0 <= zf &&  //+のとき
  3062:                 (zc += 1L << 36) >>> 36 == 0L && ++zd == 0L) {  //切り上げて溢れたとき
  3063:               zd = MSB;
  3064:               ze++;
  3065:             }
  3066:             zc &= 0xfffffff000000000L;  //端数を切り捨てる
  3067:           }
  3068:           break;
  3069:         }
  3070:         if ((short) ze != ze) {  //オーバーフローまたはアンダーフロー
  3071:           if (0 <= ze) {  //オーバーフロー
  3072:             epbFpsr |= EPB_FPSR_OF;  //オーバーフロー
  3073:             epbExceptionOperandExponent = zf;
  3074:             epbExceptionOperandMantissa = zd;
  3075:             return this.sete (OVFL_RESULTS[EPB_PREC_EFP << 3 | EPB_MODE_RP << 1 | zf >>> 31]);  //±Inf
  3076:           } else {  //アンダーフロー
  3077:             epbFpsr |= EPB_FPSR_UF;  //アンダーフロー
  3078:             epbExceptionOperandExponent = zf;
  3079:             epbExceptionOperandMantissa = zd;
  3080:             return this.sete (UNFL_RESULTS[EPB_PREC_EFP << 3 | EPB_MODE_RP << 1 | zf >>> 31]);  //±0
  3081:           }
  3082:         }
  3083:         this.flg = zf;
  3084:         this.epp = ze;
  3085:         this.dvl = zd;
  3086:         this.cvl = zc;
  3087:         return this;
  3088:       }  //switch epbRoundingMode
  3089:     }  //finish(int,int,long,long,long)
  3090:     public final EFP finish2 (int zf, int ze, long zd, long zc, long zb) {
  3091:       if (zf << 1 != 0) {  //±0,±Inf,NaN
  3092:         this.flg = zf;
  3093:         return this;
  3094:       }
  3095:       switch (epbRoundingPrec) {
  3096:       case EPB_PREC_EXD:
  3097:         this.flg = zf;
  3098:         this.epp = ze;
  3099:         this.dvl = zd;
  3100:         this.cvl = zc | zb >>> 32 | zb & 0xffffffffL;
  3101:         return this.roundx2 (epbRoundingMode);
  3102:       case EPB_PREC_SGL:
  3103:         this.flg = zf;
  3104:         this.epp = ze;
  3105:         this.dvl = zd;
  3106:         this.cvl = zc | zb >>> 32 | zb & 0xffffffffL;
  3107:         return this.roundf (epbRoundingMode);
  3108:       case EPB_PREC_DBL:
  3109:       case EPB_PREC_DBL3:
  3110:         this.flg = zf;
  3111:         this.epp = ze;
  3112:         this.dvl = zd;
  3113:         this.cvl = zc | zb >>> 32 | zb & 0xffffffffL;
  3114:         return this.roundd (epbRoundingMode);
  3115:       case EPB_PREC_TPL:
  3116:         this.flg = zf;
  3117:         this.epp = ze;
  3118:         this.dvl = zd;
  3119:         this.cvl = zc | zb >>> 32 | zb & 0xffffffffL;
  3120:         return this.roundy2 (epbRoundingMode);
  3121:       case EPB_PREC_XSG:
  3122:         this.flg = zf;
  3123:         this.epp = ze;
  3124:         this.dvl = zd;
  3125:         this.cvl = zc | zb >>> 32 | zb & 0xffffffffL;
  3126:         return this.roundg (epbRoundingMode);
  3127:       case EPB_PREC_EFP:
  3128:       default:
  3129:         switch (epbRoundingMode) {
  3130:         case EPB_MODE_RN:
  3131:           if ((zc << 28 | zb) != 0L) {  //端数が0でないとき
  3132:             epbFpsr |= EPB_FPSR_X2;  //不正確な結果
  3133:             if (zc << 28 < 0L && ((zc & 0x00000017ffffffffL) | zb) != 0L &&  //guard bitが1かつLSBまたはguard bit以外の端数が0ではないとき
  3134:                 (zc += 1L << 36) >>> 36 == 0L && ++zd == 0L) {  //切り上げて溢れたとき
  3135:               zd = MSB;
  3136:               ze++;
  3137:             }
  3138:             zc &= 0xfffffff000000000L;  //端数を切り捨てる
  3139:           }
  3140:           break;
  3141:         case EPB_MODE_RZ:
  3142:           if ((zc << 28 | zb) != 0L) {  //端数が0でないとき
  3143:             epbFpsr |= EPB_FPSR_X2;  //不正確な結果
  3144:             zc &= 0xfffffff000000000L;  //端数を切り捨てる
  3145:           }
  3146:           break;
  3147:         case EPB_MODE_RM:
  3148:           if ((zc << 28 | zb) != 0L) {  //端数が0でないとき
  3149:             epbFpsr |= EPB_FPSR_X2;  //不正確な結果
  3150:             if (zf < 0 &&  //-のとき
  3151:                 (zc += 1L << 36) >>> 36 == 0L && ++zd == 0L) {  //切り上げて溢れたとき
  3152:               zd = MSB;
  3153:               ze++;
  3154:             }
  3155:             zc &= 0xfffffff000000000L;  //端数を切り捨てる
  3156:           }
  3157:           break;
  3158:         case EPB_MODE_RP:
  3159:         default:
  3160:           if ((zc << 28 | zb) != 0L) {  //端数が0でないとき
  3161:             epbFpsr |= EPB_FPSR_X2;  //不正確な結果
  3162:             if (0 <= zf &&  //+のとき
  3163:                 (zc += 1L << 36) >>> 36 == 0L && ++zd == 0L) {  //切り上げて溢れたとき
  3164:               zd = MSB;
  3165:               ze++;
  3166:             }
  3167:             zc &= 0xfffffff000000000L;  //端数を切り捨てる
  3168:           }
  3169:           break;
  3170:         }
  3171:         if ((short) ze != ze) {  //オーバーフローまたはアンダーフロー
  3172:           if (0 <= ze) {  //オーバーフロー
  3173:             epbFpsr |= EPB_FPSR_OF;  //オーバーフロー
  3174:             epbExceptionOperandExponent = zf;
  3175:             epbExceptionOperandMantissa = zd;
  3176:             return this.sete (OVFL_RESULTS[EPB_PREC_EFP << 3 | EPB_MODE_RP << 1 | zf >>> 31]);  //±Inf
  3177:           } else {  //アンダーフロー
  3178:             epbFpsr |= EPB_FPSR_UF;  //アンダーフロー
  3179:             epbExceptionOperandExponent = zf;
  3180:             epbExceptionOperandMantissa = zd;
  3181:             return this.sete (UNFL_RESULTS[EPB_PREC_EFP << 3 | EPB_MODE_RP << 1 | zf >>> 31]);  //±0
  3182:           }
  3183:         }
  3184:         this.flg = zf;
  3185:         this.epp = ze;
  3186:         this.dvl = zd;
  3187:         this.cvl = zc;
  3188:         return this;
  3189:       }  //switch epbRoundingMode
  3190:     }  //finish(int,int,long,long,long)
  3191:     public final EFP ifinish (int zf, int ze, long zd, long zc, long zb) {
  3192:       if (zf << 1 == 0 &&  //±0,±Inf,NaN以外で
  3193:           (zc << 28 | zb) != 0L) {  //端数が0でないとき
  3194:         epbFpsr |= EPB_FPSR_X2;  //不正確な結果
  3195:         if (zc << 28 < 0L && ((zc & 0x00000017ffffffffL) | zb) != 0L &&  //guard bitが1かつLSBまたはguard bit以外の端数が0ではないとき
  3196:             (zc += 1L << 36) >>> 36 == 0L && ++zd == 0L) {  //切り上げて溢れたとき
  3197:           zd = MSB;
  3198:           ze++;
  3199:         }
  3200:         zc &= 0xfffffff000000000L;  //端数を切り捨てる
  3201:       }  //if ±0,±Inf,NaN以外で端数が0でないとき
  3202:       this.flg = zf;
  3203:       this.epp = ze;
  3204:       this.dvl = zd;
  3205:       this.cvl = zc;
  3206:       return this;
  3207:     }  //ifinish(int,int,long,long,long)
  3208: 
  3209:     //this = this.originLowerLower (x)
  3210:     //this = this.originLowerUpper (x)
  3211:     //this = this.originUpperLower (x)
  3212:     //this = this.originUpperUpper (x)
  3213:     //  原点を傾き1で通る関数で原点付近の入力と出力の大小関係に矛盾が生じていたら修正する
  3214:     //  x<0
  3215:     //    x<0でy=xよりも下(y=-Infとy=xの間)にあるもの(asin,atanh,log1p,sinh,tan)
  3216:     //      SGL,DBLでないときはy=xまで下げる
  3217:     //      RMのときはy=xの下まで下げる
  3218:     //    x<0でy=xよりも上(y=0とy=xの間)にあるもの(asinh,atan,expm1,sin,tanh)
  3219:     //      SGL,DBLでないときはy=xまで上げる
  3220:     //      RZ,RPのときはy=xの上まで上げる
  3221:     //  0<x
  3222:     //    0<xでy=xよりも下(y=0とy=xの間)にあるもの(asinh,atan,log1p,sin,tanh)
  3223:     //      SGL,DBLでないときはy=xまで下げる
  3224:     //      RZ,RMのときはy=xの下まで下げる
  3225:     //    0<xでy=xよりも上(y=xとy=+Infの間)にあるもの(asin,atanh,expm1,sinh,tan)
  3226:     //      SGL,DBLでないときはy=xまで上げる
  3227:     //      RPのときはy=xの上まで上げる
  3228:     public final EFP originLowerLower (EFP x) {
  3229:       if (x.flg << 1 == 0 && x.epp < -16) {  //0<|x|<2^-16
  3230:         if (x.flg < 0) {  //x<0でy=xよりも下(y=-Infとy=xの間)にあるもの
  3231:           if (epbRoundingPrec != EPB_PREC_SGL && epbRoundingPrec != EPB_PREC_DBL) {
  3232:             if (this.gt (x)) {
  3233:               //SGL,DBLでないときはy=xまで下げる
  3234:               this.sete (x).finish ();
  3235:             }
  3236:           }
  3237:           if (epbRoundingMode == EPB_MODE_RM) {
  3238:             if (this.ge (x)) {
  3239:               //RMのときはy=xの下まで下げる
  3240:               this.nextdown (x, epbRoundingPrec);
  3241:             }
  3242:           }
  3243:         } else {  //0<xでy=xよりも下(y=0とy=xの間)にあるもの
  3244:           if (epbRoundingPrec != EPB_PREC_SGL && epbRoundingPrec != EPB_PREC_DBL) {
  3245:             if (this.gt (x)) {
  3246:               //SGL,DBLでないときはy=xまで下げる
  3247:               this.sete (x).finish ();
  3248:             }
  3249:           }
  3250:           if (epbRoundingMode == EPB_MODE_RZ || epbRoundingMode == EPB_MODE_RM) {
  3251:             if (this.ge (x)) {
  3252:               //RZ,RMのときはy=xの下まで下げる
  3253:               this.nextdown (x, epbRoundingPrec);
  3254:             }
  3255:           }
  3256:         }
  3257:       }
  3258:       return this;
  3259:     }  //originLowerLower(EFP)
  3260:     public final EFP originLowerUpper (EFP x) {
  3261:       if (x.flg << 1 == 0 && x.epp < -16) {  //0<|x|<2^-16
  3262:         if (x.flg < 0) {  //x<0でy=xよりも下(y=-Infとy=xの間)にあるもの
  3263:           if (epbRoundingPrec != EPB_PREC_SGL && epbRoundingPrec != EPB_PREC_DBL) {
  3264:             if (this.gt (x)) {
  3265:               //SGL,DBLでないときはy=xまで下げる
  3266:               this.sete (x).finish ();
  3267:             }
  3268:           }
  3269:           if (epbRoundingMode == EPB_MODE_RM) {
  3270:             if (this.ge (x)) {
  3271:               //RMのときはy=xの下まで下げる
  3272:               this.nextdown (x, epbRoundingPrec);
  3273:             }
  3274:           }
  3275:         } else {  //0<xでy=xよりも上(y=xとy=+Infの間)にあるもの
  3276:           if (epbRoundingPrec != EPB_PREC_SGL && epbRoundingPrec != EPB_PREC_DBL) {
  3277:             if (this.lt (x)) {
  3278:               //SGL,DBLでないときはy=xまで上げる
  3279:               this.sete (x).finish ();
  3280:             }
  3281:           }
  3282:           if (epbRoundingMode == EPB_MODE_RP) {
  3283:             if (this.le (x)) {
  3284:               //RPのときはy=xの上まで上げる
  3285:               this.nextup (x, epbRoundingPrec);
  3286:             }
  3287:           }
  3288:         }
  3289:       }
  3290:       return this;
  3291:     }  //originLowerUpper(EFP)
  3292:     public final EFP originUpperLower (EFP x) {
  3293:       if (x.flg << 1 == 0 && x.epp < -16) {  //0<|x|<2^-16
  3294:         if (x.flg < 0) {  //x<0でy=xよりも上(y=0とy=xの間)にあるもの
  3295:           if (epbRoundingPrec != EPB_PREC_SGL && epbRoundingPrec != EPB_PREC_DBL) {
  3296:             if (this.lt (x)) {
  3297:               //SGL,DBLでないときはy=xまで上げる
  3298:               this.sete (x).finish ();
  3299:             }
  3300:           }
  3301:           if (epbRoundingMode == EPB_MODE_RZ || epbRoundingMode == EPB_MODE_RP) {
  3302:             if (this.le (x)) {
  3303:               //RZ,RPのときはy=xの上まで上げる
  3304:               this.nextup (x, epbRoundingPrec);
  3305:             }
  3306:           }
  3307:         } else {  //0<xでy=xよりも下(y=0とy=xの間)にあるもの
  3308:           if (epbRoundingPrec != EPB_PREC_SGL && epbRoundingPrec != EPB_PREC_DBL) {
  3309:             if (this.gt (x)) {
  3310:               //SGL,DBLでないときはy=xまで下げる
  3311:               this.sete (x).finish ();
  3312:             }
  3313:           }
  3314:           if (epbRoundingMode == EPB_MODE_RZ || epbRoundingMode == EPB_MODE_RM) {
  3315:             if (this.ge (x)) {
  3316:               //RZ,RMのときはy=xの下まで下げる
  3317:               this.nextdown (x, epbRoundingPrec);
  3318:             }
  3319:           }
  3320:         }
  3321:       }
  3322:       return this;
  3323:     }  //originUpperLower(EFP)
  3324:     public final EFP originUpperUpper (EFP x) {
  3325:       if (x.flg << 1 == 0 && x.epp < -16) {  //0<|x|<2^-16
  3326:         if (x.flg < 0) {  //x<0でy=xよりも上(y=0とy=xの間)にあるもの
  3327:           if (epbRoundingPrec != EPB_PREC_SGL && epbRoundingPrec != EPB_PREC_DBL) {
  3328:             if (this.lt (x)) {
  3329:               //SGL,DBLでないときはy=xまで上げる
  3330:               this.sete (x).finish ();
  3331:             }
  3332:           }
  3333:           if (epbRoundingMode == EPB_MODE_RZ || epbRoundingMode == EPB_MODE_RP) {
  3334:             if (this.le (x)) {
  3335:               //RZ,RPのときはy=xの上まで上げる
  3336:               this.nextup (x, epbRoundingPrec);
  3337:             }
  3338:           }
  3339:         } else {  //0<xでy=xよりも上(y=xとy=+Infの間)にあるもの
  3340:           if (epbRoundingPrec != EPB_PREC_SGL && epbRoundingPrec != EPB_PREC_DBL) {
  3341:             if (this.lt (x)) {
  3342:               //SGL,DBLでないときはy=xまで上げる
  3343:               this.sete (x).finish ();
  3344:             }
  3345:           }
  3346:           if (epbRoundingMode == EPB_MODE_RP) {
  3347:             if (this.le (x)) {
  3348:               //RPのときはy=xの上まで上げる
  3349:               this.nextup (x, epbRoundingPrec);
  3350:             }
  3351:           }
  3352:         }
  3353:       }
  3354:       return this;
  3355:     }  //originUpperUpper(EFP)
  3356: 
  3357:     //this = this.correctUnderflow (savedFpsr)
  3358:     //  非正規化数のときUFをセット、正規化数のときUFをクリアする
  3359:     public final EFP correctUnderflow (int savedFpsr) {
  3360:       if (this.flg << 1 == 0) {
  3361:         if (this.epp < (epbRoundingPrec == EPB_PREC_SGL ? -126 :
  3362:                         epbRoundingPrec == EPB_PREC_DBL || epbRoundingPrec == EPB_PREC_DBL3 ? -1022 :
  3363:                         -16383)) {  //非正規化数のとき
  3364:           epbFpsr |= EPB_FPSR_UF;  //UFをセット
  3365:         } else {  //正規化数のとき
  3366:           epbFpsr = epbFpsr & ~EPB_FPSR_UF | savedFpsr & EPB_FPSR_UF;  //UFをクリア
  3367:         }
  3368:       }
  3369:       return this;
  3370:     }  //correctUnderflow(int)
  3371: 
  3372:     //------------------------------------------------------------------------
  3373:     //x = x.abs ()
  3374:     //  x=|x|
  3375:     //y = y.abs (x)
  3376:     //  y=|x|
  3377:     //  絶対値関数 absolute value function アブソリュートバリューファンクション
  3378:     //
  3379:     //  グラフ
  3380:     //    perl -e "use Graph;$g=new Graph();$g->grid();$g->func(sub{abs($_[0])});print$g"
  3381:     //    echo read("efp.gp");graph(abs) | gp -q
  3382:     //    **--------+---------+---------+---------+---------+---------+---------+--------**
  3383:     //    |***                                    |                                    ***|
  3384:     //    |  ***                                  |                                  ***  |
  3385:     //    |    ***                                |                                ***    |
  3386:     //    |      ***                              |                              ***      |
  3387:     //    +        ***                            +                            ***        +
  3388:     //    |          ***                          |                          ***          |
  3389:     //    |            ***                        |                        ***            |
  3390:     //    |              ***                      |                      ***              |
  3391:     //    |                ***                    |                    ***                |
  3392:     //    +                  ***                  +                  ***                  +
  3393:     //    |                    ***                |                ***                    |
  3394:     //    |                      ***              |              ***                      |
  3395:     //    |                        ***            |            ***                        |
  3396:     //    |                          ***          |          ***                          |
  3397:     //    +                            ***        +        ***                            +
  3398:     //    |                              ***      |      ***                              |
  3399:     //    |                                ***    |    ***                                |
  3400:     //    |                                  ***  |  ***                                  |
  3401:     //    |                                    ***|***                                    |
  3402:     //    +---------+---------+---------+--------***--------+---------+---------+---------+
  3403:     //    |                                       |                                       |
  3404:     //    |                                       |                                       |
  3405:     //    |                                       |                                       |
  3406:     //    |                                       |                                       |
  3407:     //    +                                       +                                       +
  3408:     //    |                                       |                                       |
  3409:     //    |                                       |                                       |
  3410:     //    |                                       |                                       |
  3411:     //    |                                       |                                       |
  3412:     //    +                                       +                                       +
  3413:     //    |                                       |                                       |
  3414:     //    |                                       |                                       |
  3415:     //    |                                       |                                       |
  3416:     //    |                                       |                                       |
  3417:     //    +                                       +                                       +
  3418:     //    |                                       |                                       |
  3419:     //    |                                       |                                       |
  3420:     //    |                                       |                                       |
  3421:     //    |                                       |                                       |
  3422:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
  3423:     //
  3424:     //  定義域
  3425:     //    -inf<=x<=inf
  3426:     //
  3427:     //  値域
  3428:     //    0<=y<=inf
  3429:     //
  3430:     public final EFP abs () {
  3431:       return this.finish (this.flg & ~M, this.epp, this.dvl, this.cvl, 0L);
  3432:     }  //efp.abs()
  3433:     public final EFP iabs () {
  3434:       this.flg &= ~M;  //NaNでも問題ない
  3435:       return this;
  3436:     }  //efp.abs()
  3437:     public final EFP abs (EFP x) {
  3438:       return this.finish (x.flg & ~M, x.epp, x.dvl, x.cvl, 0L);
  3439:     }  //efp.abs(EFP)
  3440:     public final EFP iabs (EFP x) {
  3441:       this.flg = x.flg & ~M;  //NaNでも問題ない
  3442:       this.epp = x.epp;
  3443:       this.dvl = x.dvl;
  3444:       this.cvl = x.cvl;
  3445:       return this;
  3446:     }  //efp.abs(EFP)
  3447: 
  3448:     //------------------------------------------------------------------------
  3449:     //x = x.acos ()
  3450:     //  x=acos(x)
  3451:     //y = y.acos (x)
  3452:     //  y=acos(x)
  3453:     //  逆余弦 inverse cosine インバースコサイン
  3454:     //
  3455:     //  グラフ
  3456:     //    perl -e "use Math::Trig;use Graph;$g=new Graph();$g->grid();$g->func(sub{acos($_[0])});print$g"
  3457:     //    echo read("efp.gp");graph(acos) | gp -q
  3458:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
  3459:     //    |                                       |                                       |
  3460:     //    |                                       |                                       |
  3461:     //    |                                       |                                       |
  3462:     //    |                             *         |                                       |
  3463:     //    +                             *         +                                       +
  3464:     //    |                             **        |                                       |
  3465:     //    |                              **       |                                       |
  3466:     //    |                               **      |                                       |
  3467:     //    |                                ***    |                                       |
  3468:     //    +                                  ***  +                                       +
  3469:     //    |                                    ***|                                       |
  3470:     //    |                                      ***                                      |
  3471:     //    |                                       |***                                    |
  3472:     //    |                                       |  ***                                  |
  3473:     //    +                                       +    **                                 +
  3474:     //    |                                       |     ***                               |
  3475:     //    |                                       |       **                              |
  3476:     //    |                                       |        **                             |
  3477:     //    |                                       |         *                             |
  3478:     //    +---------+---------+---------+---------+---------*---------+---------+---------+
  3479:     //    |                                       |                                       |
  3480:     //    |                                       |                                       |
  3481:     //    |                                       |                                       |
  3482:     //    |                                       |                                       |
  3483:     //    +                                       +                                       +
  3484:     //    |                                       |                                       |
  3485:     //    |                                       |                                       |
  3486:     //    |                                       |                                       |
  3487:     //    |                                       |                                       |
  3488:     //    +                                       +                                       +
  3489:     //    |                                       |                                       |
  3490:     //    |                                       |                                       |
  3491:     //    |                                       |                                       |
  3492:     //    |                                       |                                       |
  3493:     //    +                                       +                                       +
  3494:     //    |                                       |                                       |
  3495:     //    |                                       |                                       |
  3496:     //    |                                       |                                       |
  3497:     //    |                                       |                                       |
  3498:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
  3499:     //
  3500:     //  定義域
  3501:     //    -1<=x<=1
  3502:     //
  3503:     //  値域
  3504:     //    0<=y<=pi
  3505:     //
  3506:     //  逆三角関数との関係
  3507:     //    acos(x)=atan2(sqrt(1-x^2),x)
  3508:     //           =atan(sqrt(1-x^2)/x)
  3509:     //           =pi/2-asin(x)
  3510:     //           =pi/2-atan2(x,sqrt(1-x^2))
  3511:     //           =pi/2-atan(x/sqrt(1-x^2))
  3512:     //
  3513:     //  テイラー展開
  3514:     //    asinのテイラー展開を参照
  3515:     //    acos(x)=pi/2-asin(x)
  3516:     //           =pi/2-sum[m=0..inf]{prod[k=0..m-1]{2*k+1}/2^m/m!/(2*m+1)*x^(2*m+1)}
  3517:     //           =pi/2-(1/1/1*x^1+(1)/(2)/3*x^3+(1*3)/(2*4)/5*x^5+(1*3*5)/(2*4*6)/7*x^7+(1*3*5*7)/(2*4*6*8)/9*x^9+...)
  3518:     //           =pi/2-x-1/6*x^3-3/40*x^5-5/112*x^7-35/1152*x^9-...
  3519:     //    > coeff(sub(a=0,for n:=0:10 sum sub(x=a,df(acos(x),x,n))/factorial(n)*(x-a)^n),x);
  3520:     //      pi         - 1      - 3      - 5      - 35
  3521:     //    {----,-1,0,------,0,------,0,------,0,-------}
  3522:     //      2          6        40      112      1152
  3523:     //
  3524:     //  pi/2-asin(x)で求める方法
  3525:     //    浮動小数点数の場合、x=1-εで桁落ちが発生して精度が低くなるので工夫が必要
  3526:     //
  3527:     public final EFP acos () {
  3528:       return this.acos (this);
  3529:     }  //efp.acos()
  3530:     public final EFP acos (EFP x) {
  3531:       //return this.asin (x).negsub (PI_2);  //pi/2-asin(x)。x=1-εのとき桁落ちが発生するため精度が低い
  3532:       int xf = x.flg;
  3533:       if (xf << 1 != 0) {  //±0,±Inf,NaN
  3534:         if (xf << 1 < 0) {  //±0
  3535:           epbFpsr |= EPB_FPSR_X2;  //不正確な結果
  3536:           this.sete (ROUNDED_PI_2[epbRoundingMode]).finish ();  //acos(±0)=pi/2
  3537:         } else if (xf << 2 < 0) {  //±Inf
  3538:           epbFpsr |= EPB_FPSR_OE;
  3539:           epbExceptionOperandExponent = xf & M | 0x7fff << 16;
  3540:           epbExceptionOperandMantissa = 0x0000000000000000L;
  3541:           this.flg = N;  //acos(±Inf)=NaN
  3542:         } else {  //NaN
  3543:           this.flg = N;  //acos(NaN)=NaN
  3544:         }
  3545:         return this;
  3546:       }
  3547:       //±0,±Inf,NaN以外
  3548:       int xe = x.epp;
  3549:       if (xe >= 0) {  //|x|>=1
  3550:         if (xe == 0 && x.dvl == MSB && x.cvl == 0L) {  //|x|==1
  3551:           if (xf >= 0) {
  3552:             this.flg = P | Z;  //acos(+1)=+0
  3553:           } else {
  3554:             epbFpsr |= EPB_FPSR_X2;  //不正確な結果
  3555:             this.sete (ROUNDED_PI[epbRoundingMode]).finish ();  //acos(-1)=pi
  3556:           }
  3557:         } else {  //1<|x|
  3558:           epbFpsr |= EPB_FPSR_OE;
  3559:           epbExceptionOperandExponent = xf | 0x3fff + xe << 16;
  3560:           epbExceptionOperandMantissa = x.dvl;
  3561:           this.flg = N;
  3562:         }
  3563:         return this;
  3564:       }
  3565:       //|x|<1
  3566:       if (this == x) {
  3567:         x = new EFP (x);
  3568:       }
  3569:       return this.inner ().negdec (x).imul (new EFP ().inc (x)).sqrt ().outer ().atan2 (x);  //atan2(sqrt((1-x)*(1+x)),x) [91]
  3570:     }  //efp.acos(EFP)
  3571: 
  3572:     //------------------------------------------------------------------------
  3573:     //x = x.acosh ()
  3574:     //  x=acosh(x)
  3575:     //y = y.acosh (x)
  3576:     //  y=acosh(x)
  3577:     //  逆双曲線余弦 inverse hyperbolic cosine インバースハイパボリックコサイン
  3578:     //
  3579:     //  グラフ
  3580:     //    perl -e "use Math::Trig;use Graph;$g=new Graph();$g->grid();$g->func(sub{acosh($_[0])});print$g"
  3581:     //    echo read("efp.gp");graph(acosh) | gp -q
  3582:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
  3583:     //    |                                       |                                       |
  3584:     //    |                                       |                                       |
  3585:     //    |                                       |                                       |
  3586:     //    |                                       |                                       |
  3587:     //    +                                       +                                       +
  3588:     //    |                                       |                                       |
  3589:     //    |                                       |                                       |
  3590:     //    |                                       |                                       |
  3591:     //    |                                       |                                       |
  3592:     //    +                                       +                                 *******
  3593:     //    |                                       |                           *******     |
  3594:     //    |                                       |                       *****           |
  3595:     //    |                                       |                   *****               |
  3596:     //    |                                       |                ****                   |
  3597:     //    +                                       +             ****                      +
  3598:     //    |                                       |            **                         |
  3599:     //    |                                       |          ***                          |
  3600:     //    |                                       |         **                            |
  3601:     //    |                                       |         *                             |
  3602:     //    +---------+---------+---------+---------+---------*---------+---------+---------+
  3603:     //    |                                       |                                       |
  3604:     //    |                                       |                                       |
  3605:     //    |                                       |                                       |
  3606:     //    |                                       |                                       |
  3607:     //    +                                       +                                       +
  3608:     //    |                                       |                                       |
  3609:     //    |                                       |                                       |
  3610:     //    |                                       |                                       |
  3611:     //    |                                       |                                       |
  3612:     //    +                                       +                                       +
  3613:     //    |                                       |                                       |
  3614:     //    |                                       |                                       |
  3615:     //    |                                       |                                       |
  3616:     //    |                                       |                                       |
  3617:     //    +                                       +                                       +
  3618:     //    |                                       |                                       |
  3619:     //    |                                       |                                       |
  3620:     //    |                                       |                                       |
  3621:     //    |                                       |                                       |
  3622:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
  3623:     //
  3624:     //  定義域
  3625:     //    1<=x<=inf
  3626:     //
  3627:     //  値域
  3628:     //    0<=y<=inf
  3629:     //
  3630:     //  対数関数との関係
  3631:     //    acosh(x)=log(x+sqrt(x^2-1))
  3632:     //            =log1p(x-1+sqrt((x-1)*(x+1)))
  3633:     //            =log1p(x-1+sqrt((x-1)^2+2*(x-1)))
  3634:     //      x^2-1=(x-1+1)^2-1
  3635:     //           =(x-1)^2+2*(x-1)+1-1
  3636:     //           =(x-1)^2+2*(x-1)
  3637:     //      acoshの定義域は1<=xなのでx-1で誤差が増えることはない
  3638:     //
  3639:     public final EFP acosh () {
  3640:       return this.acosh (this);
  3641:     }  //efp.acosh()
  3642:     public final EFP acosh (EFP x) {
  3643:       int xf = x.flg;
  3644:       if (xf != 0) {  //-x,±0,±Inf,NaN
  3645:         if (xf < 0 || xf << 1 < 0) {  //-x,±0,-Inf
  3646:           epbFpsr |= EPB_FPSR_OE;
  3647:           if (xf << 1 < 0) {  //±0
  3648:             epbExceptionOperandExponent = xf & M;
  3649:             epbExceptionOperandMantissa = 0x0000000000000000L;
  3650:           } else if (xf == (M | I)) {  //-Inf
  3651:             epbExceptionOperandExponent = M | 0x7fff << 16;
  3652:             epbExceptionOperandMantissa = 0x0000000000000000L;
  3653:           } else {  //-x
  3654:             epbExceptionOperandExponent = M | 0x3fff + x.epp << 16;
  3655:             epbExceptionOperandMantissa = x.dvl;
  3656:           }
  3657:           this.flg = N;  //acosh(-x)=acosh(-Inf)=acosh(±0)=NaN
  3658:         } else {
  3659:           this.flg = xf == (P | I) ? P | I : N;  //acosh(+Inf)=+Inf, acosh(NaN)=NaN
  3660:         }
  3661:         return this;
  3662:       }
  3663:       //±0,±Inf,NaN以外
  3664:       if (x.epp < 0) {  //0<x<1
  3665:         epbFpsr |= EPB_FPSR_OE;
  3666:         epbExceptionOperandExponent = 0x3fff + x.epp << 16;
  3667:         epbExceptionOperandMantissa = x.dvl;
  3668:         this.flg = N;  //acosh(|x|<1)=NaN
  3669:         return this;
  3670:       }
  3671:       //1<=|x|
  3672:       return this.inner ().dec (x).iadd (new EFP ().isqu (this).iadd (new EFP ().imul2 (this)).sqrt ()).outer ().log1p ();  //log1p(x-1+sqrt((x-1)^2+2*(x-1)))
  3673:     }  //efp.acosh(EFP)
  3674: 
  3675:     //------------------------------------------------------------------------
  3676:     //x = x.acot ()
  3677:     //  x=acot(x)
  3678:     //y = y.acot (x)
  3679:     //  y=acot(x)
  3680:     //  逆余接 inverse cotangent インバースコタンジェント
  3681:     //
  3682:     //  グラフ
  3683:     //    perl -e "use Math::Trig;use Graph;$g=new Graph();$g->grid();$g->func(sub{acot($_[0])});print$g"
  3684:     //    echo read("efp.gp");eval("acot(x)=atan(1/x)");graph(acot) | gp -q
  3685:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
  3686:     //    |                                       |                                       |
  3687:     //    |                                       |                                       |
  3688:     //    |                                       |                                       |
  3689:     //    |                                       |                                       |
  3690:     //    +                                       +                                       +
  3691:     //    |                                       |                                       |
  3692:     //    |                                       |                                       |
  3693:     //    |                                       |                                       |
  3694:     //    |                                       |                                       |
  3695:     //    +                                       +                                       +
  3696:     //    |                                       |                                       |
  3697:     //    |                                       **                                      |
  3698:     //    |                                       |***                                    |
  3699:     //    |                                       |  ***                                  |
  3700:     //    +                                       +    ****                               +
  3701:     //    |                                       |       *****                           |
  3702:     //    |                                       |           *******                     |
  3703:     //    |                                       |                 ***************       |
  3704:     //    |                                       |                               *********
  3705:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
  3706:     //    *********                               |                                       |
  3707:     //    |       ***************                 |                                       |
  3708:     //    |                     *******           |                                       |
  3709:     //    |                           *****       |                                       |
  3710:     //    +                               ****    +                                       +
  3711:     //    |                                  ***  |                                       |
  3712:     //    |                                    ***|                                       |
  3713:     //    |                                      **                                       |
  3714:     //    |                                       |                                       |
  3715:     //    +                                       +                                       +
  3716:     //    |                                       |                                       |
  3717:     //    |                                       |                                       |
  3718:     //    |                                       |                                       |
  3719:     //    |                                       |                                       |
  3720:     //    +                                       +                                       +
  3721:     //    |                                       |                                       |
  3722:     //    |                                       |                                       |
  3723:     //    |                                       |                                       |
  3724:     //    |                                       |                                       |
  3725:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
  3726:     //
  3727:     //  定義域
  3728:     //    inf<=x<0
  3729:     //    0<x<=inf
  3730:     //
  3731:     //  値域
  3732:     //    -pi/2<=y<0
  3733:     //    0<y<=pi/2
  3734:     //
  3735:     //  逆三角関数との関係
  3736:     //    acot(x)=atan2(1/x,1)
  3737:     //           =atan(1/x)
  3738:     //
  3739:     public final EFP acot () {
  3740:       return this.acot (this);
  3741:     }  //efp.acot()
  3742:     public final EFP acot (EFP x) {
  3743:       return this.inner ().rcp (x).outer ().atan ();  //atan(1/x)
  3744:     }  //efp.acot(EFP)
  3745: 
  3746:     //------------------------------------------------------------------------
  3747:     //x = x.acoth ()
  3748:     //  x=acoth(x)
  3749:     //y = y.acoth (x)
  3750:     //  y=acoth(x)
  3751:     //  逆双曲線余接 inverse hyperbolic cotangent インバースハイパボリックコタンジェント
  3752:     //
  3753:     //  グラフ
  3754:     //    perl -e "use Math::Trig;use Graph;$g=new Graph();$g->grid();$g->func(sub{acoth($_[0])});print$g"
  3755:     //    echo read("efp.gp");eval("acoth(x)=log((x+1)/(x-1))/2");graph(acoth) | gp -q
  3756:     //    +---------+---------+---------+---------+---------*---------+---------+---------+
  3757:     //    |                                       |         *                             |
  3758:     //    |                                       |         *                             |
  3759:     //    |                                       |         *                             |
  3760:     //    |                                       |         *                             |
  3761:     //    +                                       +         *                             +
  3762:     //    |                                       |         *                             |
  3763:     //    |                                       |         *                             |
  3764:     //    |                                       |         *                             |
  3765:     //    |                                       |         *                             |
  3766:     //    +                                       +         *                             +
  3767:     //    |                                       |         **                            |
  3768:     //    |                                       |          *                            |
  3769:     //    |                                       |          **                           |
  3770:     //    |                                       |           *                           |
  3771:     //    +                                       +           ***                         +
  3772:     //    |                                       |             ****                      |
  3773:     //    |                                       |                ******                 |
  3774:     //    |                                       |                     *************     |
  3775:     //    |                                       |                                 *******
  3776:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
  3777:     //    *******                                 |                                       |
  3778:     //    |     *************                     |                                       |
  3779:     //    |                 ******                |                                       |
  3780:     //    |                      ****             |                                       |
  3781:     //    +                         ***           +                                       +
  3782:     //    |                           *           |                                       |
  3783:     //    |                           **          |                                       |
  3784:     //    |                            *          |                                       |
  3785:     //    |                            **         |                                       |
  3786:     //    +                             *         +                                       +
  3787:     //    |                             *         |                                       |
  3788:     //    |                             *         |                                       |
  3789:     //    |                             *         |                                       |
  3790:     //    |                             *         |                                       |
  3791:     //    +                             *         +                                       +
  3792:     //    |                             *         |                                       |
  3793:     //    |                             *         |                                       |
  3794:     //    |                             *         |                                       |
  3795:     //    |                             *         |                                       |
  3796:     //    +---------+---------+---------*---------+---------+---------+---------+---------+
  3797:     //
  3798:     //  定義域
  3799:     //    inf<=x<-1
  3800:     //    1<x<=inf
  3801:     //
  3802:     //  値域
  3803:     //    -inf<=y<0
  3804:     //    0<y<=inf
  3805:     //
  3806:     //  対数関数との関係
  3807:     //    acoth(x)=log((x+1)/(x-1))/2
  3808:     //            =log(sqrt((x+1)/(x-1)))
  3809:     //            =log(sqrt(x+1)/sqrt(x-1))
  3810:     //
  3811:     public final EFP acoth () {
  3812:       return this.acoth (this);
  3813:     }  //efp.acoth()
  3814:     public final EFP acoth (EFP x) {
  3815:       int xf = x.flg;
  3816:       if (xf << 1 != 0) {  //±0,±Inf,NaN
  3817:         if (xf << 1 < 0) {  //±0
  3818:           epbFpsr |= EPB_FPSR_OE;
  3819:           epbExceptionOperandExponent = xf & M;
  3820:           epbExceptionOperandMantissa = 0x0000000000000000L;
  3821:           this.flg = N;  //acoth(±0)=NaN
  3822:         } else {
  3823:           this.flg = xf << 2 < 0 ? xf ^ (Z | I) : N;  //acoth(±Inf)=±0, acoth(NaN)=NaN
  3824:         }
  3825:         return this;
  3826:       }
  3827:       //±0,±Inf,NaN以外
  3828:       if (x.epp < 0) {  //|x|<1
  3829:         epbFpsr |= EPB_FPSR_OE;
  3830:         epbExceptionOperandExponent = xf | 0x3fff + x.epp << 16;
  3831:         epbExceptionOperandMantissa = x.dvl;
  3832:         this.flg = N;  //acoth(|x|<1)=NaN
  3833:         return this;
  3834:       }
  3835:       if (x.epp == 0 && x.dvl == MSB && x.cvl == 0L) {  //|x|==1
  3836:         epbFpsr |= EPB_FPSR_DZ;
  3837:         epbExceptionOperandExponent = xf & M | 0x3fff << 16;
  3838:         epbExceptionOperandMantissa = 0x8000000000000000L;
  3839:         this.flg = xf | I;  //acoth(±1)=±Inf
  3840:         return this;
  3841:       }
  3842:       //1<|x|
  3843:       return this.inner ().iabs (x).dec ().rcp ().imul2 ().log1p ().idiv2 ().outer ().neg (xf < 0);  //sgn(x)*log(1+2/(|x|-1))/2
  3844:     }  //efp.acoth(EFP)
  3845: 
  3846:     //------------------------------------------------------------------------
  3847:     //x = x.acsc ()
  3848:     //  x=acsc(x)
  3849:     //y = y.acsc (x)
  3850:     //  y=acsc(x)
  3851:     //  逆余割 inverse cosecant インバースコセカント
  3852:     //
  3853:     //  グラフ
  3854:     //    perl -e "use Math::Trig;use Graph;$g=new Graph();$g->grid();$g->func(sub{acsc($_[0])});print$g"
  3855:     //    echo read("efp.gp");eval("acsc(x)=sign(x)*atan(1/sqrt((x-1)*(x+1)))");graph(acsc) | gp -q
  3856:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
  3857:     //    |                                       |                                       |
  3858:     //    |                                       |                                       |
  3859:     //    |                                       |                                       |
  3860:     //    |                                       |                                       |
  3861:     //    +                                       +                                       +
  3862:     //    |                                       |                                       |
  3863:     //    |                                       |                                       |
  3864:     //    |                                       |                                       |
  3865:     //    |                                       |                                       |
  3866:     //    +                                       +                                       +
  3867:     //    |                                       |                                       |
  3868:     //    |                                       |         *                             |
  3869:     //    |                                       |         *                             |
  3870:     //    |                                       |         **                            |
  3871:     //    +                                       +          ***                          +
  3872:     //    |                                       |            ****                       |
  3873:     //    |                                       |               ******                  |
  3874:     //    |                                       |                    **************     |
  3875:     //    |                                       |                                 *******
  3876:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
  3877:     //    *******                                 |                                       |
  3878:     //    |     **************                    |                                       |
  3879:     //    |                  ******               |                                       |
  3880:     //    |                       ****            |                                       |
  3881:     //    +                          ***          +                                       +
  3882:     //    |                            **         |                                       |
  3883:     //    |                             *         |                                       |
  3884:     //    |                             *         |                                       |
  3885:     //    |                                       |                                       |
  3886:     //    +                                       +                                       +
  3887:     //    |                                       |                                       |
  3888:     //    |                                       |                                       |
  3889:     //    |                                       |                                       |
  3890:     //    |                                       |                                       |
  3891:     //    +                                       +                                       +
  3892:     //    |                                       |                                       |
  3893:     //    |                                       |                                       |
  3894:     //    |                                       |                                       |
  3895:     //    |                                       |                                       |
  3896:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
  3897:     //
  3898:     //  定義域
  3899:     //    inf<=x<=-1
  3900:     //    1<=x<=inf
  3901:     //
  3902:     //  値域
  3903:     //    -pi/2<=y<0
  3904:     //    0<y<=pi/2
  3905:     //
  3906:     //  逆三角関数との関係
  3907:     //    acsc(x)=atan2(1/x,sqrt(1-1/x^2))
  3908:     //           =atan2(sgn(x),sqrt(x^2-1))
  3909:     //           =sgn(x)*atan2(1,sqrt(x^2-1))
  3910:     //           =sgn(x)*atan(1/sqrt(x^2-1))
  3911:     //           =sgn(x)*atan(1/sqrt((x-1)*(x+1)))
  3912:     //           =asin(1/x)
  3913:     //
  3914:     public final EFP acsc () {
  3915:       return this.acsc (this);
  3916:     }  //efp.acsc()
  3917:     public final EFP acsc (EFP x) {
  3918:       int xf = x.flg;
  3919:       if (xf << 1 != 0) {  //±0,±Inf,NaN
  3920:         if (xf << 1 < 0) {  //±0
  3921:           epbFpsr |= EPB_FPSR_OE;
  3922:           epbExceptionOperandExponent = xf & M;
  3923:           epbExceptionOperandMantissa = 0x0000000000000000L;
  3924:           this.flg = N;  //acsc(±0)=NaN
  3925:         } else {
  3926:           this.flg = xf << 2 < 0 ? xf ^ (Z | I) : N;  //acsc(±Inf)=±0, acsc(NaN)=NaN
  3927:         }
  3928:         return this;
  3929:       }
  3930:       //±0,±Inf,NaN以外
  3931:       if (x.epp < 0) {  //|x|<1
  3932:         epbFpsr |= EPB_FPSR_OE;
  3933:         epbExceptionOperandExponent = xf | 0x3fff + x.epp << 16;
  3934:         epbExceptionOperandMantissa = x.dvl;
  3935:         this.flg = N;  //acsc(|x|<1)=NaN
  3936:         return this;
  3937:       }
  3938:       if (x.epp == 0 && x.dvl == MSB && x.cvl == 0L) {  //|x|==1
  3939:         epbFpsr |= EPB_FPSR_X2;  //不正確な結果
  3940:         if (xf >= 0) {
  3941:           this.sete (ROUNDED_PI_2[epbRoundingMode]).finish ();  //acsc(1)=pi/2
  3942:         } else {
  3943:           this.sete (ROUNDED_NEGPI_2[epbRoundingMode]).finish ();  //acsc(-1)=-pi/2
  3944:         }
  3945:         return this;
  3946:       }
  3947:       //1<|x|
  3948:       EFP t = new EFP ().inner ().inc (x);
  3949:       return this.dec (x).imul (t).sqrt ().rcp ().atan ().outer ().neg (xf < 0);  //sgn(x)*atan(1/sqrt((x-1)*(x+1)))
  3950:     }  //efp.acsc(EFP)
  3951: 
  3952:     //------------------------------------------------------------------------
  3953:     //x = x.acsch ()
  3954:     //  x=acsch(x)
  3955:     //y = y.acsch (x)
  3956:     //  y=acsch(x)
  3957:     //  逆双曲線余割 inverse hyperbolic cosecant インバースハイパボリックコセカント
  3958:     //
  3959:     //  グラフ
  3960:     //    perl -e "use Math::Trig;use Graph;$g=new Graph();$g->grid();$g->func(sub{acsch($_[0])});print$g"
  3961:     //    echo read("efp.gp");eval("acsch(x)=log(1/x+sqrt(1/x^2+1))");graph(acsch) | gp -q
  3962:     //    +---------+---------+---------+---------*---------+---------+---------+---------+
  3963:     //    |                                       *                                       |
  3964:     //    |                                       **                                      |
  3965:     //    |                                       |*                                      |
  3966:     //    |                                       |*                                      |
  3967:     //    +                                       +*                                      +
  3968:     //    |                                       |*                                      |
  3969:     //    |                                       |**                                     |
  3970:     //    |                                       | *                                     |
  3971:     //    |                                       | *                                     |
  3972:     //    +                                       + **                                    +
  3973:     //    |                                       |  **                                   |
  3974:     //    |                                       |   **                                  |
  3975:     //    |                                       |    **                                 |
  3976:     //    |                                       |     **                                |
  3977:     //    +                                       +      ****                             +
  3978:     //    |                                       |         ****                          |
  3979:     //    |                                       |            *******                    |
  3980:     //    |                                       |                  ***************      |
  3981:     //    |                                       |                                ********
  3982:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
  3983:     //    ********                                |                                       |
  3984:     //    |      ***************                  |                                       |
  3985:     //    |                    *******            |                                       |
  3986:     //    |                          ****         |                                       |
  3987:     //    +                             ****      +                                       +
  3988:     //    |                                **     |                                       |
  3989:     //    |                                 **    |                                       |
  3990:     //    |                                  **   |                                       |
  3991:     //    |                                   **  |                                       |
  3992:     //    +                                    ** +                                       +
  3993:     //    |                                     * |                                       |
  3994:     //    |                                     * |                                       |
  3995:     //    |                                     **|                                       |
  3996:     //    |                                      *|                                       |
  3997:     //    +                                      *+                                       +
  3998:     //    |                                      *|                                       |
  3999:     //    |                                      *|                                       |
  4000:     //    |                                      **                                       |
  4001:     //    |                                       *                                       |
  4002:     //    +---------+---------+---------+---------*---------+---------+---------+---------+
  4003:     //
  4004:     //  定義域
  4005:     //    inf<=x<0
  4006:     //    0<x<=inf
  4007:     //
  4008:     //  値域
  4009:     //    -inf<=y<0
  4010:     //    0<y<=inf
  4011:     //
  4012:     //  逆双曲線関数との関係
  4013:     //    acsch(x)=asinh(1/x)
  4014:     //
  4015:     //  対数関数との関係
  4016:     //    acsch(x)=log(1/x+sqrt(1/x^2+1))
  4017:     //            =log((1+sgn(x)*sqrt(1+x^2))/x)
  4018:     //            =log((sgn(x)+sqrt(1+x^2))/abs(x))
  4019:     //            =log(sgn(x)+sqrt(1+x^2))-log(abs(x))
  4020:     //
  4021:     //  テイラー展開
  4022:     //    http://mathworld.wolfram.com/InverseHyperbolicCosecant.html
  4023:     //    acsch(x)=sum[n=1..inf]{(-1)^n*pochhammer(1/2,n-1)/((2*n-1)*(n-1)!)*x^(1-2*n)}
  4024:     //            =x^-1-1/6*x^-3+3/40*x^-5-5/112*x^-7+...
  4025:     //      pochhammer(x,n)=prod[k=0..n-1]{x+k}  ポッホハマー記号
  4026:     //
  4027:     //  ピュイズー展開
  4028:     //    http://mathworld.wolfram.com/InverseHyperbolicCosecant.html
  4029:     //    acsch(x)=-log(x)+log(2)+sum[n=1..inf]{(-1)^(n+1)*(2*n-1)!!/(2*n*(2*n)!!)*x^(2*n)}
  4030:     //            =-log(x)+log(2)+1!!/(2*2!!)*x^2-3!!/(4*4!!)*x^4+5!!/(6*6!!)*x^6-...
  4031:     //            =-log(x)+log(2)+1/(2*2)*x^2-1*3/(4*2*4)*x^4+1*3*5/(6*2*4*6)*x^6-...
  4032:     //            =-log(x)+log(2)+1/4*x^2-3/32*x^4+5/96*x^6-...
  4033:     //
  4034:     //  1<xのとき
  4035:     //    sqrt(x^2+1)-x=sum[n=0..inf]{(-1)^n*catalan(n)/(2*x)^(2*n+1)}
  4036:     //                 =sum[n=0..inf]{(-1)^n*(2*n)!/(n!*(n+1)!)/(2*x)^(2*n+1)}
  4037:     //                 =1/(2*x)-1/(2*x)^3+2/(2*x)^5-5/(2*x)^7+14/(2*x)^9
  4038:     //                 -42/(2*x)^11+132/(2*x)^13-429/(2*x)^15+1430/(2*x)^17-4862/(2*x)^19
  4039:     //                 +16796/(2*x)^21-58786/(2*x)^23...
  4040:     //
  4041:     //  0<=x<1のとき
  4042:     //    sqrt(1/x^2+1)-1/x=sum[n=0..inf]{(-1)^n*catalan(n)/2^(2*n+1)*x^(2*n+1)}
  4043:     //                     =sum[n=0..inf]{(-1)^n*(2*n)!/(n!*(n+1)!)/2^(2*n+1)*x^(2*n+1)}
  4044:     //                     =1/2*x-1/2^3*x^3+2/2^5*x^5-5/2^7*x^7+14/2^9*x^9
  4045:     //                     -42/2^11*x^11+132/2^13*x^13-429/2^15*x^15+1430/2^17*x^17-4862/2^19*x^19
  4046:     //                     +16796/2^21*x^21-58786/2^23*x^23...
  4047:     //    acsch(x)=log(2/x+sum[n=0..inf]{(-1)^n*catalan(n)/2^(2*n+1)*x^(2*n+1)})
  4048:     //      ピュイズー展開の式に似ている。x→+0でlog(2/x)に近付くのだから当然か
  4049:     //
  4050:     public final EFP acsch () {
  4051:       return this.acsch (this);
  4052:     }  //efp.acsch()
  4053:     public final EFP acsch (EFP x) {
  4054:       int xf = x.flg;
  4055:       if (xf << 1 != 0) {  //±0,±Inf,NaN
  4056:         if (xf << 1 < 0) {  //±0
  4057:           epbFpsr |= EPB_FPSR_OE;
  4058:           epbExceptionOperandExponent = xf & M;
  4059:           epbExceptionOperandMantissa = 0x0000000000000000L;
  4060:           this.flg = N;  //acsch(±0)=NaN
  4061:         } else {
  4062:           this.flg = xf << 2 < 0 ? xf ^ (Z | I) : N;  //acsch(±Inf)=±0, acsc(NaN)=NaN
  4063:         }
  4064:         return this;
  4065:       }
  4066:       //±0,±Inf,NaN以外
  4067:       x = new EFP ().inner ().rcp (x);  //1/x
  4068:       if (x.epp < -1) {  //|x|<0.5
  4069:         EFP x2 = new EFP ().isqu (x);
  4070:         return this.imul (ASINH_C43, x2)
  4071:           .iadd (ASINH_C41).imul (x2)
  4072:             .iadd (ASINH_C39).imul (x2)
  4073:               .iadd (ASINH_C37).imul (x2)
  4074:                 .iadd (ASINH_C35).imul (x2)
  4075:                   .iadd (ASINH_C33).imul (x2)
  4076:                     .iadd (ASINH_C31).imul (x2)
  4077:                       .iadd (ASINH_C29).imul (x2)
  4078:                         .iadd (ASINH_C27).imul (x2)
  4079:                           .iadd (ASINH_C25).imul (x2)
  4080:                             .iadd (ASINH_C23).imul (x2)
  4081:                               .iadd (ASINH_C21).imul (x2)
  4082:                                 .iadd (ASINH_C19).imul (x2)
  4083:                                   .iadd (ASINH_C17).imul (x2)
  4084:                                     .iadd (ASINH_C15).imul (x2)
  4085:                                       .iadd (ASINH_C13).imul (x2)
  4086:                                         .iadd (ASINH_C11).imul (x2)
  4087:                                           .iadd (ASINH_C9).imul (x2)
  4088:                                             .iadd (ASINH_C7).imul (x2)
  4089:                                               .iadd (ASINH_C5).imul (x2)
  4090:                                                 .iadd (ASINH_C3).imul (x2)
  4091:                                                   .iadd (ASINH_C1).outer ().mul (x);
  4092:       }
  4093:       //0.5<=|x|
  4094:       return this.iabs (x).iadd (new EFP ().isqu (this).inc ().sqrt ()).log ().outer ().neg (xf < 0);  //sgn(x)*log(|1/x|+sqrt((|1/x|)^2+1))
  4095:     }  //efp.acsch(EFP)
  4096: 
  4097:     //------------------------------------------------------------------------
  4098:     //x = x.add (y)
  4099:     //  x+=y
  4100:     //z = z.add (x, y)
  4101:     //  z=x+y
  4102:     //  加算
  4103:     //
  4104:     //  (xn/xd)+(yn/yd)
  4105:     //    =((xn*yd)/(xd*yd))+((xd*yn)/(xd*yd))
  4106:     //    =(xn*yd+xd*yn)/(xd*yd)
  4107:     //
  4108:     public final EFP add (EFP y) {
  4109:       int xf = this.flg;
  4110:       int xe = this.epp;
  4111:       long xd = this.dvl;
  4112:       long xc = this.cvl;
  4113:       long xb = 0L;
  4114:       int yf = y.flg;
  4115:       if ((xf | yf) << 1 != 0) {  //どちらかが±0,±Inf,NaN
  4116:         if ((xf | yf) << 3 < 0) {  //どちらかがNaNのときNaN
  4117:           this.flg = N;
  4118:           return this;
  4119:         }
  4120:         if ((xf & yf) << 2 < 0 && xf != yf) {  //両方±Infで符号が逆のときNaN
  4121:           epbFpsr |= EPB_FPSR_OE;
  4122:           epbExceptionOperandExponent = yf & M | 0x7fff << 16;
  4123:           epbExceptionOperandMantissa = 0x0000000000000000L;
  4124:           this.flg = N;
  4125:           return this;
  4126:         }
  4127:         if ((xf & yf) << 1 < 0 && xf != yf) {  //両方±0で符号が逆のとき
  4128:           this.flg = epbRoundingMode == EPB_MODE_RM ? M | Z : P | Z;  //RMのとき-0,それ以外は+0
  4129:           return this;
  4130:         }
  4131:         if (xf << 1 < 0 || yf << 2 < 0) {  //xが±0またはyが±Infのときy
  4132:           xf = yf;
  4133:           xe = y.epp;
  4134:           xd = y.dvl;
  4135:           xc = y.cvl;
  4136:         }
  4137:         //xが±Infまたはyが±0のときx
  4138:       } else {  //両方±0,±Inf,NaN以外
  4139:         //加算なのでyの符号はそのまま
  4140:         long yd = y.dvl;
  4141:         long yc = y.cvl;
  4142:         int o = xe - y.epp;
  4143:         if (o < 0 || o == 0 && (xd < yd || xd == yd && xc >>> 1 < yc >>> 1)) {  //yの方が絶対値が大きい
  4144:           //xとyを入れ換える
  4145:           xf = yf;
  4146:           xe += o = -o;  //xe=y.epp
  4147:           xd = yd;
  4148:           xc = yc;
  4149:           yf = this.flg;  //後で符号を比較するときに使う
  4150:           yd = this.dvl;
  4151:           yc = this.cvl;
  4152:         }
  4153:         //xの方が絶対値が大きいか等しい
  4154:         //yを右にずらして小数点の位置を合わせる
  4155:         if (0 < o) {
  4156:           if (o <= 63) {
  4157:             xb = yc << -o;
  4158:             yc = yd << -o | yc >>> o;
  4159:             yd >>>= o;
  4160:           } else if (o == 64) {
  4161:             xb = yc;
  4162:             yc = yd;
  4163:             yd = 0L;
  4164:           } else if (o <= 127) {
  4165:             xb = yd << -o | yc;
  4166:             yc = yd >>> o;
  4167:             yd = 0L;
  4168:           } else {
  4169:             xb = yd | yc;  //絶対値減算を行うとき下位からのボローとして必要
  4170:             yc = 0L;
  4171:             yd = 0L;
  4172:           }
  4173:         }
  4174:         //絶対値加算または絶対値減算を行う
  4175:         if (xf == yf) {  //符号が同じなので絶対値加算を行う
  4176:           //yc[1]とyc[0]をsticky bitに押し出す
  4177:           xb |= yc << 62;
  4178:           //右にずらしてxd[63]を空ける
  4179:           xc = xd << 63 | xc >>> 1;
  4180:           xd >>>= 1;
  4181:           yc = yd << 63 | yc >>> 1;
  4182:           yd >>>= 1;
  4183:           //下位を右にずらしてxc[63]を空ける
  4184:           yc >>>= 1;
  4185:           xc >>>= 1;
  4186:           //足す
  4187:           xc += yc;
  4188:           xd += yd + (xc >>> 63);
  4189:           //下位を左にずらしてxc[63]を詰める
  4190:           xc <<= 1;
  4191:           //溢れの処理
  4192:           if (xd < 0L) {  //溢れたとき
  4193:             xe++;
  4194:           } else {  //溢れなかったとき
  4195:             xd = xd << 1 | xc >>> 63;  //左にずらしてxd[63]を詰める
  4196:             xc <<= 1;
  4197:           }
  4198:         } else {  //符号が異なるので絶対値減算を行う
  4199:           //yc[0]をsticky bitに押し出す
  4200:           xb |= yc << 63;
  4201:           //下位を右にずらしてxc[63]を空ける
  4202:           yc >>>= 1;
  4203:           xc >>>= 1;
  4204:           //引く
  4205:           //  xの方が絶対値が大きいか等しいので負になることはないが0になることがある
  4206:           if (xb != 0L) {
  4207:             xc--;
  4208:           }
  4209:           xc -= yc;
  4210:           xd -= yd + (xc >>> 63);
  4211:           //下位を左にずらしてxc[63]を詰める
  4212:           xc <<= 1;
  4213:           //正規化する
  4214:           if (0L <= xd) {
  4215:             if (xd != 0L) {
  4216:               xe -= o = Long.numberOfLeadingZeros (xd);
  4217:               xd = xd << o | xc >>> -o;
  4218:               xc <<= o;
  4219:             } else if (xc != 0L) {
  4220:               xe -= o = 64 + Long.numberOfLeadingZeros (xc);
  4221:               xd = xc << o;
  4222:               xc = 0L;
  4223:             } else {  //0になった
  4224:               xf = epbRoundingMode == EPB_MODE_RM ? M | Z : P | Z;  //RMのとき-0,それ以外は+0
  4225:             }
  4226:           }
  4227:         }  //if 符号が同じなので絶対値加算を行う/符号が異なるので絶対値減算を行う
  4228:       }  //if どちらかが±0,±Inf,NaN/両方±0,±Inf,NaN以外
  4229:       return this.finish (xf, xe, xd, xc, xb);
  4230:     }  //efp.add(EFP)
  4231:     public final EFP iadd (EFP y) {
  4232:       int xf = this.flg;
  4233:       int xe = this.epp;
  4234:       long xd = this.dvl;
  4235:       long xc = this.cvl;
  4236:       long xb = 0L;
  4237:       int yf = y.flg;
  4238:       if ((xf | yf) << 1 != 0) {  //どちらかが±0,±Inf,NaN
  4239:         if ((xf | yf) << 3 < 0) {  //どちらかがNaNのときNaN
  4240:           this.flg = N;
  4241:           return this;
  4242:         }
  4243:         if ((xf & yf) << 2 < 0 && xf != yf) {  //両方±Infで符号が逆のときNaN
  4244:           epbFpsr |= EPB_FPSR_OE;
  4245:           epbExceptionOperandExponent = yf & M | 0x7fff << 16;
  4246:           epbExceptionOperandMantissa = 0x0000000000000000L;
  4247:           this.flg = N;
  4248:           return this;
  4249:         }
  4250:         if ((xf & yf) << 1 < 0 && xf != yf) {  //両方±0で符号が逆のとき
  4251:           this.flg = epbRoundingMode == EPB_MODE_RM ? M | Z : P | Z;  //RMのとき-0,それ以外は+0
  4252:           return this;
  4253:         }
  4254:         if (xf << 1 < 0 || yf << 2 < 0) {  //xが±0またはyが±Infのときy
  4255:           xf = yf;
  4256:           xe = y.epp;
  4257:           xd = y.dvl;
  4258:           xc = y.cvl;
  4259:         }
  4260:         //xが±Infまたはyが±0のときx
  4261:       } else {  //両方±0,±Inf,NaN以外
  4262:         //加算なのでyの符号はそのまま
  4263:         long yd = y.dvl;
  4264:         long yc = y.cvl;
  4265:         int o = xe - y.epp;
  4266:         if (o < 0 || o == 0 && (xd < yd || xd == yd && xc >>> 1 < yc >>> 1)) {  //yの方が絶対値が大きい
  4267:           //xとyを入れ換える
  4268:           xf = yf;
  4269:           xe += o = -o;  //xe=y.epp
  4270:           xd = yd;
  4271:           xc = yc;
  4272:           yf = this.flg;  //後で符号を比較するときに使う
  4273:           yd = this.dvl;
  4274:           yc = this.cvl;
  4275:         }
  4276:         //xの方が絶対値が大きいか等しい
  4277:         //yを右にずらして小数点の位置を合わせる
  4278:         if (0 < o) {
  4279:           if (o <= 63) {
  4280:             xb = yc << -o;
  4281:             yc = yd << -o | yc >>> o;
  4282:             yd >>>= o;
  4283:           } else if (o == 64) {
  4284:             xb = yc;
  4285:             yc = yd;
  4286:             yd = 0L;
  4287:           } else if (o <= 127) {
  4288:             xb = yd << -o | yc;
  4289:             yc = yd >>> o;
  4290:             yd = 0L;
  4291:           } else {
  4292:             xb = yd | yc;  //絶対値減算を行うとき下位からのボローとして必要
  4293:             yc = 0L;
  4294:             yd = 0L;
  4295:           }
  4296:         }
  4297:         //絶対値加算または絶対値減算を行う
  4298:         if (xf == yf) {  //符号が同じなので絶対値加算を行う
  4299:           //yc[1]とyc[0]をsticky bitに押し出す
  4300:           xb |= yc << 62;
  4301:           //右にずらしてxd[63]を空ける
  4302:           xc = xd << 63 | xc >>> 1;
  4303:           xd >>>= 1;
  4304:           yc = yd << 63 | yc >>> 1;
  4305:           yd >>>= 1;
  4306:           //下位を右にずらしてxc[63]を空ける
  4307:           yc >>>= 1;
  4308:           xc >>>= 1;
  4309:           //足す
  4310:           xc += yc;
  4311:           xd += yd + (xc >>> 63);
  4312:           //下位を左にずらしてxc[63]を詰める
  4313:           xc <<= 1;
  4314:           //溢れの処理
  4315:           if (xd < 0L) {  //溢れたとき
  4316:             xe++;
  4317:           } else {  //溢れなかったとき
  4318:             xd = xd << 1 | xc >>> 63;  //左にずらしてxd[63]を詰める
  4319:             xc <<= 1;
  4320:           }
  4321:         } else {  //符号が異なるので絶対値減算を行う
  4322:           //yc[0]をsticky bitに押し出す
  4323:           xb |= yc << 63;
  4324:           //下位を右にずらしてxc[63]を空ける
  4325:           yc >>>= 1;
  4326:           xc >>>= 1;
  4327:           //引く
  4328:           //  xの方が絶対値が大きいか等しいので負になることはないが0になることがある
  4329:           if (xb != 0L) {
  4330:             xc--;
  4331:           }
  4332:           xc -= yc;
  4333:           xd -= yd + (xc >>> 63);
  4334:           //下位を左にずらしてxc[63]を詰める
  4335:           xc <<= 1;
  4336:           //正規化する
  4337:           if (0L <= xd) {
  4338:             if (xd != 0L) {
  4339:               xe -= o = Long.numberOfLeadingZeros (xd);
  4340:               xd = xd << o | xc >>> -o;
  4341:               xc <<= o;
  4342:             } else if (xc != 0L) {
  4343:               xe -= o = 64 + Long.numberOfLeadingZeros (xc);
  4344:               xd = xc << o;
  4345:               xc = 0L;
  4346:             } else {  //0になった
  4347:               xf = epbRoundingMode == EPB_MODE_RM ? M | Z : P | Z;  //RMのとき-0,それ以外は+0
  4348:             }
  4349:           }
  4350:         }  //if 符号が同じなので絶対値加算を行う/符号が異なるので絶対値減算を行う
  4351:       }  //if どちらかが±0,±Inf,NaN/両方±0,±Inf,NaN以外
  4352:       return this.ifinish (xf, xe, xd, xc, xb);
  4353:     }  //efp.iadd(EFP)
  4354:     public final EFP add (EFP x, EFP y) {
  4355:       int xf = x.flg;
  4356:       int xe = x.epp;
  4357:       long xd = x.dvl;
  4358:       long xc = x.cvl;
  4359:       long xb = 0L;
  4360:       int yf = y.flg;
  4361:       if ((xf | yf) << 1 != 0) {  //どちらかが±0,±Inf,NaN
  4362:         if ((xf | yf) << 3 < 0) {  //どちらかがNaNのときNaN
  4363:           this.flg = N;
  4364:           return this;
  4365:         }
  4366:         if ((xf & yf) << 2 < 0 && xf != yf) {  //両方±Infで符号が逆のときNaN
  4367:           epbFpsr |= EPB_FPSR_OE;
  4368:           epbExceptionOperandExponent = yf & M | 0x7fff << 16;
  4369:           epbExceptionOperandMantissa = 0x0000000000000000L;
  4370:           this.flg = N;
  4371:           return this;
  4372:         }
  4373:         if ((xf & yf) << 1 < 0 && xf != yf) {  //両方±0で符号が逆のとき
  4374:           this.flg = epbRoundingMode == EPB_MODE_RM ? M | Z : P | Z;  //RMのとき-0,それ以外は+0
  4375:           return this;
  4376:         }
  4377:         if (xf << 1 < 0 || yf << 2 < 0) {  //xが±0またはyが±Infのときy
  4378:           xf = yf;
  4379:           xe = y.epp;
  4380:           xd = y.dvl;
  4381:           xc = y.cvl;
  4382:         }
  4383:         //xが±Infまたはyが±0のときx
  4384:       } else {  //両方±0,±Inf,NaN以外
  4385:         //加算なのでyの符号はそのまま
  4386:         long yd = y.dvl;
  4387:         long yc = y.cvl;
  4388:         int o = xe - y.epp;
  4389:         if (o < 0 || o == 0 && (xd < yd || xd == yd && xc >>> 1 < yc >>> 1)) {  //yの方が絶対値が大きい
  4390:           //xとyを入れ換える
  4391:           xf = yf;
  4392:           xe += o = -o;  //xe=y.epp
  4393:           xd = yd;
  4394:           xc = yc;
  4395:           yf = x.flg;  //後で符号を比較するときに使う
  4396:           yd = x.dvl;
  4397:           yc = x.cvl;
  4398:         }
  4399:         //xの方が絶対値が大きいか等しい
  4400:         //yを右にずらして小数点の位置を合わせる
  4401:         if (0 < o) {
  4402:           if (o <= 63) {
  4403:             xb = yc << -o;
  4404:             yc = yd << -o | yc >>> o;
  4405:             yd >>>= o;
  4406:           } else if (o == 64) {
  4407:             xb = yc;
  4408:             yc = yd;
  4409:             yd = 0L;
  4410:           } else if (o <= 127) {
  4411:             xb = yd << -o | yc;
  4412:             yc = yd >>> o;
  4413:             yd = 0L;
  4414:           } else {
  4415:             xb = yd | yc;  //絶対値減算を行うとき下位からのボローとして必要
  4416:             yc = 0L;
  4417:             yd = 0L;
  4418:           }
  4419:         }
  4420:         //絶対値加算または絶対値減算を行う
  4421:         if (xf == yf) {  //符号が同じなので絶対値加算を行う
  4422:           //yc[1]とyc[0]をsticky bitに押し出す
  4423:           xb |= yc << 62;
  4424:           //右にずらしてxd[63]を空ける
  4425:           xc = xd << 63 | xc >>> 1;
  4426:           xd >>>= 1;
  4427:           yc = yd << 63 | yc >>> 1;
  4428:           yd >>>= 1;
  4429:           //下位を右にずらしてxc[63]を空ける
  4430:           yc >>>= 1;
  4431:           xc >>>= 1;
  4432:           //足す
  4433:           xc += yc;
  4434:           xd += yd + (xc >>> 63);
  4435:           //下位を左にずらしてxc[63]を詰める
  4436:           xc <<= 1;
  4437:           //溢れの処理
  4438:           if (xd < 0L) {  //溢れたとき
  4439:             xe++;
  4440:           } else {  //溢れなかったとき
  4441:             xd = xd << 1 | xc >>> 63;  //左にずらしてxd[63]を詰める
  4442:             xc <<= 1;
  4443:           }
  4444:         } else {  //符号が異なるので絶対値減算を行う
  4445:           //yc[0]をsticky bitに押し出す
  4446:           xb |= yc << 63;
  4447:           //下位を右にずらしてxc[63]を空ける
  4448:           yc >>>= 1;
  4449:           xc >>>= 1;
  4450:           //引く
  4451:           //  xの方が絶対値が大きいか等しいので負になることはないが0になることがある
  4452:           if (xb != 0L) {
  4453:             xc--;
  4454:           }
  4455:           xc -= yc;
  4456:           xd -= yd + (xc >>> 63);
  4457:           //下位を左にずらしてxc[63]を詰める
  4458:           xc <<= 1;
  4459:           //正規化する
  4460:           if (0L <= xd) {
  4461:             if (xd != 0L) {
  4462:               xe -= o = Long.numberOfLeadingZeros (xd);
  4463:               xd = xd << o | xc >>> -o;
  4464:               xc <<= o;
  4465:             } else if (xc != 0L) {
  4466:               xe -= o = 64 + Long.numberOfLeadingZeros (xc);
  4467:               xd = xc << o;
  4468:               xc = 0L;
  4469:             } else {  //0になった
  4470:               xf = epbRoundingMode == EPB_MODE_RM ? M | Z : P | Z;  //RMのとき-0,それ以外は+0
  4471:             }
  4472:           }
  4473:         }  //if 符号が同じなので絶対値加算を行う/符号が異なるので絶対値減算を行う
  4474:       }  //if どちらかが±0,±Inf,NaN/両方±0,±Inf,NaN以外
  4475:       return this.finish (xf, xe, xd, xc, xb);
  4476:     }  //efp.add(EFP,EFP)
  4477:     public final EFP iadd (EFP x, EFP y) {
  4478:       int xf = x.flg;
  4479:       int xe = x.epp;
  4480:       long xd = x.dvl;
  4481:       long xc = x.cvl;
  4482:       long xb = 0L;
  4483:       int yf = y.flg;
  4484:       if ((xf | yf) << 1 != 0) {  //どちらかが±0,±Inf,NaN
  4485:         if ((xf | yf) << 3 < 0) {  //どちらかがNaNのときNaN
  4486:           this.flg = N;
  4487:           return this;
  4488:         }
  4489:         if ((xf & yf) << 2 < 0 && xf != yf) {  //両方±Infで符号が逆のときNaN
  4490:           epbFpsr |= EPB_FPSR_OE;
  4491:           epbExceptionOperandExponent = yf & M | 0x7fff << 16;
  4492:           epbExceptionOperandMantissa = 0x0000000000000000L;
  4493:           this.flg = N;
  4494:           return this;
  4495:         }
  4496:         if ((xf & yf) << 1 < 0 && xf != yf) {  //両方±0で符号が逆のとき
  4497:           this.flg = epbRoundingMode == EPB_MODE_RM ? M | Z : P | Z;  //RMのとき-0,それ以外は+0
  4498:           return this;
  4499:         }
  4500:         if (xf << 1 < 0 || yf << 2 < 0) {  //xが±0またはyが±Infのときy
  4501:           xf = yf;
  4502:           xe = y.epp;
  4503:           xd = y.dvl;
  4504:           xc = y.cvl;
  4505:         }
  4506:         //xが±Infまたはyが±0のときx
  4507:       } else {  //両方±0,±Inf,NaN以外
  4508:         //加算なのでyの符号はそのまま
  4509:         long yd = y.dvl;
  4510:         long yc = y.cvl;
  4511:         int o = xe - y.epp;
  4512:         if (o < 0 || o == 0 && (xd < yd || xd == yd && xc >>> 1 < yc >>> 1)) {  //yの方が絶対値が大きい
  4513:           //xとyを入れ換える
  4514:           xf = yf;
  4515:           xe += o = -o;  //xe=y.epp
  4516:           xd = yd;
  4517:           xc = yc;
  4518:           yf = x.flg;  //後で符号を比較するときに使う
  4519:           yd = x.dvl;
  4520:           yc = x.cvl;
  4521:         }
  4522:         //xの方が絶対値が大きいか等しい
  4523:         //yを右にずらして小数点の位置を合わせる
  4524:         if (0 < o) {
  4525:           if (o <= 63) {
  4526:             xb = yc << -o;
  4527:             yc = yd << -o | yc >>> o;
  4528:             yd >>>= o;
  4529:           } else if (o == 64) {
  4530:             xb = yc;
  4531:             yc = yd;
  4532:             yd = 0L;
  4533:           } else if (o <= 127) {
  4534:             xb = yd << -o | yc;
  4535:             yc = yd >>> o;
  4536:             yd = 0L;
  4537:           } else {
  4538:             xb = yd | yc;  //絶対値減算を行うとき下位からのボローとして必要
  4539:             yc = 0L;
  4540:             yd = 0L;
  4541:           }
  4542:         }
  4543:         //絶対値加算または絶対値減算を行う
  4544:         if (xf == yf) {  //符号が同じなので絶対値加算を行う
  4545:           //yc[1]とyc[0]をsticky bitに押し出す
  4546:           xb |= yc << 62;
  4547:           //右にずらしてxd[63]を空ける
  4548:           xc = xd << 63 | xc >>> 1;
  4549:           xd >>>= 1;
  4550:           yc = yd << 63 | yc >>> 1;
  4551:           yd >>>= 1;
  4552:           //下位を右にずらしてxc[63]を空ける
  4553:           yc >>>= 1;
  4554:           xc >>>= 1;
  4555:           //足す
  4556:           xc += yc;
  4557:           xd += yd + (xc >>> 63);
  4558:           //下位を左にずらしてxc[63]を詰める
  4559:           xc <<= 1;
  4560:           //溢れの処理
  4561:           if (xd < 0L) {  //溢れたとき
  4562:             xe++;
  4563:           } else {  //溢れなかったとき
  4564:             xd = xd << 1 | xc >>> 63;  //左にずらしてxd[63]を詰める
  4565:             xc <<= 1;
  4566:           }
  4567:         } else {  //符号が異なるので絶対値減算を行う
  4568:           //yc[0]をsticky bitに押し出す
  4569:           xb |= yc << 63;
  4570:           //下位を右にずらしてxc[63]を空ける
  4571:           yc >>>= 1;
  4572:           xc >>>= 1;
  4573:           //引く
  4574:           //  xの方が絶対値が大きいか等しいので負になることはないが0になることがある
  4575:           if (xb != 0L) {
  4576:             xc--;
  4577:           }
  4578:           xc -= yc;
  4579:           xd -= yd + (xc >>> 63);
  4580:           //下位を左にずらしてxc[63]を詰める
  4581:           xc <<= 1;
  4582:           //正規化する
  4583:           if (0L <= xd) {
  4584:             if (xd != 0L) {
  4585:               xe -= o = Long.numberOfLeadingZeros (xd);
  4586:               xd = xd << o | xc >>> -o;
  4587:               xc <<= o;
  4588:             } else if (xc != 0L) {
  4589:               xe -= o = 64 + Long.numberOfLeadingZeros (xc);
  4590:               xd = xc << o;
  4591:               xc = 0L;
  4592:             } else {  //0になった
  4593:               xf = epbRoundingMode == EPB_MODE_RM ? M | Z : P | Z;  //RMのとき-0,それ以外は+0
  4594:             }
  4595:           }
  4596:         }  //if 符号が同じなので絶対値加算を行う/符号が異なるので絶対値減算を行う
  4597:       }  //if どちらかが±0,±Inf,NaN/両方±0,±Inf,NaN以外
  4598:       return this.ifinish (xf, xe, xd, xc, xb);
  4599:     }  //efp.iadd(EFP,EFP)
  4600: 
  4601:     //------------------------------------------------------------------------
  4602:     //a = a.agi (b)
  4603:     //  a=I(a,b)
  4604:     //i = i.agi (a, b)
  4605:     //  i=I(a,b)
  4606:     //  算術幾何平均
  4607:     //
  4608:     //  グラフ
  4609:     //    echo read("efp.gp");eval("f(b)=if(0<b&&b<1,Pi/(2*agm(1,b)),error())");graph(f) | gp -q
  4610:     //    +---------+---------+---------+---------+*--------+---------+---------+---------+
  4611:     //    |                                       |*                                      |
  4612:     //    |                                       |*                                      |
  4613:     //    |                                       |*                                      |
  4614:     //    |                                       |**                                     |
  4615:     //    +                                       + *                                     +
  4616:     //    |                                       | **                                    |
  4617:     //    |                                       |  *                                    |
  4618:     //    |                                       |  **                                   |
  4619:     //    |                                       |   **                                  |
  4620:     //    +                                       +    ***                                +
  4621:     //    |                                       |      ***                              |
  4622:     //    |                                       |        **                             |
  4623:     //    |                                       |                                       |
  4624:     //    |                                       |                                       |
  4625:     //    +                                       +                                       +
  4626:     //    |                                       |                                       |
  4627:     //    |                                       |                                       |
  4628:     //    |                                       |                                       |
  4629:     //    |                                       |                                       |
  4630:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
  4631:     //    |                                       |                                       |
  4632:     //    |                                       |                                       |
  4633:     //    |                                       |                                       |
  4634:     //    |                                       |                                       |
  4635:     //    +                                       +                                       +
  4636:     //    |                                       |                                       |
  4637:     //    |                                       |                                       |
  4638:     //    |                                       |                                       |
  4639:     //    |                                       |                                       |
  4640:     //    +                                       +                                       +
  4641:     //    |                                       |                                       |
  4642:     //    |                                       |                                       |
  4643:     //    |                                       |                                       |
  4644:     //    |                                       |                                       |
  4645:     //    +                                       +                                       +
  4646:     //    |                                       |                                       |
  4647:     //    |                                       |                                       |
  4648:     //    |                                       |                                       |
  4649:     //    |                                       |                                       |
  4650:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
  4651:     //
  4652:     //  定義域
  4653:     //    0<b<1
  4654:     //
  4655:     //  値域
  4656:     //    pi/2<i<+inf
  4657:     //
  4658:     //  I(a,b)=int[0..pi/2]{dt/sqrt(a^2*cos(t)^2+b^2*sin(t)^2)}
  4659:     //        =1/2*int[-inf..inf]{dt/sqrt((a^2+t^2)*(b^2+t^2))}
  4660:     //        =pi/(2*M(a,b))
  4661:     //
  4662:     public final EFP agi (EFP be) {
  4663:       return this.agi (this, be);
  4664:     }  //efp.agi(EFP)
  4665:     public final EFP agi (EFP ae, EFP be) {
  4666:       return this.agm (ae, be).rcpdiv (PI_2);  //pi/(2*M(a,b))
  4667:     }  //efp.agi(EFP,EFP)
  4668: 
  4669:     //------------------------------------------------------------------------
  4670:     //a = a.agm (b)
  4671:     //  a=M(a,b)
  4672:     //m = m.agm (a, b)
  4673:     //  m=M(a,b)
  4674:     //  算術幾何平均
  4675:     //
  4676:     //  グラフ
  4677:     //    echo read("efp.gp");eval("f(b)=if(0<b&&b<1,agm(1,b),error())");graph(f) | gp -q
  4678:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
  4679:     //    |                                       |                                       |
  4680:     //    |                                       |                                       |
  4681:     //    |                                       |                                       |
  4682:     //    |                                       |                                       |
  4683:     //    +                                       +                                       +
  4684:     //    |                                       |                                       |
  4685:     //    |                                       |                                       |
  4686:     //    |                                       |                                       |
  4687:     //    |                                       |                                       |
  4688:     //    +                                       +                                       +
  4689:     //    |                                       |                                       |
  4690:     //    |                                       |                                       |
  4691:     //    |                                       |                                       |
  4692:     //    |                                       |                                       |
  4693:     //    +                                       +       ***                             +
  4694:     //    |                                       |    ****                               |
  4695:     //    |                                       | ****                                  |
  4696:     //    |                                       ***                                     |
  4697:     //    |                                       *                                       |
  4698:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
  4699:     //    |                                       |                                       |
  4700:     //    |                                       |                                       |
  4701:     //    |                                       |                                       |
  4702:     //    |                                       |                                       |
  4703:     //    +                                       +                                       +
  4704:     //    |                                       |                                       |
  4705:     //    |                                       |                                       |
  4706:     //    |                                       |                                       |
  4707:     //    |                                       |                                       |
  4708:     //    +                                       +                                       +
  4709:     //    |                                       |                                       |
  4710:     //    |                                       |                                       |
  4711:     //    |                                       |                                       |
  4712:     //    |                                       |                                       |
  4713:     //    +                                       +                                       +
  4714:     //    |                                       |                                       |
  4715:     //    |                                       |                                       |
  4716:     //    |                                       |                                       |
  4717:     //    |                                       |                                       |
  4718:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
  4719:     //
  4720:     //  定義域
  4721:     //    0<b<1
  4722:     //
  4723:     //  値域
  4724:     //    0<m<1
  4725:     //
  4726:     //    a[0]=1
  4727:     //    b[0]=b
  4728:     //    a[n+1]=(a[n]+b[n])/2
  4729:     //    b[n+1]=sqrt(a[n]*b[n])
  4730:     //    M(1,b)=lim[n=inf]{a[n]}
  4731:     //          =lim[n=inf]{b[n]}
  4732:     //
  4733:     public final EFP agm (EFP be) {
  4734:       return this.agm (this, be);
  4735:     }  //efp.agm(EFP)
  4736:     public final EFP agm (EFP ae, EFP be) {
  4737:       int af = ae.flg;
  4738:       int bf = be.flg;
  4739:       if ((af | bf) != 0) {  //どちらかが±0,±Inf,NaN,-x
  4740:         this.flg = ((af | bf) << 3 < 0 ||  //agm(NaN,b)=agm(a,NaN)=NaN
  4741:                     ((af | bf) & (Z | I)) == (Z | I) ? N :  //agm(±0,±Inf)=agm(±Inf,±0)=NaN
  4742:                     (af | bf) << 1 < 0 ? P | Z :  //agm(±0,b)=agm(a,±0)=+0
  4743:                     (af | bf) < 0 ? N :  //agm(a<0,b!=0)=agm(a!=0,b<0)=NaN
  4744:                     P | I);  //agm(+Inf,b>0)=agm(a>0,+Inf)=+Inf
  4745:         return this;
  4746:       }
  4747:       //両方±0,±Inf,NaN,-x以外
  4748:       EFP t = new EFP ();
  4749:       EFP u = new EFP ();
  4750:       EFP v = new EFP ();
  4751:       if (ae.ge (be)) {  //b<=a
  4752:         //u.sete (ae);
  4753:         u.flg = ae.flg;
  4754:         u.epp = ae.epp;
  4755:         u.dvl = ae.dvl;
  4756:         u.cvl = ae.cvl;
  4757:         //v.sete (be);
  4758:         v.flg = be.flg;
  4759:         v.epp = be.epp;
  4760:         v.dvl = be.dvl;
  4761:         v.cvl = be.cvl;
  4762:       } else {  //a<b
  4763:         //u.sete (be);
  4764:         u.flg = be.flg;
  4765:         u.epp = be.epp;
  4766:         u.dvl = be.dvl;
  4767:         u.cvl = be.cvl;
  4768:         //v.sete (ae);
  4769:         v.flg = ae.flg;
  4770:         v.epp = ae.epp;
  4771:         v.dvl = ae.dvl;
  4772:         v.cvl = ae.cvl;
  4773:       }
  4774:       //  0<b<=a
  4775:       //  0<sqrt(a*b)<=(a+b)/2
  4776:       this.inner ();
  4777:       for (;;) {
  4778:         //  u=a,v=b
  4779:         t.iadd (u, v).idiv2 ();  //t=(a+b)/2。算術平均
  4780:         if (t.ge (u)) {  //0<b<aのままaとbが近付くのでaが減らなくなったら終了
  4781:           return this.outer ().sete (u).finish ();
  4782:         }
  4783:         v.imul (u).sqrt ();  //b=sqrt(a*b)。幾何平均
  4784:         //  t=a,v=b
  4785:         u.iadd (t, v).idiv2 ();  //u=(a+b)/2。算術平均
  4786:         if (u.ge (t)) {  //0<b<aのままaとbが近付くのでaが減らなくなったら終了
  4787:           return this.outer ().sete (t).finish ();
  4788:         }
  4789:         v.imul (t).sqrt ();  //b=sqrt(a*b)。幾何平均
  4790:       }
  4791:     }  //efp.agm(EFP,EFP)
  4792: 
  4793:     //------------------------------------------------------------------------
  4794:     //x = x.asec ()
  4795:     //  x=asec(x)
  4796:     //y = y.asec (x)
  4797:     //  y=asec(x)
  4798:     //  逆正割 inverse secant インバースセカント
  4799:     //
  4800:     //  グラフ
  4801:     //    perl -e "use Math::Trig;use Graph;$g=new Graph();$g->grid();$g->func(sub{asec($_[0])});print$g"
  4802:     //    echo read("efp.gp");eval("asec(x)=if(x>=0,atan(sqrt(x^2-1)),Pi-atan(sqrt(x^2-1)))");graph(asec) | gp -q
  4803:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
  4804:     //    |                                       |                                       |
  4805:     //    |                                       |                                       |
  4806:     //    |                                       |                                       |
  4807:     //    |                             *         |                                       |
  4808:     //    +                             *         +                                       +
  4809:     //    |                            **         |                                       |
  4810:     //    |                           **          |                                       |
  4811:     //    |                        ****           |                                       |
  4812:     //    |                   ******              |                                       |
  4813:     //    +        ************                   +                                       +
  4814:     //    **********                              |                                       |
  4815:     //    |                                       |                                       |
  4816:     //    |                                       |                                    ****
  4817:     //    |                                       |                     ****************  |
  4818:     //    +                                       +               *******                 +
  4819:     //    |                                       |            ****                       |
  4820:     //    |                                       |          ***                          |
  4821:     //    |                                       |         **                            |
  4822:     //    |                                       |         *                             |
  4823:     //    +---------+---------+---------+---------+---------*---------+---------+---------+
  4824:     //    |                                       |                                       |
  4825:     //    |                                       |                                       |
  4826:     //    |                                       |                                       |
  4827:     //    |                                       |                                       |
  4828:     //    +                                       +                                       +
  4829:     //    |                                       |                                       |
  4830:     //    |                                       |                                       |
  4831:     //    |                                       |                                       |
  4832:     //    |                                       |                                       |
  4833:     //    +                                       +                                       +
  4834:     //    |                                       |                                       |
  4835:     //    |                                       |                                       |
  4836:     //    |                                       |                                       |
  4837:     //    |                                       |                                       |
  4838:     //    +                                       +                                       +
  4839:     //    |                                       |                                       |
  4840:     //    |                                       |                                       |
  4841:     //    |                                       |                                       |
  4842:     //    |                                       |                                       |
  4843:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
  4844:     //
  4845:     //  定義域
  4846:     //    inf<=x<=1
  4847:     //    1<=x<=inf
  4848:     //
  4849:     //  値域
  4850:     //    0<=y<=pi
  4851:     //
  4852:     //  逆三角関数との関係
  4853:     //    asec(x)=atan2(sqrt(x^2-1),sgn(x))
  4854:     //           =x>=0?atan(sqrt(x^2-1)):pi-atan(sqrt(x^2-1))
  4855:     //
  4856:     public final EFP asec () {
  4857:       return this.asec (this);
  4858:     }  //efp.asec()
  4859:     public final EFP asec (EFP x) {
  4860:       int xf = x.flg;
  4861:       if (x.cmp1abs () < 0) {  //|x|<1
  4862:         epbFpsr |= EPB_FPSR_OE;
  4863:         if (xf << 1 < 0) {  //±0
  4864:           epbExceptionOperandExponent = xf & M;
  4865:           epbExceptionOperandMantissa = 0x0000000000000000L;
  4866:         } else {  //|±x|<1
  4867:           epbExceptionOperandExponent = xf & M | 0x3fff + x.epp << 16;
  4868:           epbExceptionOperandMantissa = x.dvl;
  4869:         }
  4870:         this.flg = N;
  4871:         return this;
  4872:       }
  4873:       EFP t = new EFP ().inner ().dec (x);
  4874:       this.inc (x).imul (t).sqrt ();
  4875:       return (xf < 0 ?
  4876:               this.atan ().negsub (PI).outer ().add (PIA) :  //pi-atan(sqrt((x-1)*(x+1)))
  4877:               this.outer ().atan ());  //atan(sqrt((x-1)*(x+1)))。x^2-1だと1+εのとき精度が低い
  4878:     }  //efp.asec(EFP)
  4879: 
  4880:     //------------------------------------------------------------------------
  4881:     //x = x.asech ()
  4882:     //  x=asech(x)
  4883:     //y = y.asech (x)
  4884:     //  y=asech(x)
  4885:     //  逆双曲線正割 inverse hyperbolic secant インバースハイパボリックセカント
  4886:     //
  4887:     //  グラフ
  4888:     //    perl -e "use Math::Trig;use Graph;$g=new Graph();$g->grid();$g->func(sub{asech($_[0])});print$g"
  4889:     //    echo read("efp.gp");eval("asech(x)=log(1/x+sqrt(1/x^2-1))");graph(asech) | gp -q
  4890:     //    +---------+---------+---------+---------*---------+---------+---------+---------+
  4891:     //    |                                       *                                       |
  4892:     //    |                                       **                                      |
  4893:     //    |                                       |*                                      |
  4894:     //    |                                       |*                                      |
  4895:     //    +                                       +*                                      +
  4896:     //    |                                       |*                                      |
  4897:     //    |                                       |**                                     |
  4898:     //    |                                       | *                                     |
  4899:     //    |                                       | *                                     |
  4900:     //    +                                       + **                                    +
  4901:     //    |                                       |  **                                   |
  4902:     //    |                                       |   *                                   |
  4903:     //    |                                       |   **                                  |
  4904:     //    |                                       |    **                                 |
  4905:     //    +                                       +     **                                +
  4906:     //    |                                       |      **                               |
  4907:     //    |                                       |       **                              |
  4908:     //    |                                       |        **                             |
  4909:     //    |                                       |         *                             |
  4910:     //    +---------+---------+---------+---------+---------*---------+---------+---------+
  4911:     //    |                                       |                                       |
  4912:     //    |                                       |                                       |
  4913:     //    |                                       |                                       |
  4914:     //    |                                       |                                       |
  4915:     //    +                                       +                                       +
  4916:     //    |                                       |                                       |
  4917:     //    |                                       |                                       |
  4918:     //    |                                       |                                       |
  4919:     //    |                                       |                                       |
  4920:     //    +                                       +                                       +
  4921:     //    |                                       |                                       |
  4922:     //    |                                       |                                       |
  4923:     //    |                                       |                                       |
  4924:     //    |                                       |                                       |
  4925:     //    +                                       +                                       +
  4926:     //    |                                       |                                       |
  4927:     //    |                                       |                                       |
  4928:     //    |                                       |                                       |
  4929:     //    |                                       |                                       |
  4930:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
  4931:     //
  4932:     //  定義域
  4933:     //    0<x<=1
  4934:     //
  4935:     //  値域
  4936:     //    0<=y<=inf
  4937:     //
  4938:     //  逆双曲線関数との関係
  4939:     //    asech(x)=acosh(1/x)
  4940:     //
  4941:     //  対数関数との関係
  4942:     //    asech(x)=log(1/x+sqrt(1/x^2-1))
  4943:     //            =log1p(1/x-1+sqrt((1/x-1)*(1/x+1)))
  4944:     //            =log1p(1/x-1+sqrt((1/x-1)^2+2*(1/x-1)))
  4945:     //            =log1p((1-x)/x+sqrt(((1-x)/x)^2+2*(1-x)/x))
  4946:     //
  4947:     public final EFP asech () {
  4948:       return this.asech (this);
  4949:     }  //efp.asech()
  4950:     public final EFP asech (EFP x) {
  4951:       //return this.rcp (x).acosh ();  //1-εのとき精度が低い
  4952:       int xf = x.flg;
  4953:       if (xf != 0) {  //-x,±0,±Inf,NaN
  4954:         if (xf < 0 || xf << 2 < 0) {  //-x,-0,±Inf
  4955:           epbFpsr |= EPB_FPSR_OE;
  4956:           if (xf == (M | Z)) {  //-0
  4957:             epbExceptionOperandExponent = M;
  4958:             epbExceptionOperandMantissa = 0x0000000000000000L;
  4959:           } else if (xf << 2 < 0) {  //±Inf
  4960:             epbExceptionOperandExponent = xf & M | 0x7fff << 16;
  4961:             epbExceptionOperandMantissa = 0x0000000000000000L;
  4962:           } else {  //-x
  4963:             epbExceptionOperandExponent = M | 0x3fff + x.epp << 16;
  4964:             epbExceptionOperandMantissa = x.dvl;
  4965:           }
  4966:           this.flg = N;  //asech(-x)=NaN, asech(-0)=NaN, asech(±Inf)=NaN
  4967:         } else {  //+0,NaN
  4968:           this.flg = xf << 1 < 0 ? P | I : N;  //asech(+0)=+Inf, asech(NaN)=NaN
  4969:         }
  4970:         return this;
  4971:       }
  4972:       //x<0,±0,±Inf,NaN以外
  4973:       if (0 <= x.epp) {  //1<=|x|
  4974:         if (x.epp == 0 && x.dvl == MSB && x.cvl == 0L) {  //|x|==1
  4975:           this.flg = P | Z;  //+0
  4976:         } else {  //1<|x|
  4977:           epbFpsr |= EPB_FPSR_OE;
  4978:           epbExceptionOperandExponent = xf | 0x3fff + x.epp << 16;
  4979:           epbExceptionOperandMantissa = x.dvl;
  4980:           this.flg = N;  //NaN
  4981:         }
  4982:         return this;
  4983:       }
  4984:       //|x|<1
  4985:       EFP t = new EFP ().inner ().negdec (x).div (x);  //(1-x)/x
  4986:       return this.iadd (t, new EFP ().isqu (t).iadd (new EFP ().imul2 (t)).sqrt ()).outer ().log1p ();  //log1p((1-x)/x+sqrt(((1-x)/x)^2+2*(1-x)/x))
  4987:     }  //efp.asech(EFP)
  4988: 
  4989:     //------------------------------------------------------------------------
  4990:     //x = x.asin ()
  4991:     //  x=asin(x)
  4992:     //y = y.asin (x)
  4993:     //  y=asin(x)
  4994:     //  逆正弦 inverse sine インバースサイン
  4995:     //
  4996:     //  グラフ
  4997:     //    perl -e "use Math::Trig;use Graph;$g=new Graph();$g->grid();$g->func(sub{asin($_[0])});print$g"
  4998:     //    echo read("efp.gp");graph(asin) | gp -q
  4999:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
  5000:     //    |                                       |                                       |
  5001:     //    |                                       |                                       |
  5002:     //    |                                       |                                       |
  5003:     //    |                                       |                                       |
  5004:     //    +                                       +                                       +
  5005:     //    |                                       |                                       |
  5006:     //    |                                       |                                       |
  5007:     //    |                                       |                                       |
  5008:     //    |                                       |                                       |
  5009:     //    +                                       +                                       +
  5010:     //    |                                       |                                       |
  5011:     //    |                                       |         *                             |
  5012:     //    |                                       |         *                             |
  5013:     //    |                                       |        **                             |
  5014:     //    +                                       +       **                              +
  5015:     //    |                                       |     ***                               |
  5016:     //    |                                       |    **                                 |
  5017:     //    |                                       |  ***                                  |
  5018:     //    |                                       |***                                    |
  5019:     //    +---------+---------+---------+--------***--------+---------+---------+---------+
  5020:     //    |                                    ***|                                       |
  5021:     //    |                                  ***  |                                       |
  5022:     //    |                                 **    |                                       |
  5023:     //    |                               ***     |                                       |
  5024:     //    +                              **       +                                       +
  5025:     //    |                             **        |                                       |
  5026:     //    |                             *         |                                       |
  5027:     //    |                             *         |                                       |
  5028:     //    |                                       |                                       |
  5029:     //    +                                       +                                       +
  5030:     //    |                                       |                                       |
  5031:     //    |                                       |                                       |
  5032:     //    |                                       |                                       |
  5033:     //    |                                       |                                       |
  5034:     //    +                                       +                                       +
  5035:     //    |                                       |                                       |
  5036:     //    |                                       |                                       |
  5037:     //    |                                       |                                       |
  5038:     //    |                                       |                                       |
  5039:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
  5040:     //
  5041:     //  定義域
  5042:     //    -1<=x<=1
  5043:     //
  5044:     //  値域
  5045:     //    -pi/2<=y<=pi/2
  5046:     //
  5047:     //  逆三角関数との関係
  5048:     //    asin(x)=atan2(x,sqrt(1-x^2))
  5049:     //           =atan2(x,sqrt((1-x)*(1+x)))
  5050:     //           =atan(x/sqrt(1-x^2))
  5051:     //           =atan(x/sqrt((1-x)*(1+x)))
  5052:     //           =pi/2-acos(x)
  5053:     //           =acsc(1/x)
  5054:     //
  5055:     //  微分
  5056:     //    df{asin(x)}=1/sqrt(1-x^2)
  5057:     //
  5058:     //  積分表示
  5059:     //    asin(x)=int[t=0..x]{dt/sqrt(1-t^2)}
  5060:     //
  5061:     //  テイラー展開
  5062:     //    積分表示を二項展開してから項別積分する
  5063:     //      二項展開
  5064:     //        (1+x)^n=sum[m=0..inf]{ncm(n,m)*x^m}
  5065:     //               =sum[m=0..inf]{n!/(m!*(n-m)!)*x^m}
  5066:     //               =sum[m=0..inf]{prod[k=0..m-1]{n-k}/m!*x^m}  (prodで項が1つもないときの値は1とする)
  5067:     //    asin(x)=int[t=0..x]{dt/sqrt(1-t^2)}
  5068:     //           =int[t=0..x]{(1-t^2)^(-1/2)*dt}
  5069:     //      二項展開する
  5070:     //           =int[t=0..x]{sum[m=0..inf]{prod[k=0..m-1]{-1/2-k}/m!*(-t^2)^m}*dt}
  5071:     //           =int[t=0..x]{sum[m=0..inf]{(-1)^m*prod[k=0..m-1]{2*k+1}/2^m/m!*(-1)^m*t^(2*m)}*dt}
  5072:     //           =int[t=0..x]{sum[m=0..inf]{prod[k=0..m-1]{2*k+1}/2^m/m!*t^(2*m)}*dt}
  5073:     //      項別積分する
  5074:     //           =sum[m=0..inf]{prod[k=0..m-1]{2*k+1}/2^m/m!*int[t=0..x]{t^(2*m)*dt}}
  5075:     //           =sum[m=0..inf]{prod[k=0..m-1]{2*k+1}/2^m/m!/(2*m+1)*x^(2*m+1)}
  5076:     //           =1/2^0/1/1*x^1+(1)/2^1/(1)/3*x^3+(1*3)/2^2/(1*2)/5*x^5+(1*3*5)/2^3/(1*2*3)/7*x^7+(1*3*5*7)/2^4/(1*2*3*4)/9*x^9+...
  5077:     //           =1/1/1*x^1+(1)/(2)/3*x^3+(1*3)/(2*4)/5*x^5+(1*3*5)/(2*4*6)/7*x^7+(1*3*5*7)/(2*4*6*8)/9*x^9+...
  5078:     //           =x+1/6*x^3+3/40*x^5+5/112*x^7+35/1152*x^9+...
  5079:     //    > coeff(sub(a=0,for n:=0:10 sum sub(x=a,df(asin(x),x,n))/factorial(n)*(x-a)^n),x);
  5080:     //            1     3       5       35
  5081:     //    {0,1,0,---,0,----,0,-----,0,------}
  5082:     //            6     40     112     1152
  5083:     //    |x|が1に近いとき収束が遅い
  5084:     //
  5085:     //  連分数展開
  5086:     //    asin(x)=x/(1-(1*x)^2/(2*3+(1*x)^2-2*3*(3*x)^2/(4*5+(3*x)^2-4*5*(5*x)^2/(6*7+(5*x)^2-6*7*(7*x)^2/(8*9+(7*x)^2-...)))))
  5087:     //      テイラー展開と同じ
  5088:     //
  5089:     public final EFP asin () {
  5090:       return this.asin (this);
  5091:     }  //efp.asin()
  5092:     public final EFP asin (EFP x) {
  5093:       int xf = x.flg;
  5094:       if (xf << 1 != 0) {  //±0,±Inf,NaN
  5095:         if (xf << 2 < 0) {  //±Inf
  5096:           epbFpsr |= EPB_FPSR_OE;
  5097:           epbExceptionOperandExponent = xf & M | 0x7fff << 16;
  5098:           epbExceptionOperandMantissa = 0x0000000000000000L;
  5099:           this.flg = N;  //asin(±Inf)=NaN
  5100:         } else {  //±0,NaN
  5101:           this.flg = xf;  //asin(±0)=±0, asin(NaN)=NaN
  5102:         }
  5103:         return this;
  5104:       }
  5105:       //±0,±Inf,NaN以外
  5106:       int xe = x.epp;
  5107:       if (0 <= xe) {  //1<=|x|
  5108:         if (xe == 0 && x.dvl == MSB && x.cvl == 0L) {  //|x|==1
  5109:           epbFpsr |= EPB_FPSR_X2;  //不正確な結果
  5110:           epbExceptionOperandExponent = xf | 0x3fff + x.epp << 16;
  5111:           epbExceptionOperandMantissa = x.dvl;
  5112:           if (0 <= xf) {
  5113:             this.sete (ROUNDED_PI_2[epbRoundingMode]).finish ();  //asin(1)=pi/2
  5114:           } else {
  5115:             this.sete (ROUNDED_NEGPI_2[epbRoundingMode]).finish ();  //asin(-1)=-pi/2
  5116:           }
  5117:         } else {  //1<|x|
  5118:           epbFpsr |= EPB_FPSR_OE;
  5119:           epbExceptionOperandExponent = xf | 0x3fff + x.epp << 16;
  5120:           epbExceptionOperandMantissa = x.dvl;
  5121:           this.flg = N;
  5122:         }
  5123:         return this;
  5124:       }
  5125:       //|x|<1
  5126:       epbFpsr |= EPB_FPSR_X2;  //不正確な結果
  5127:       epbExceptionOperandExponent = xf | 0x3fff + x.epp << 16;
  5128:       epbExceptionOperandMantissa = x.dvl;
  5129:       if (x.epp < -4) {  //|x|<1/16
  5130:         //atan2を使う方法はxが±0に近すぎると誤差で|asin(x)|<|x|になってしまうことがある
  5131:         //±0の近くだけチェビシェフ展開を使う
  5132:         int savedFpsr = epbFpsr;
  5133:         this.inner ();
  5134:         if (this == x) {
  5135:           x = new EFP (x);
  5136:         }
  5137:         EFP x2 = new EFP ().isqu (x);  //x^2
  5138:         this.imul (ASIN_C17, x2)
  5139:           .iadd (ASIN_C15).imul (x2)
  5140:             .iadd (ASIN_C13).imul (x2)
  5141:               .iadd (ASIN_C11).imul (x2)
  5142:                 .iadd (ASIN_C9).imul (x2)
  5143:                   .iadd (ASIN_C7).imul (x2)
  5144:                     .iadd (ASIN_C5).imul (x2)
  5145:                       .iadd (ASIN_C3).imul (x2)
  5146:                         .iadd (ASIN_C1).outer ().mul (x);
  5147:         return this.originLowerUpper (x).correctUnderflow (savedFpsr);
  5148:       }
  5149:       //1/16<=|x|<1
  5150:       this.inner ();
  5151:       EFP t = new EFP ().negdec (x).imul (new EFP ().inc (x)).sqrt ();
  5152:       return this.outer ().atan2 (x, t);  //atan2(x,sqrt((1-x)*(1+x))) [90]
  5153:     }  //efp.asin(EFP)
  5154: 
  5155:     //------------------------------------------------------------------------
  5156:     //x = x.asinh ()
  5157:     //  x=asinh(x)
  5158:     //y = y.asinh (x)
  5159:     //  y=asinh(x)
  5160:     //  逆双曲線正弦 inverse hyperbolic sine インバースハイパボリックサイン
  5161:     //
  5162:     //  グラフ
  5163:     //    perl -e "use Math::Trig;use Graph;$g=new Graph();$g->grid();$g->func(sub{asinh($_[0])});print$g"
  5164:     //    echo read("efp.gp");graph(asinh) | gp -q
  5165:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
  5166:     //    |                                       |                                       |
  5167:     //    |                                       |                                       |
  5168:     //    |                                       |                                       |
  5169:     //    |                                       |                                       |
  5170:     //    +                                       +                                       +
  5171:     //    |                                       |                                       |
  5172:     //    |                                       |                                       |
  5173:     //    |                                       |                                       |
  5174:     //    |                                       |                                       |
  5175:     //    +                                       +                                ********
  5176:     //    |                                       |                         ********      |
  5177:     //    |                                       |                    ******             |
  5178:     //    |                                       |                *****                  |
  5179:     //    |                                       |            *****                      |
  5180:     //    +                                       +         ****                          +
  5181:     //    |                                       |       ***                             |
  5182:     //    |                                       |    ****                               |
  5183:     //    |                                       |  ***                                  |
  5184:     //    |                                       |***                                    |
  5185:     //    +---------+---------+---------+--------***--------+---------+---------+---------+
  5186:     //    |                                    ***|                                       |
  5187:     //    |                                  ***  |                                       |
  5188:     //    |                               ****    |                                       |
  5189:     //    |                             ***       |                                       |
  5190:     //    +                          ****         +                                       +
  5191:     //    |                      *****            |                                       |
  5192:     //    |                  *****                |                                       |
  5193:     //    |             ******                    |                                       |
  5194:     //    |      ********                         |                                       |
  5195:     //    ********                                +                                       +
  5196:     //    |                                       |                                       |
  5197:     //    |                                       |                                       |
  5198:     //    |                                       |                                       |
  5199:     //    |                                       |                                       |
  5200:     //    +                                       +                                       +
  5201:     //    |                                       |                                       |
  5202:     //    |                                       |                                       |
  5203:     //    |                                       |                                       |
  5204:     //    |                                       |                                       |
  5205:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
  5206:     //
  5207:     //  定義域
  5208:     //    -inf<=x<=inf
  5209:     //
  5210:     //  値域
  5211:     //    -inf<=y<=inf
  5212:     //
  5213:     //  対数関数との関係
  5214:     //    asinh(x)=sgn(x)*log(abs(x)+sqrt(x^2+1))
  5215:     //            =sgn(x)*log(abs(x)+sqrt((abs(x)-1)*(abs(x)+1)+2))
  5216:     //
  5217:     //  マクローリン展開
  5218:     //    http://mathworld.wolfram.com/InverseHyperbolicSine.html
  5219:     //    |x|<1のとき
  5220:     //    asinh(x)=sum[n=0..inf]{(-1)^n*(2*n-1)!!/((2*n+1)*(2*n)!!)*x^(2*n+1)}
  5221:     //            =1!!/(1*0!!)*x^1-1!!/(3*2!!)*x^3+3!!/(5*4!!)*x^5-5!!/(7*6!!)*x^7+7!!/(9*8!!)*x^9-9!!/(11*10!!)*x^11+...
  5222:     //            =x-1/(3*2)*x^3+1*3/(5*2*4)*x^5-1*3*5/(7*2*4*6)*x^7+1*3*5*7/(9*2*4*6*8)*x^9-1*3*5*7*9/(11*2*4*6*8*10)*x^11+...
  5223:     //            =x-1/6*x^3+3/40*x^5-5/112*x^7+35/1152*x^9-63/2816*x^11+...
  5224:     //
  5225:     //  ピュイズー展開
  5226:     //    http://mathworld.wolfram.com/InverseHyperbolicSine.html
  5227:     //    asinh(x)=-log(1/x)+log(2)+sum[n=1..inf]{(-1)^(n-1)*(2*n-1)!!/(2*n*(2*n)!!)*x^(-2*n))}
  5228:     //            =-log(1/x)+log(2)+1/4/x^2-3/32/x^4+5/96/x^6-...
  5229:     //
  5230:     //  チェビシェフ展開
  5231:     //    0の近くだけチェビシェフ展開を使う
  5232:     //    echo read("efp.gp");eval("f(x)=asinh(x)");a=-0.25;b=0.25;nmax=41;print1("    //    ");forstep(n=1,nmax,2,printf("%4d",n));print();print1("    //    ");forstep(n=1,nmax,2,printf("%4d",floor(closeness(f,chebyshev(f,a,b,n),a,b,10000))));print() | gp -q
  5233:     //       1   3   5   7   9  11  13  15  17  19  21  23  25  27  29  31  33  35  37  39  41
  5234:     //       7  13  19  26  32  38  44  50  56  62  69  75  81  87  93  99 105 111 117 123 129
  5235:     //
  5236:     public final EFP asinh () {
  5237:       return this.asinh (this);
  5238:     }  //efp.asinh()
  5239:     public final EFP asinh (EFP x) {
  5240:       int xf = x.flg;
  5241:       if (xf << 1 != 0) {  //±0,±Inf,NaN
  5242:         this.flg = xf;  //asinh(±0), asinh(±Inf)=±Inf, asinh(NaN)=NaN
  5243:         return this;
  5244:       }
  5245:       //±0,±Inf,NaN以外
  5246:       if (x.epp < -1) {  //|x|<0.5
  5247:         int savedFpsr = epbFpsr;
  5248:         this.inner ();
  5249:         if (this == x) {
  5250:           x = new EFP (x);
  5251:         }
  5252:         EFP x2 = new EFP ().isqu (x);
  5253:         this.imul (ASINH_C43, x2)
  5254:           .iadd (ASINH_C41).imul (x2)
  5255:             .iadd (ASINH_C39).imul (x2)
  5256:               .iadd (ASINH_C37).imul (x2)
  5257:                 .iadd (ASINH_C35).imul (x2)
  5258:                   .iadd (ASINH_C33).imul (x2)
  5259:                     .iadd (ASINH_C31).imul (x2)
  5260:                       .iadd (ASINH_C29).imul (x2)
  5261:                         .iadd (ASINH_C27).imul (x2)
  5262:                           .iadd (ASINH_C25).imul (x2)
  5263:                             .iadd (ASINH_C23).imul (x2)
  5264:                               .iadd (ASINH_C21).imul (x2)
  5265:                                 .iadd (ASINH_C19).imul (x2)
  5266:                                   .iadd (ASINH_C17).imul (x2)
  5267:                                     .iadd (ASINH_C15).imul (x2)
  5268:                                       .iadd (ASINH_C13).imul (x2)
  5269:                                         .iadd (ASINH_C11).imul (x2)
  5270:                                           .iadd (ASINH_C9).imul (x2)
  5271:                                             .iadd (ASINH_C7).imul (x2)
  5272:                                               .iadd (ASINH_C5).imul (x2)
  5273:                                                 .iadd (ASINH_C3).imul (x2)
  5274:                                                   .iadd (ASINH_C1).outer ().mul (x);
  5275:         return this.originUpperLower (x).correctUnderflow (savedFpsr);
  5276:       }
  5277:       //0.5<=|x|
  5278:       EFP t = new EFP ().inner ().iabs (x);
  5279:       return this.isqu (t).inc ().sqrt ().iadd (t).log ().outer ().neg (xf < 0);  //sgn(x)*log(abs(x)+sqrt(x^2+1))
  5280:     }  //efp.asinh(EFP)
  5281: 
  5282:     //------------------------------------------------------------------------
  5283:     //x = x.atan ()
  5284:     //  x=atan(x)
  5285:     //y = y.atan (x)
  5286:     //  y=atan(x)
  5287:     //  逆正接 inverse tangent インバースタンジェント
  5288:     //
  5289:     //  グラフ
  5290:     //    perl -e "use Math::Trig;use Graph;$g=new Graph();$g->grid();$g->func(sub{atan($_[0])});print$g"
  5291:     //    echo read("efp.gp");graph(atan) | gp -q
  5292:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
  5293:     //    |                                       |                                       |
  5294:     //    |                                       |                                       |
  5295:     //    |                                       |                                       |
  5296:     //    |                                       |                                       |
  5297:     //    +                                       +                                       +
  5298:     //    |                                       |                                       |
  5299:     //    |                                       |                                       |
  5300:     //    |                                       |                                       |
  5301:     //    |                                       |                                       |
  5302:     //    +                                       +                                       +
  5303:     //    |                                       |                                       |
  5304:     //    |                                       |                                       |
  5305:     //    |                                       |                                   *****
  5306:     //    |                                       |                   *****************   |
  5307:     //    +                                       +            ********                   +
  5308:     //    |                                       |       ******                          |
  5309:     //    |                                       |    ****                               |
  5310:     //    |                                       |  ***                                  |
  5311:     //    |                                       |***                                    |
  5312:     //    +---------+---------+---------+--------***--------+---------+---------+---------+
  5313:     //    |                                    ***|                                       |
  5314:     //    |                                  ***  |                                       |
  5315:     //    |                               ****    |                                       |
  5316:     //    |                          ******       |                                       |
  5317:     //    +                   ********            +                                       +
  5318:     //    |   *****************                   |                                       |
  5319:     //    *****                                   |                                       |
  5320:     //    |                                       |                                       |
  5321:     //    |                                       |                                       |
  5322:     //    +                                       +                                       +
  5323:     //    |                                       |                                       |
  5324:     //    |                                       |                                       |
  5325:     //    |                                       |                                       |
  5326:     //    |                                       |                                       |
  5327:     //    +                                       +                                       +
  5328:     //    |                                       |                                       |
  5329:     //    |                                       |                                       |
  5330:     //    |                                       |                                       |
  5331:     //    |                                       |                                       |
  5332:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
  5333:     //
  5334:     //  定義域
  5335:     //    -inf<=x<=inf
  5336:     //
  5337:     //  値域
  5338:     //    -pi/2<=atan(x)<=pi/2
  5339:     //    加法定理を用いるときは値域からはみ出さないように注意すること
  5340:     //
  5341:     //  逆三角関数との関係
  5342:     //    asin(x)=atan(x/sqrt(1-x^2))
  5343:     //    acos(x)=pi/2-atan(x/sqrt(1-x^2))
  5344:     //
  5345:     //  加法定理
  5346:     //    atan(a)+atan(b)=atan((a+b)/(1-a*b))  a*b!=1
  5347:     //    atan(a)-atan(b)=atan((a-b)/(1+a*b))  a*b!=-1
  5348:     //    値域が-pi/2<atan(x)<=pi/2に制限されるので左辺の値と右辺の値がpiだけずれる場合があることに注意
  5349:     //    atan(x)+atan((1-x)/(1+x))=atan((x+(1-x)/(1+x))/(1-x*(1-x)/(1+x)))
  5350:     //                             =atan((x*(1+x)+(1-x))/((1+x)-x*(1-x)))
  5351:     //                             =atan((x+x^2+1-x)/(1+x-x+x^2))
  5352:     //                             =atan((1+x^2)/(1+x^2))
  5353:     //                             =atan(1)
  5354:     //                             =pi/4     -1<xのとき
  5355:     //                              -3/4*pi  x<-1のとき
  5356:     //    perl -e "use Math::Trig;use Graph;$g=new Graph();$g->grid();$g->func(sub{atan($_[0])+atan((1-$_[0])/(1+$_[0]))});print$g"
  5357:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
  5358:     //    |                                       |                                       |
  5359:     //    |                                       |                                       |
  5360:     //    |                                       |                                       |
  5361:     //    |                                       |                                       |
  5362:     //    +                                       +                                       +
  5363:     //    |                                       |                                       |
  5364:     //    |                                       |                                       |
  5365:     //    |                                       |                                       |
  5366:     //    |                                       |                                       |
  5367:     //    +                                       +                                       +
  5368:     //    |                                       |                                       |
  5369:     //    |                                       |                                       |
  5370:     //    |                                       |                                       |
  5371:     //    |                                       |                                       |
  5372:     //    +                                       +                                       +
  5373:     //    |                             ***************************************************
  5374:     //    |                                       |                                       |
  5375:     //    |                                       |                                       |
  5376:     //    |                                       |                                       |
  5377:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
  5378:     //    |                                       |                                       |
  5379:     //    |                                       |                                       |
  5380:     //    |                                       |                                       |
  5381:     //    |                                       |                                       |
  5382:     //    +                                       +                                       +
  5383:     //    |                                       |                                       |
  5384:     //    |                                       |                                       |
  5385:     //    |                                       |                                       |
  5386:     //    |                                       |                                       |
  5387:     //    +                                       +                                       +
  5388:     //    |                                       |                                       |
  5389:     //    *******************************         |                                       |
  5390:     //    |                                       |                                       |
  5391:     //    |                                       |                                       |
  5392:     //    +                                       +                                       +
  5393:     //    |                                       |                                       |
  5394:     //    |                                       |                                       |
  5395:     //    |                                       |                                       |
  5396:     //    |                                       |                                       |
  5397:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
  5398:     //    atan(x)+atan(1/x)=sgn(x)*pi/2
  5399:     //    perl -e "use Math::Trig;use Graph;$g=new Graph();$g->grid();$g->func(sub{atan($_[0])+atan(1/$_[0])});print$g"
  5400:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
  5401:     //    |                                       |                                       |
  5402:     //    |                                       |                                       |
  5403:     //    |                                       |                                       |
  5404:     //    |                                       |                                       |
  5405:     //    +                                       +                                       +
  5406:     //    |                                       |                                       |
  5407:     //    |                                       |                                       |
  5408:     //    |                                       |                                       |
  5409:     //    |                                       |                                       |
  5410:     //    +                                       +                                       +
  5411:     //    |                                       |                                       |
  5412:     //    |                                       *****************************************
  5413:     //    |                                       |                                       |
  5414:     //    |                                       |                                       |
  5415:     //    +                                       +                                       +
  5416:     //    |                                       |                                       |
  5417:     //    |                                       |                                       |
  5418:     //    |                                       |                                       |
  5419:     //    |                                       |                                       |
  5420:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
  5421:     //    |                                       |                                       |
  5422:     //    |                                       |                                       |
  5423:     //    |                                       |                                       |
  5424:     //    |                                       |                                       |
  5425:     //    +                                       +                                       +
  5426:     //    |                                       |                                       |
  5427:     //    |                                       |                                       |
  5428:     //    *****************************************                                       |
  5429:     //    |                                       |                                       |
  5430:     //    +                                       +                                       +
  5431:     //    |                                       |                                       |
  5432:     //    |                                       |                                       |
  5433:     //    |                                       |                                       |
  5434:     //    |                                       |                                       |
  5435:     //    +                                       +                                       +
  5436:     //    |                                       |                                       |
  5437:     //    |                                       |                                       |
  5438:     //    |                                       |                                       |
  5439:     //    |                                       |                                       |
  5440:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
  5441:     //
  5442:     //  例外
  5443:     //    |x|<=2^(-LEN/2)のときatan(x)=xとみなす
  5444:     //      テイラー展開よりatan(x)=x-1/3*x^3+1/5*x^5-1/7*x^7+...である
  5445:     //      |x|<=2^(-LEN/2)ならば|-1/3*x^3|/|x|=1/3*x^2<=1/3*2^(-LEN)であるから、
  5446:     //      仮数部がLENbitの浮動小数点数では|x|<=2^(-LEN/2)のときatan(x)とxを区別できない
  5447:     //      echo for(n=1,10,x=eval("10^-n");printf("    //      x=%.10f atan(x)=%.10f%c",x,atan(x),10)) | gp -q
  5448:     //      x=0.1000000000 atan(x)=0.0996686525
  5449:     //      x=0.0100000000 atan(x)=0.0099996667
  5450:     //      x=0.0010000000 atan(x)=0.0009999997
  5451:     //      x=0.0001000000 atan(x)=0.0001000000
  5452:     //      x=0.0000100000 atan(x)=0.0000100000
  5453:     //      x=0.0000010000 atan(x)=0.0000010000
  5454:     //      x=0.0000001000 atan(x)=0.0000001000
  5455:     //      x=0.0000000100 atan(x)=0.0000000100
  5456:     //      x=0.0000000010 atan(x)=0.0000000010
  5457:     //      x=0.0000000001 atan(x)=0.0000000001
  5458:     //    |x|>=2^(LEN+1)のときatan(x)=sgn(x)*pi/2とみなす
  5459:     //      atan(x)+atan(1/x)=sgn(x)*pi/2よりatan(x)-sgn(x)*pi/2=atan(1/x)=1/x-1/(3*x^3)+1/(5*x^5)-1/(7*x^7)+...である
  5460:     //      |x|>=2^(LEN+1)ならば|1/x|<=2^(-LEN-1)であるから、
  5461:     //      仮数部がLENbitの浮動小数点数では|x|>=2^(LEN+1)のときatan(x)とsgn(x)*pi/2を区別できない
  5462:     //      echo for(n=1,10,x=eval("10^n");printf("    //      1/x=%.10f pi/2-atan(x)=%.10f%c",1/x,Pi/2-atan(x),10)) | gp -q
  5463:     //      1/x=0.1000000000 pi/2-atan(x)=0.0996686525
  5464:     //      1/x=0.0100000000 pi/2-atan(x)=0.0099996667
  5465:     //      1/x=0.0010000000 pi/2-atan(x)=0.0009999997
  5466:     //      1/x=0.0001000000 pi/2-atan(x)=0.0001000000
  5467:     //      1/x=0.0000100000 pi/2-atan(x)=0.0000100000
  5468:     //      1/x=0.0000010000 pi/2-atan(x)=0.0000010000
  5469:     //      1/x=0.0000001000 pi/2-atan(x)=0.0000001000
  5470:     //      1/x=0.0000000100 pi/2-atan(x)=0.0000000100
  5471:     //      1/x=0.0000000010 pi/2-atan(x)=0.0000000010
  5472:     //      1/x=0.0000000001 pi/2-atan(x)=0.0000000001
  5473:     //
  5474:     //  符号除去
  5475:     //    符号を付けたままだと加法定理が使いにくいので0<=xにする
  5476:     //    atan(x)は奇関数
  5477:     //      atan(x)=-atan(-x)
  5478:     //
  5479:     //  変数変換
  5480:     //    収束を速くするために0<=x<=sqrt(2)-1にする
  5481:     //    0<=x<=sqrt(2)-1のとき
  5482:     //      y=atan(x)
  5483:     //      除算は不要
  5484:     //    sqrt(2)-1<x<1+sqrt(2)のとき
  5485:     //      x'=(1-x)/(1+x)
  5486:     //      y'=atan(x')
  5487:     //      y=pi/4-y'
  5488:     //       =pi/4-atan(x')
  5489:     //       =pi/4-atan((1-x)/(1+x))
  5490:     //        -1<xのときatan(x)+atan((1-x)/(1+x))=pi/4なので
  5491:     //       =atan(x)
  5492:     //      多項式を用いるときは除算が1回必要
  5493:     //    1+sqrt(2)<=xのとき
  5494:     //      x'=1/x
  5495:     //      y'=atan(x')
  5496:     //      y=pi/2-y'
  5497:     //       =pi/2-atan(x')
  5498:     //       =pi/2-atan(1/x)
  5499:     //        0<xのときatan(x)+atan(1/x)=pi/2なので
  5500:     //       =atan(x)
  5501:     //      多項式を用いるときは除算が1回必要
  5502:     //    perl -e "use Math::Trig;use Graph;$g=new Graph();$g->grid();$g->func(sub{my$a=abs($_[0]);$a<=sqrt(2)-1?$a:$a<1+sqrt(2)?(1-$a)/(1+$a):1/$a});print$g"
  5503:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
  5504:     //    |                                       |                                       |
  5505:     //    |                                       |                                       |
  5506:     //    |                                       |                                       |
  5507:     //    |                                       |                                       |
  5508:     //    +                                       +                                       +
  5509:     //    |                                       |                                       |
  5510:     //    |                                       |                                       |
  5511:     //    |                                       |                                       |
  5512:     //    |                                       |                                       |
  5513:     //    +                                       +                                       +
  5514:     //    |                                       |                                       |
  5515:     //    |                                       |                                       |
  5516:     //    |                                       |                                       |
  5517:     //    |                                       |                                       |
  5518:     //    +                                       +                                       +
  5519:     //    |                                       |                                       |
  5520:     //    |                                       |                                       |
  5521:     //    |      **********                  ***  |  ***                  **********      |
  5522:     //    ********                        **** ***|*** ****                        ********
  5523:     //    +---------+---------+-------*****------***------*****-------+---------+---------+
  5524:     //    |                    ********           |           ********                    |
  5525:     //    |               ******                  |                  ******               |
  5526:     //    |                                       |                                       |
  5527:     //    |                                       |                                       |
  5528:     //    +                                       +                                       +
  5529:     //    |                                       |                                       |
  5530:     //    |                                       |                                       |
  5531:     //    |                                       |                                       |
  5532:     //    |                                       |                                       |
  5533:     //    +                                       +                                       +
  5534:     //    |                                       |                                       |
  5535:     //    |                                       |                                       |
  5536:     //    |                                       |                                       |
  5537:     //    |                                       |                                       |
  5538:     //    +                                       +                                       +
  5539:     //    |                                       |                                       |
  5540:     //    |                                       |                                       |
  5541:     //    |                                       |                                       |
  5542:     //    |                                       |                                       |
  5543:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
  5544:     //    perl -e "use Math::Trig;use Graph;$g=new Graph();$g->grid();$PI=4*atan(1);$g->func(sub{my$x=$_[0];my $a=abs($x);($x<=>0)*($a<=sqrt(2)-1?atan($a):$a<1+sqrt(2)?$PI/4-atan((1-$a)/(1+$a)):$PI/2-atan(1/$a))});print$g"
  5545:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
  5546:     //    |                                       |                                       |
  5547:     //    |                                       |                                       |
  5548:     //    |                                       |                                       |
  5549:     //    |                                       |                                       |
  5550:     //    +                                       +                                       +
  5551:     //    |                                       |                                       |
  5552:     //    |                                       |                                       |
  5553:     //    |                                       |                                       |
  5554:     //    |                                       |                                       |
  5555:     //    +                                       +                                       +
  5556:     //    |                                       |                                       |
  5557:     //    |                                       |                                       |
  5558:     //    |                                       |                                   *****
  5559:     //    |                                       |                   *****************   |
  5560:     //    +                                       +            ********                   +
  5561:     //    |                                       |       ******                          |
  5562:     //    |                                       |    ****                               |
  5563:     //    |                                       |  ***                                  |
  5564:     //    |                                       |***                                    |
  5565:     //    +---------+---------+---------+--------***--------+---------+---------+---------+
  5566:     //    |                                    ***|                                       |
  5567:     //    |                                  ***  |                                       |
  5568:     //    |                               ****    |                                       |
  5569:     //    |                          ******       |                                       |
  5570:     //    +                   ********            +                                       +
  5571:     //    |   *****************                   |                                       |
  5572:     //    *****                                   |                                       |
  5573:     //    |                                       |                                       |
  5574:     //    |                                       |                                       |
  5575:     //    +                                       +                                       +
  5576:     //    |                                       |                                       |
  5577:     //    |                                       |                                       |
  5578:     //    |                                       |                                       |
  5579:     //    |                                       |                                       |
  5580:     //    +                                       +                                       +
  5581:     //    |                                       |                                       |
  5582:     //    |                                       |                                       |
  5583:     //    |                                       |                                       |
  5584:     //    |                                       |                                       |
  5585:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
  5586:     //
  5587:     //  テイラー展開
  5588:     //      atan(x)=x-1/3*x^3+1/5*x^5-1/7*x^7+...
  5589:     //      f(n,x)=sum(k=0,n,(-1)^k*1/(2*k+1)*x^(2*k+1))
  5590:     //    収束が遅い
  5591:     //    除算は不要
  5592:     //
  5593:     //  連分数展開
  5594:     //      atan(x)=x/(1+x^2/(3+4*x^2/(5+9*x^2/(7+16*x^2/(9+...n^2*x^2/(2*n+1))))))
  5595:     //      g(n,x,k)=k^2*x^2/(2*k+1+if(k<n,g(n,x,k+1),0))
  5596:     //      f(n,x)=x/(1+if(n<1,0,g(n,x,1)))
  5597:     //      echo eval("g(n,x,k)=k^2*x^2/(2*k+1+if(k<n,g(n,x,k+1),0))");eval("f(n,x)=x/(1+if(n<1,0,g(n,x,1)))");for(n=0,10,print("    //      f(",n,",x)=",f(n,x))) | gp -q
  5598:     //      f(0,x)=x
  5599:     //      f(1,x)=3*x/(x^2 + 3)
  5600:     //      f(2,x)=(4*x^3 + 15*x)/(9*x^2 + 15)
  5601:     //      f(3,x)=(55*x^3 + 105*x)/(9*x^4 + 90*x^2 + 105)
  5602:     //      f(4,x)=(64*x^5 + 735*x^3 + 945*x)/(225*x^4 + 1050*x^2 + 945)
  5603:     //      f(5,x)=(231*x^5 + 1190*x^3 + 1155*x)/(25*x^6 + 525*x^4 + 1575*x^2 + 1155)
  5604:     //      f(6,x)=(256*x^7 + 5943*x^5 + 19250*x^3 + 15015*x)/(1225*x^6 + 11025*x^4 + 24255*x^2 + 15015)
  5605:     //      f(7,x)=(15159*x^7 + 147455*x^5 + 345345*x^3 + 225225*x)/(1225*x^8 + 44100*x^6 + 242550*x^4 + 420420*x^2 + 225225)
  5606:     //      f(8,x)=(16384*x^9 + 638055*x^7 + 3738735*x^5 + 6831825*x^3 + 3828825*x)/(99225*x^8 + 1455300*x^6 + 5675670*x^4 + 8108100*x^2 + 3828825)
  5607:     //      f(9,x)=(307835*x^9 + 4813380*x^7 + 19801782*x^5 + 29609580*x^3 + 14549535*x)/(19845*x^10 + 1091475*x^8 + 9459450*x^6 + 28378350*x^4 + 34459425*x^2 + 14549535)
  5608:     //      f(10,x)=(327680*x^11 + 19225635*x^9 + 175855680*x^7 + 552473922*x^5 + 698377680*x^3 + 305540235*x)/(2401245*x^10 + 52026975*x^8 + 312161850*x^6 + 758107350*x^4 + 800224425*x^2 + 305540235)
  5609:     //      分子は(n|1)次(n>>1)項、分母は(n+1&~1)次(n+1>>1)項、合わせてn+2項
  5610:     //    テイラー展開よりも収束が速い
  5611:     //    分母が定数ではないので除算が必要
  5612:     //    1項ずつ除算するのは効率が悪いので通分して分子の多項式と分母の多項式をそれぞれ計算して最後に割ったほうが速い
  5613:     //    それでも除算が1回必要
  5614:     //
  5615:     //  チェビシェフ展開
  5616:     //    テイラー展開よりも収束が速い
  5617:     //    変数変換で|x|<=sqrt(2)-1にしてから展開する
  5618:     //    sqrt(2)-1<|x|のとき変数変換に除算が1回必要
  5619:     //    変数変換の都合で符号を分離していても奇関数のまま展開した方が収束が速い
  5620:     //
  5621:     //  tan(x)を高速に計算できる場合
  5622:     //    組み込み関数を使ってatan(x)の近似値t'を求める
  5623:     //    tan(x)を使ってx'=tan(t')を正確に求める。これは正確なのでatan(x')=t'である
  5624:     //    atan(x)=atan(x')+atan((x-x')/(1+x*x'))
  5625:     //           =t'+atan((x-x')/(1+x*x'))
  5626:     //    (x-x')/(1+x*x')は小さいのでatan((x-x')/(1+x*x'))は速く収束する
  5627:     //
  5628:     //  CORDIC
  5629:     //    基本
  5630:     //      座標(u[k],v[k])を向き+x→+yで角度t[k]だけ回転した座標(u[k+1],v[k+1])は
  5631:     //        u[k+1]=cos(t[k])*u[k]-sin(t[k])*v[k]
  5632:     //        v[k+1]=sin(t[k])*u[k]+cos(t[k])*v[k]
  5633:     //      である
  5634:     //      原点から見た方向だけが必要で原点からの距離は変化しても構わないとき
  5635:     //        cos(t[k])=1
  5636:     //        sin(t[k])=tan(t[k])
  5637:     //      とおけば
  5638:     //        u[k+1]=u[k]-tan(t[k])*v[k]
  5639:     //        v[k+1]=v[k]+tan(t[k])*u[k]
  5640:     //      となる
  5641:     //      向き+y→+xのときは
  5642:     //        v[k+1]=cos(t[k])*v[k]-sin(t[k])*u[k]
  5643:     //        u[k+1]=sin(t[k])*v[k]+cos(t[k])*u[k]
  5644:     //      であるから
  5645:     //        u[k+1]=u[k]+tan(t[k])*v[k]
  5646:     //        v[k+1]=v[k]-tan(t[k])*u[k]
  5647:     //      となる
  5648:     //    準備
  5649:     //      tan(t[k])=1/2^kに固定してt[k]のテーブルを用意する
  5650:     //        t[k]=atan(1/2^k)
  5651:     //    手順
  5652:     //      座標(u[0],v[0])ただしu[0]>0が与えられたとき、
  5653:     //      k=0,1,2,…について
  5654:     //        座標(u[k],v[k])がx軸よりも上にあるとき(v[k]>=0)
  5655:     //          (u[k],v[k])をt[k]だけ右回転した方向にある座標を(u[k+1],v[k+1])とする
  5656:     //            u[k+1]=u[k]-v[k]/2^k
  5657:     //            v[k+1]=v[k]+u[k]/2^k
  5658:     //        座標(u[k],v[k])がx軸よりも下にあるとき(v[k]<0)
  5659:     //          (u[k],v[k])をt[k]だけ左回転した方向にある座標を(u[k+1],v[k+1])とする
  5660:     //            u[k+1]=u[k]+v[k]/2^k
  5661:     //            v[k+1]=v[k]-u[k]/2^k
  5662:     //      を繰り返すと、座標(u[k],v[k])はx軸に近付いてゆく
  5663:     //      座標(u[k],v[k])とx軸のなす角はatan(v[k],u[k])であるから、kが十分に大きくなったとき
  5664:     //        右回転した角度の合計-左回転した角度の合計
  5665:     //      は座標(u[0],v[0])とx軸のなす角、すなわちatan2(v[0],u[0])である
  5666:     //    高速化1
  5667:     //      atan(1/2^1)≒0.463
  5668:     //      |x|<=sqrt(2)-1≒0.414
  5669:     //      atan(1/2^2)≒0.245
  5670:     //      であるから少なくともk=0とk=1は不要
  5671:     //      指数部を見てkの開始位置を決めればよい
  5672:     //      k=8あたりまでと仮数部の先頭4bitくらいをテーブル参照で処理することで固定小数点の上位のビットを排除してビット数を確保する
  5673:     //    高速化2
  5674:     //      x→0のときatan(x)≒x-x^3/3であるから、有効桁数の1/3まで回して結果にv[k]/u[k]を加えてもよい
  5675:     //      しかし、このままだと除算が必要
  5676:     //      t→0のとき1-cos(t)≒t^2/2であるから、u[0]が1などの定数のときは有効桁数の1/2まで回せばu[k]も定数になる
  5677:     //      u==1のときは有効桁数の1/2まで回して結果にv[k]*(1/K)を加えればよい
  5678:     //    乗算の回数は少ないが加減算の回数が多い
  5679:     //    1要素の固定小数点のときは速い
  5680:     //    2要素以上になると固定小数点でもキャリーやボローの処理が加わるため遅くなる
  5681:     //
  5682:     //  ガウス求積
  5683:     //    atan(x)は積分で表されるのでルジャンドル多項式を用いて近似式を構築することができる
  5684:     //    atan(x)=int[t=0..x]{1/(1+t^2)}
  5685:     //           =1/2*int[t=-x..x]{1/(1+t^2)}
  5686:     //           =x/2*int[t=-1..1]{1/(1+x^2*t^2)}
  5687:     //
  5688:     //  AGM
  5689:     //    Fast multiple-precision evaluation of elementary functions (1976)
  5690:     //    http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.98.4721
  5691:     //      S=2^(-n/2)
  5692:     //      V=x/(1+sqrt(1+x^2))
  5693:     //      Q=1
  5694:     //      while 1-S>2^(-n) {
  5695:     //        Q=2*Q/(1+S)
  5696:     //        W=2*S*V/(1+V^2)
  5697:     //        W=W/(1+sqrt(1-W^2))
  5698:     //        W=(V+W)/(1-V*W)
  5699:     //        V=W/(1+sqrt(1+W^2))
  5700:     //        S=2*sqrt(S)/(1+S)
  5701:     //      }
  5702:     //      return Q*log((1+V)/(1-V))
  5703:     //    多倍長演算用。桁数が少ないときは遅い
  5704:     //
  5705:     //  テイラー展開
  5706:     //    echo read("efp.gp");eval("f(n,x)=sum(k=0,n,(-1)^k*1/(2*k+1)*x^(2*k+1))");a=1-sqrt(2);b=sqrt(2)-1;nmax=27;print1("    //    ");for(n=0,nmax,printf("%4d",2*n+1));print();print1("    //    ");for(n=0,nmax,printf("%4d",floor(closeness(atan,f(n,x),a,b,10000))));print() | gp -q
  5707:     //       1   3   5   7   9  11  13  15  17  19  21  23  25  27  29  31  33  35  37  39  41  43  45  47  49  51  53  55
  5708:     //       4   7  10  13  16  19  21  24  27  29  32  35  37  40  43  45  48  51  53  56  58  61  64  66  69  71  74  77
  5709:     //
  5710:     //  連分数展開
  5711:     //    echo read("efp.gp");eval("g(n,x,k)=k^2*x^2/(2*k+1+if(k<n,g(n,x,k+1),0))");eval("f(n,x)=x/(1+if(n<1,0,g(n,x,1)))");a=1-sqrt(2);b=sqrt(2)-1;nmax=27;print1("    //    ");for(n=0,nmax,printf("%4d",2*n+1));print();print1("    //    ");for(n=0,nmax,printf("%4d",floor(closeness(atan,f(n,x),a,b,10000))));print() | gp -q
  5712:     //       1   3   5   7   9  11  13  15  17  19  21  23  25  27  29  31  33  35  37  39  41  43  45  47  49  51  53  55
  5713:     //       4   8  13  18  22  27  31  36  41  45  50  55  59  64  69  73  78  83  87  92  97 101 106 111 115 120 125 129
  5714:     //
  5715:     //  チェビシェフ展開
  5716:     //    echo read("efp.gp");a=1-sqrt(2);b=sqrt(2)-1;nmax=55;print1("    //    ");forstep(n=1,nmax,2,printf("%4d",n));print();print1("    //    ");forstep(n=1,nmax,2,printf("%4d",floor(closeness(atan,chebyshev(atan,a,b,n),a,b,10000))));print() | gp -q
  5717:     //       1   3   5   7   9  11  13  15  17  19  21  23  25  27  29  31  33  35  37  39  41  43  45  47  49  51  53  55
  5718:     //       4   9  13  18  23  27  32  37  41  46  51  55  60  65  69  74  79  83  88  93  97 102 107 111 116 121 125 130
  5719:     //
  5720:     public final EFP atan () {
  5721:       return this.atan (this);
  5722:     }  //efp.atan()
  5723:     public final EFP atan (EFP x) {
  5724:       int xf = x.flg;
  5725:       if (xf << 1 != 0) {  //±0,±Inf,NaN
  5726:         if (xf << 2 >= 0) {  //atan(±0)=±0,atan(NaN)=NaN
  5727:           this.flg = xf;
  5728:         } else {
  5729:           epbFpsr |= EPB_FPSR_X2;  //不正確な結果
  5730:           if (xf >= 0) {
  5731:             this.sete (ROUNDED_PI_2[epbRoundingMode]).finish ();  //atan(+Inf)=pi/2
  5732:           } else {
  5733:             this.sete (ROUNDED_NEGPI_2[epbRoundingMode]).finish ();  //atan(-Inf)=-pi/2
  5734:           }
  5735:         }
  5736:         return this;
  5737:       }
  5738:       //±0,±Inf,NaN以外
  5739:       int xe = x.epp;
  5740:       if (xe <= -LEN / 2) {  //|x|<=2^(-LEN/2) --> atan(x)=x
  5741:         epbFpsr |= EPB_FPSR_X2;  //不正確な結果
  5742:         int savedFpsr = epbFpsr;
  5743:         //this.sete (x);
  5744:         this.flg = xf;
  5745:         this.epp = xe;
  5746:         this.dvl = x.dvl;
  5747:         this.cvl = x.cvl;
  5748:         if (this.flg < 0) {
  5749:           if (epbRoundingMode == EPB_MODE_RZ || epbRoundingMode == EPB_MODE_RP) {
  5750:             this.nextup (epbRoundingPrec);
  5751:           }
  5752:         } else {
  5753:           if (epbRoundingMode == EPB_MODE_RZ || epbRoundingMode == EPB_MODE_RM) {
  5754:             this.nextdown (epbRoundingPrec);
  5755:           }
  5756:         }
  5757:         return this.finish ().correctUnderflow (savedFpsr);
  5758:       }
  5759:       if (LEN + 1 <= xe) {  //2^(LEN+1)<=|x| --> atan(x)=sgn(x)*pi/2
  5760:         epbFpsr |= EPB_FPSR_X2;  //不正確な結果
  5761:         return this.sete (ROUNDED_PI_2[epbRoundingMode]).neg (xf < 0);
  5762:       }
  5763:       if (false) {  //[91] 600ns
  5764:         this.inner ();
  5765:         EFP u = new EFP ().iabs (x);  //|x|
  5766:         EFP b;
  5767:         EFP bw;
  5768:         EFP t = new EFP ();
  5769:         if (u.le (DECSQRT2)) {  //0<=x<=sqrt(2)-1
  5770:           b = null;  //y=y'
  5771:           bw = null;
  5772:         } else if (u.lt (INCSQRT2)) {  //sqrt(2)-1<x<1+sqrt(2)
  5773:           //t.inc (u);
  5774:           //u.imul2 ().div (t).negdec ();  //x'=1-(2*x)/(1+x)
  5775:           u.div (t.negdec (u), u.inc ());  //x'=(1-x)/(1+x)
  5776:           b = PI_4;  //y=pi/4-y'
  5777:           bw = PI_4A;
  5778:         } else {  //1+sqrt(2)<=x
  5779:           u.rcp ();  //x'=1/x
  5780:           b = PI_2;  //y=pi/2-y'
  5781:           bw = PI_2A;
  5782:         }
  5783:         if (false) {  //テイラー展開
  5784:           EFP x2 = new EFP (u).isqu ();  //x^2
  5785:           //this.set0 ();  //0
  5786:           this.flg = P | Z;
  5787:           for (int k = 0; ; k++) {
  5788:             t.divi (u, 2 * k + 1);  //1/(2*k+1)*x^(2*k+1)
  5789:             if ((k & 1) == 0) {
  5790:               t.iadd (this, t);  //(-1)^k*1/(2*k+1)*x^(2*k+1)
  5791:             } else {
  5792:               t.sub (this, t);  //(-1)^k*1/(2*k+1)*x^(2*k+1)
  5793:             }
  5794:             if (this.eq (t)) {
  5795:               break;
  5796:             }
  5797:             //this.sete (t);
  5798:             this.flg = t.flg;
  5799:             this.epp = t.epp;
  5800:             this.dvl = t.dvl;
  5801:             this.cvl = t.cvl;
  5802:             u.imul (x2);
  5803:           }
  5804:         } else {  //チェビシェフ展開
  5805:           t.isqu (u);  //u^2
  5806:           this.imul (ATAN_C39, t)
  5807:             .iadd (ATAN_C37).imul (t)
  5808:               .iadd (ATAN_C35).imul (t)
  5809:                 .iadd (ATAN_C33).imul (t)
  5810:                   .iadd (ATAN_C31).imul (t)
  5811:                     .iadd (ATAN_C29).imul (t)
  5812:                       .iadd (ATAN_C27).imul (t)
  5813:                         .iadd (ATAN_C25).imul (t)
  5814:                           .iadd (ATAN_C23).imul (t)
  5815:                             .iadd (ATAN_C21).imul (t)
  5816:                               .iadd (ATAN_C19).imul (t)
  5817:                                 .iadd (ATAN_C17).imul (t)
  5818:                                   .iadd (ATAN_C15).imul (t)
  5819:                                     .iadd (ATAN_C13).imul (t)
  5820:                                       .iadd (ATAN_C11).imul (t)
  5821:                                         .iadd (ATAN_C9).imul (t)
  5822:                                           .iadd (ATAN_C7).imul (t)
  5823:                                             .iadd (ATAN_C5).imul (t)
  5824:                                               .iadd (ATAN_C3).imul (t)
  5825:                                                 .iadd (ATAN_C1).imul (u);
  5826:         }
  5827:         if (b != null) {
  5828:           this.negsub (b).iadd (bw);  //y=pi/4-y'またはy=pi/2-y'
  5829:         }
  5830:         return this.outer ().neg (xf < 0);
  5831:       } else {  //tanを使う。[91] 540ns
  5832:         int savedFpsr = epbFpsr;
  5833:         this.inner ();
  5834:         if (this == x) {
  5835:           x = new EFP (x);  //必要なときだけコピーする
  5836:         }
  5837:         //  指数部が小さすぎる場合と大きすぎる場合は除いてあるのでこのままdoubleに変換する
  5838:         //  Math.atan(double)を使ってatan(x)の近似値t'を求める
  5839:         long s = Double.doubleToLongBits (Math.atan (Double.longBitsToDouble ((long) (1023 + x.epp) << 52 | x.dvl << 1 >>> 12)));
  5840:         EFP tt = new EFP (xf, (int) (s >>> 52) - 1023, MSB | s << 12 >>> 1, 0L);  //atan(x)の近似値t'
  5841:         //  tanを使ってatan(x')=t'を満たすx'を求める
  5842:         EFP xx = new EFP ().tan (tt);  //x'=tan(t')
  5843:         //  atan(x)=atan(x')+atan((x-x')/(1+x*x'))を使ってatan(x)を計算する
  5844:         //  (x-x')/(1+x*x')は小さいので1次の項だけ加える
  5845:         this.imul (x, xx).inc ().rcp ().imul (xx.negsub (x)).outer ().add (tt);  //t'+(x-x')/(1+x*x')
  5846:         return this.originUpperLower (x).correctUnderflow (savedFpsr);
  5847:       }
  5848:     }  //efp.atan(EFP)
  5849: 
  5850:     //------------------------------------------------------------------------
  5851:     //y = y.atan2 (x)
  5852:     //  y=atan2(y,x)
  5853:     //z = z.atan2 (y, x)
  5854:     //  z=atan2(y,x)
  5855:     //  逆正接 inverse tangent インバースタンジェント
  5856:     //
  5857:     //  atan2(y,x)=(isNaN(y)||isNaN(x)?NaN:
  5858:     //              isInfinite(y)&&isInfinite(x)?copySign(x>=+0?pi/4:3*pi/4,y):
  5859:     //              y==0||isInfinite(x)?copySign(x>=+0?0:pi,y):
  5860:     //              isInfinite(y)||x==0?copySign(pi/2,y):
  5861:     //              x>=0?atan(y/x):atan(y/x)+copySign(pi,y))
  5862:     //
  5863:     //  定義域
  5864:     //    -inf<=y<=inf
  5865:     //    -inf<=x<=inf
  5866:     //    y==0&&x==0を除く
  5867:     //    (y,x)=(Inf,Inf)などは感覚的にはNaNにするべきだと思うがMath.atan2はpi/4を返す
  5868:     //
  5869:     //  値域
  5870:     //    -pi<=atan2(y,x)<=pi
  5871:     //
  5872:     public final EFP atan2 (EFP x) {
  5873:       return this.atan2 (this, x);
  5874:     }  //efp.atan2(EFP)
  5875:     public final EFP atan2 (EFP y, EFP x) {
  5876:       int yf = y.flg;
  5877:       int xf = x.flg;
  5878:       if ((yf | xf) << 1 != 0) {  //どちらかが±0,±Inf,NaN
  5879:         if ((yf | xf) << 3 < 0) {  //どちらかがNaN
  5880:           this.flg = N;
  5881:         } else if ((yf & xf) << 2 < 0) {  //両方±Inf
  5882:           epbFpsr |= EPB_FPSR_X2;  //不正確な結果
  5883:           this.sete (yf >= 0 ? xf >= 0 ? PI_4 : PI3_4 : xf >= 0 ? NEGPI_4 : NEGPI3_4).finish ();
  5884:         } else if (yf << 1 < 0 || xf << 2 < 0) {  //yが±0またはxが±Inf
  5885:           if (xf >= 0) {
  5886:             this.sete (yf >= 0 ? ZERO : NEGZERO);
  5887:           } else {
  5888:             epbFpsr |= EPB_FPSR_X2;  //不正確な結果
  5889:             if (yf >= 0) {
  5890:               this.sete (ROUNDED_PI[epbRoundingMode]).finish ();
  5891:             } else {
  5892:               this.sete (ROUNDED_NEGPI[epbRoundingMode]).finish ();
  5893:             }
  5894:           }
  5895:         } else {  //yが±Infまたはxが±0
  5896:           epbFpsr |= EPB_FPSR_X2;  //不正確な結果
  5897:           if (yf >= 0) {
  5898:             this.sete (ROUNDED_PI_2[epbRoundingMode]).finish ();
  5899:           } else {
  5900:             this.sete (ROUNDED_NEGPI_2[epbRoundingMode]).finish ();
  5901:           }
  5902:         }
  5903:         return this;
  5904:       }
  5905:       //両方±0,±Inf,NaN以外
  5906:       return (xf < 0 ?
  5907:               this.inner ().div (y, x).atan ().outer ().add (yf >= 0 ? PI : NEGPI) :
  5908:               this.inner ().div (y, x).outer ().atan ());
  5909:     }  //efp.atan2(EFP,EFP)
  5910: 
  5911:     //------------------------------------------------------------------------
  5912:     //x = x.atanh ()
  5913:     //  x=atanh(x)
  5914:     //y = y.atanh (x)
  5915:     //  y=atanh(x)
  5916:     //  逆双曲線正接 inverse hyperbolic tangent インバースハイパボリックタンジェント
  5917:     //
  5918:     //  グラフ
  5919:     //    perl -e "use Math::Trig;use Graph;$g=new Graph();$g->grid();$g->func(sub{atanh($_[0])});print$g"
  5920:     //    echo read("efp.gp");graph(atanh) | gp -q
  5921:     //    +---------+---------+---------+---------+---------*---------+---------+---------+
  5922:     //    |                                       |         *                             |
  5923:     //    |                                       |         *                             |
  5924:     //    |                                       |         *                             |
  5925:     //    |                                       |         *                             |
  5926:     //    +                                       +         *                             +
  5927:     //    |                                       |         *                             |
  5928:     //    |                                       |         *                             |
  5929:     //    |                                       |         *                             |
  5930:     //    |                                       |         *                             |
  5931:     //    +                                       +         *                             +
  5932:     //    |                                       |        **                             |
  5933:     //    |                                       |        *                              |
  5934:     //    |                                       |        *                              |
  5935:     //    |                                       |       **                              |
  5936:     //    +                                       +      **                               +
  5937:     //    |                                       |     **                                |
  5938:     //    |                                       |    **                                 |
  5939:     //    |                                       |  ***                                  |
  5940:     //    |                                       |***                                    |
  5941:     //    +---------+---------+---------+--------***--------+---------+---------+---------+
  5942:     //    |                                    ***|                                       |
  5943:     //    |                                  ***  |                                       |
  5944:     //    |                                 **    |                                       |
  5945:     //    |                                **     |                                       |
  5946:     //    +                               **      +                                       +
  5947:     //    |                              **       |                                       |
  5948:     //    |                              *        |                                       |
  5949:     //    |                              *        |                                       |
  5950:     //    |                             **        |                                       |
  5951:     //    +                             *         +                                       +
  5952:     //    |                             *         |                                       |
  5953:     //    |                             *         |                                       |
  5954:     //    |                             *         |                                       |
  5955:     //    |                             *         |                                       |
  5956:     //    +                             *         +                                       +
  5957:     //    |                             *         |                                       |
  5958:     //    |                             *         |                                       |
  5959:     //    |                             *         |                                       |
  5960:     //    |                             *         |                                       |
  5961:     //    +---------+---------+---------*---------+---------+---------+---------+---------+
  5962:     //
  5963:     //  定義域
  5964:     //    -1<=x<=1
  5965:     //
  5966:     //  値域
  5967:     //    -inf<=y<=inf
  5968:     //
  5969:     //  テイラー展開
  5970:     //    atanh(x)=sum[k=0..inf]{x^(2*k+1)/(2*k+1)}
  5971:     //    > coeff(sub(a=0,for n:=0:13 sum sub(x=a,df(atanh(x),x,n))/factorial(n)*(x-a)^n),x);
  5972:     //            1     1     1     1     1      1
  5973:     //    {0,1,0,---,0,---,0,---,0,---,0,----,0,----}
  5974:     //            3     5     7     9     11     13
  5975:     //
  5976:     //  対数関数との関係
  5977:     //    atanh(x)=x>=0?log((1+x)/(1-x))/2:-log((1-x)/(1+x))/2
  5978:     //
  5979:     //  変数変換1
  5980:     //    次のように変形する
  5981:     //      atanh(x)=log((1+x)/(1-x))/2
  5982:     //              =(log((1+x)/(1-x))-log(2^n)+log(2^n))/2
  5983:     //              =log((1+x)/(2^n*(1-x)))/2+n*log(2)/2
  5984:     //    ここで
  5985:     //      (1+x)/(2^n*(1-x))=(1+t)/(1-t)
  5986:     //    となるようにtを定める
  5987:     //      atanh(x)=log((1+t)/(1-t))/2+n*log(2)/2
  5988:     //              =atanh(t)+n*log(2)/2
  5989:     //    tをxで表現する
  5990:     //      1+t=(1+x)/(2^n*(1-x))*(1-t)
  5991:     //      (1+(1+x)/(2^n*(1-x)))*t=(1+x)/(2^n*(1-x))-1
  5992:     //      t=((1+x)/(2^n*(1-x))-1)/(1+(1+x)/(2^n*(1-x)))
  5993:     //       =((1+x)-2^n*(1-x))/(2^n*(1-x)+(1+x))
  5994:     //       =(1+x-2^n+2^n*x)/(2^n-2^n*x+1+x)
  5995:     //       =((2^n+1)*x-(2^n-1))/((2^n+1)-(2^n-1)*x)
  5996:     //       =(((2^n+1)*x-(2^n-1))+((2^n+1)-(2^n-1)*x))/((2^n+1)-(2^n-1)*x)-1
  5997:     //       =((2^n+1)*x-(2^n-1)+(2^n+1)-(2^n-1)*x)/((2^n+1)-(2^n-1)*x)-1
  5998:     //       =(2*x+2)/((2^n+1)-(2^n-1)*x)-1
  5999:     //       =2*(1+x)/((2^n+1)-(2^n-1)*x)-1
  6000:     //    xをtで表現する
  6001:     //      1+x=2^n*(1+t)/(1-t)*(1-x)
  6002:     //      (1+2^n*(1+t)/(1-t))*x=2^n*(1+t)/(1-t)-1
  6003:     //      x=(2^n*(1+t)/(1-t)-1)/(1+2^n*(1+t)/(1-t))
  6004:     //       =(2^n*(1+t)-(1-t))/((1-t)+2^n*(1+t))
  6005:     //       =(2^n+2^n*t-1+t)/(1-t+2^n+2^n*t)
  6006:     //       =((2^n+1)*t+(2^n-1))/((2^n+1)+(2^n-1)*t)
  6007:     //       =1-(((2^n+1)+(2^n-1)*t)-((2^n+1)*t+(2^n-1)))/((2^n+1)+(2^n-1)*t)
  6008:     //       =1-((2^n+1)+(2^n-1)*t-(2^n+1)*t-(2^n-1))/((2^n+1)+(2^n-1)*t)
  6009:     //       =1-(2-2*t)/((2^n+1)+(2^n-1)*t)
  6010:     //       =1-2*(1-t)/((2^n+1)+(2^n-1)*t)
  6011:     //
  6012:     //  変数変換2
  6013:     //    t=0となるxで分割する
  6014:     //      x=1-2*(1-0)/((2^n+1)+(2^n-1)*0)
  6015:     //       =1-2/(2^n+1)
  6016:     //    したがって、|x|<1を
  6017:     //      1-2/(2^n+1)={1/3,3/5,7/9,15/17,31/33,...}
  6018:     //    で分割すると、|t|<=1/3になる
  6019:     //    perl -e "use POSIX;sub log2{my($x)=@_;log($x)/log(2);}printf'    //    %4s%10s%10s%11s%18s%c','n','x','1-x','log2(1-x)','floor(log2(1-x))',10;for$n(0..10){$x=1-2/(2**$n+1);printf'    //    %4d%10.6f%10.6f%11.6f%18d%c',$n,$x,1-$x,log2(1-$x),floor(log2(1-$x)),10}"
  6020:     //       n         x       1-x  log2(1-x)  floor(log2(1-x))
  6021:     //       0  0.000000  1.000000   0.000000                 0
  6022:     //       1  0.333333  0.666667  -0.584963                -1
  6023:     //       2  0.600000  0.400000  -1.321928                -2
  6024:     //       3  0.777778  0.222222  -2.169925                -3
  6025:     //       4  0.882353  0.117647  -3.087463                -4
  6026:     //       5  0.939394  0.060606  -4.044394                -5
  6027:     //       6  0.969231  0.030769  -5.022368                -6
  6028:     //       7  0.984496  0.015504  -6.011227                -7
  6029:     //       8  0.992218  0.007782  -7.005625                -8
  6030:     //       9  0.996101  0.003899  -8.002815                -9
  6031:     //      10  0.998049  0.001951  -9.001408               -10
  6032:     //    手順
  6033:     //      n=-floor(log2(1-|x|));  //1-xの指数部を取り出して符号を反転したもの。1以上
  6034:     //      if(|x|<=1-2/(2^n+1)){  //1-2/(2^n+1)は高々LEN通りしかないのでテーブルに列挙しておく
  6035:     //        n--;
  6036:     //      }
  6037:     //      t=(1+|x|-2^n*(1-|x|))/(1+|x|+2^n*(1-|x|))
  6038:     //      //tで多項式を計算する
  6039:     //      //n*log(2)/2を加える
  6040:     //      //xの符号を掛ける
  6041:     //    x→tのグラフ
  6042:     //    perl -e "use POSIX;use Graph;sub log2{my($x)=@_;log($x)/log(2);}$g=new Graph(80,40,-1,1,-1,1);$g->grid();$g->func(sub{$x=$_[0];if(1<=abs($x)){$t=undef;}else{$n=-floor(log2(1-abs($x)));if(abs($x)<=1-2/(2**$n+1)){$n--;}$t=($x<=>0)*(1+abs($x)-2**$n*(1-abs($x)))/(1+abs($x)+2**$n*(1-abs($x)));}$t});print$g"
  6043:     //                                            +                                        
  6044:     //                                            |                                        
  6045:     //                                            |                                        
  6046:     //                                            |                                        
  6047:     //                                            |                                        
  6048:     //                                            |                                        
  6049:     //                                            |                                        
  6050:     //                                            |                                        
  6051:     //                                            |                                        
  6052:     //                                            |                                        
  6053:     //                                            |                                        
  6054:     //                                            |                                        
  6055:     //                                            |                                        
  6056:     //                                            |            *          *      *   *  ***
  6057:     //                                            |          ***        ***     **   * ****
  6058:     //                                            |        ***         **      **   ** ****
  6059:     //                                            |      ***         ***      **    *  ****
  6060:     //                                            |    ***          **       **    ** *****
  6061:     //                                            |  ***          ***       **    **  * ***
  6062:     //                                            |***          ***        **    **   * ***
  6063:     //    ***-**---*-----**---------**-----------***-----------**---------**-----*---**-***
  6064:     //    *** *   **    **        ***          ***|                                        
  6065:     //    *** *  **    **       ***          ***  |                                        
  6066:     //    ***** **    **       **          ***    |                                        
  6067:     //    ****  *    **      ***         ***      |                                        
  6068:     //    **** **   **      **         ***        |                                        
  6069:     //    **** *   **     ***        ***          |                                        
  6070:     //    ***  *   *      *          *            |                                        
  6071:     //                                            |                                        
  6072:     //                                            |                                        
  6073:     //                                            |                                        
  6074:     //                                            |                                        
  6075:     //                                            |                                        
  6076:     //                                            |                                        
  6077:     //                                            |                                        
  6078:     //                                            |                                        
  6079:     //                                            |                                        
  6080:     //                                            |                                        
  6081:     //                                            |                                        
  6082:     //                                            |                                        
  6083:     //                                            +                                        
  6084:     //
  6085:     //  変数変換3
  6086:     //    -r<=t<=rとなるxの範囲が重ならないように分割する
  6087:     //    nのときt=rに対応するxとn+1のときt=-rに対応するxが等しくなるようにする
  6088:     //      1-2*(1-r)/((2^n+1)+(2^n-1)*r)=1-2*(1-(-r))/((2^(n+1)+1)+(2^(n+1)-1)*(-r))
  6089:     //      (1-r)/((2^n+1)+(2^n-1)*r)=(1+r)/((2*2^n+1)-(2*2^n-1)*r)
  6090:     //      (1-r)*((2*2^n+1)-(2*2^n-1)*r)-(1+r)*((2^n+1)+(2^n-1)*r)=0
  6091:     //      ((2*2^n+1)-(2*2^n-1)*r)-((2*2^n+1)-(2*2^n-1)*r)*r-((2^n+1)+(2^n-1)*r)-((2^n+1)+(2^n-1)*r)*r=0
  6092:     //      (2*2^n+1)-(2*2^n-1)*r-(2*2^n+1)*r+(2*2^n-1)*r^2-(2^n+1)-(2^n-1)*r-(2^n+1)*r-(2^n-1)*r^2=0
  6093:     //      (2*2^n-1)*r^2-(2^n-1)*r^2-(2*2^n-1)*r-(2*2^n+1)*r-(2^n-1)*r-(2^n+1)*r+(2*2^n+1)-(2^n+1)=0
  6094:     //      (2*2^n-1-2^n+1)*r^2-(2*2^n-1+2*2^n+1+2^n-1+2^n+1)*r+(2*2^n+1-2^n-1)=0
  6095:     //      (2^n)*r^2-(6*2^n)*r+(2^n)=0
  6096:     //      r^2-6*r+1=0
  6097:     //      r=3+/-2*sqrt(2)
  6098:     //      r=3-2*sqrt(2)
  6099:     //    t=rのときのxは
  6100:     //      x=1-2*(1-r)/((2^n+1)+(2^n-1)*r)
  6101:     //       =1-2*(1-(3-2*sqrt(2)))/((2^n+1)+(2^n-1)*(3-2*sqrt(2)))
  6102:     //       =1-2*(sqrt(2)-1)/((2*2^n-1)-(2^n-1)*sqrt(2))
  6103:     //       =1-2*(sqrt(2)-1)*((2*2^n-1)+(2^n-1)*sqrt(2))/((2*2^n-1)-(2^n-1)*sqrt(2))/((2*2^n-1)+(2^n-1)*sqrt(2))
  6104:     //       =1-2*((2*2^n-1)*sqrt(2)+2*(2^n-1)-(2*2^n-1)-(2^n-1)*sqrt(2))/((2*2^n-1)^2-2*(2^n-1)^2)
  6105:     //       =1-2*((2*2^n-1-2^n+1)*sqrt(2)+(2*2^n-2-2*2^n+1))/(4*4^n-4*2^n+1-2*4^n+4*2^n-2)
  6106:     //       =1-2*(2^n*sqrt(2)-1)/(2*4^n-1)
  6107:     //       =1-2*(2^n*sqrt(2)-1)/((2^n*sqrt(2)-1)*(2^n*sqrt(2)+1))
  6108:     //       =1-2/(2^n*sqrt(2)+1)
  6109:     //    したがって、|x|<1を
  6110:     //       1-2/(2^n*sqrt(2)+1)={3-2*sqrt(2),(9-4*sqrt(2))/7,(33-8*sqrt(2))/31,(129-16*sqrt(2))/127,(513-32*sqrt(2))/511,...}
  6111:     //    で分割すると、|t|<=3-2*sqrt(2)になる
  6112:     //    perl -e "use POSIX;sub log2{my($x)=@_;log($x)/log(2);}printf'    //    %4s%10s%10s%11s%18s%c','n','x','1-x','log2(1-x)','floor(log2(1-x))',10;for$n(0..10){$x=1-2/(2**$n*sqrt(2)+1);printf'    //    %4d%10.6f%10.6f%11.6f%18d%c',$n,$x,1-$x,log2(1-$x),floor(log2(1-$x)),10}"
  6113:     //       n         x       1-x  log2(1-x)  floor(log2(1-x))
  6114:     //       0  0.171573  0.828427  -0.271553                -1
  6115:     //       1  0.477592  0.522408  -0.936752                -1
  6116:     //       2  0.699558  0.300442  -1.734841                -2
  6117:     //       3  0.837579  0.162421  -2.622193                -3
  6118:     //       4  0.915353  0.084647  -3.562390                -4
  6119:     //       5  0.956761  0.043239  -4.531532                -5
  6120:     //       6  0.978144  0.021856  -5.515852                -6
  6121:     //       7  0.989012  0.010988  -6.507948                -7
  6122:     //       8  0.994491  0.005509  -7.503979                -8
  6123:     //       9  0.997242  0.002758  -8.501991                -9
  6124:     //      10  0.998620  0.001380  -9.500996               -10
  6125:     //    手順
  6126:     //      if(|x|<=3-2*sqrt(2)){
  6127:     //        //変数変換を行わない
  6128:     //        //|x|<0.5に区切りが2箇所あるのでn=0を分けなければならない
  6129:     //        //|x|が小さすぎると1-|x|が1になってしまうので1-|x|を経由する方法では正確に計算できない
  6130:     //        //xで多項式を計算する
  6131:     //      }else{
  6132:     //        n=-floor(log2(1-|x|));  //1-|x|の指数部を取り出して符号を反転したもの。1以上
  6133:     //        if(1-2/(2^n*sqrt(2)+1)<|x|){  //1-2/(2^n*sqrt(2)+1)は高々LEN通りしかないのでテーブルに列挙しておく
  6134:     //          n++;
  6135:     //        }
  6136:     //        t=(1+|x|-2^n*(1-|x|))/(1+|x|+2^n*(1-|x|))
  6137:     //        //tで多項式を計算する
  6138:     //        //n*log(2)/2を加える
  6139:     //        //xの符号を掛ける
  6140:     //      }
  6141:     //    x→tのグラフ
  6142:     //    perl -e "use POSIX;use Graph;sub log2{my($x)=@_;log($x)/log(2);}$g=new Graph(80,40,-1,1,-1,1);$g->grid();$g->func(sub{my$x=$_[0];if(1<=abs($x)){$t=undef;}elsif(abs($x)<=3-2*sqrt(2)){$t=$x;}else{$n=-floor(log2(1-abs($x)));if(1-2/(2**$n*sqrt(2)+1)<abs($x)){$n++;}$t=($x<=>0)*(1+abs($x)-2**$n*(1-abs($x)))/(1+abs($x)+2**$n*(1-abs($x)));}$t});print$g"
  6143:     //                                            +                                        
  6144:     //                                            |                                        
  6145:     //                                            |                                        
  6146:     //                                            |                                        
  6147:     //                                            |                                        
  6148:     //                                            |                                        
  6149:     //                                            |                                        
  6150:     //                                            |                                        
  6151:     //                                            |                                        
  6152:     //                                            |                                        
  6153:     //                                            |                                        
  6154:     //                                            |                                        
  6155:     //                                            |                                        
  6156:     //                                            |                                        
  6157:     //                                            |                                        
  6158:     //                                            |                                        
  6159:     //                                            |                                        
  6160:     //    ****  *    **      ***         ***      |    ***          **       **    ** *****
  6161:     //    **** **   **      **         ***        |  ***          ***       **    **  * ***
  6162:     //    ** * *   **      **         **          |***          ***        **    **   * ***
  6163:     //    ******---*-----***--------***----------***----------***--------***-----*---******
  6164:     //    *** *   **    **        ***          ***|          **         **      **   * * **
  6165:     //    *** *  **    **       ***          ***  |        ***         **      **   ** ****
  6166:     //    ***** **    **       **          ***    |      ***         ***      **    *  ****
  6167:     //                                            |                                        
  6168:     //                                            |                                        
  6169:     //                                            |                                        
  6170:     //                                            |                                        
  6171:     //                                            |                                        
  6172:     //                                            |                                        
  6173:     //                                            |                                        
  6174:     //                                            |                                        
  6175:     //                                            |                                        
  6176:     //                                            |                                        
  6177:     //                                            |                                        
  6178:     //                                            |                                        
  6179:     //                                            |                                        
  6180:     //                                            |                                        
  6181:     //                                            |                                        
  6182:     //                                            |                                        
  6183:     //                                            +                                        
  6184:     //
  6185:     //  チェビシェフ展開
  6186:     //    |x|<3-2*sqrt(2)
  6187:     //    echo read("efp.gp");a=2*sqrt(2)-3;b=-a;nmax=55;print1("    //    ");forstep(n=1,nmax,2,printf("%4d",n));print();print1("    //    ");forstep(n=1,nmax,2,printf("%4d",floor(closeness(atanh,chebyshev(atanh,a,b,n),a,b,10000))));print() | gp -q
  6188:     //       1   3   5   7   9  11  13  15  17  19  21  23  25  27  29  31  33  35  37  39  41  43  45  47  49  51  53  55
  6189:     //       7  14  21  28  35  42  49  56  63  70  77  84  91  98 105 113 120 127 134 141 148 155 162 169 176 183 190 197
  6190:     //
  6191:     //  CORDIC
  6192:     //    atanh(y/x)のときxとyを両方入力することで除算が不要になる
  6193:     //    tanh(t)=sinh(t)/cosh(t)
  6194:     //    t=atanh(sinh(t)/cosh(t))
  6195:     //
  6196:     public final EFP atanh () {
  6197:       return this.atanh (this);
  6198:     }  //efp.atanh()
  6199:     public final EFP atanh (EFP x) {
  6200:       int xf = x.flg;
  6201:       if (xf << 1 != 0) {  //±0,±Inf,NaN
  6202:         if (xf << 2 < 0) {  //±Inf
  6203:           epbFpsr |= EPB_FPSR_OE;
  6204:           epbExceptionOperandExponent = xf & M | 0x7fff << 16;
  6205:           epbExceptionOperandMantissa = 0x0000000000000000L;
  6206:           this.flg = N;  //atanh(±Inf)=NaN
  6207:         } else {
  6208:           this.flg = xf;  //atanh(±0)=±0, atanh(NaN)=NaN
  6209:         }
  6210:         return this;
  6211:       }
  6212:       //±0,±Inf,NaN以外
  6213:       int xe = x.epp;
  6214:       if (0 <= xe) {  //1<=|x|
  6215:         if (xe == 0 && x.dvl == MSB && x.cvl == 0L) {  //|x|==1
  6216:           epbFpsr |= EPB_FPSR_DZ;
  6217:           epbExceptionOperandExponent = xf | 0x3fff << 16;
  6218:           epbExceptionOperandMantissa = 0x8000000000000000L;
  6219:           this.flg = xf | I;
  6220:         } else {  //1<|x|
  6221:           epbFpsr |= EPB_FPSR_OE;
  6222:           epbExceptionOperandExponent = xf | 0x3fff + x.epp << 16;
  6223:           epbExceptionOperandMantissa = x.dvl;
  6224:           this.flg = N;
  6225:         }
  6226:         return this;
  6227:       }
  6228:       //|x|<1
  6229:       if (false) {  //logを使う。[89] 540ns
  6230:         if (x.epp < -4) {  //|x|<0.0625
  6231:           EFP x2 = new EFP ().inner ().isqu (x);  //x^2
  6232:           return this.imul (ATANH_C19, x2)
  6233:             .iadd (ATANH_C17).imul (x2)
  6234:               .iadd (ATANH_C15).imul (x2)
  6235:                 .iadd (ATANH_C13).imul (x2)
  6236:                   .iadd (ATANH_C11).imul (x2)
  6237:                     .iadd (ATANH_C9).imul (x2)
  6238:                       .iadd (ATANH_C7).imul (x2)
  6239:                         .iadd (ATANH_C5).imul (x2)
  6240:                           .iadd (ATANH_C3).imul (x2)
  6241:                             .iadd (ATANH_C1).outer ().mul (x);
  6242:         }
  6243:         //0.0625<=|x|
  6244:         this.inner ().iabs (x);  //|x|
  6245:         EFP t = new EFP ().negdec (this);  //1-|x|
  6246:         return this.inc ().div (t).log ().idiv2 ().outer ().neg (xf < 0);  //sgn(x)*log((1+|x|)/(1-|x|))/2
  6247:       } else {  //|x|<3-2*sqrt(2)に畳む。[90] 425ns
  6248:         int savedFpsr = epbFpsr;
  6249:         this.inner ();
  6250:         long xd = x.dvl;
  6251:         long xc = x.cvl;
  6252:         if (xe <= -3 && (xe < -3 || xd <= 0xafb0ccc06219b7baL)) {  //|x|<=3-2*sqrt(2)。xcの比較は省略
  6253:           if (this == x) {
  6254:             x = new EFP (x);  //必要なときだけコピーする
  6255:           }
  6256:           EFP x2 = new EFP ().isqu (x);  //x^2
  6257:           /*
  6258:           return this.imul (ATH_C25, x2)
  6259:             .iadd (ATH_C23).imul (x2)
  6260:               .iadd (ATH_C21).imul (x2)
  6261:                 .iadd (ATH_C19).imul (x2)
  6262:                   .iadd (ATH_C17).imul (x2)
  6263:                     .iadd (ATH_C15).imul (x2)
  6264:                       .iadd (ATH_C13).imul (x2)
  6265:                         .iadd (ATH_C11).imul (x2)
  6266:                           .iadd (ATH_C9).imul (x2)
  6267:                             .iadd (ATH_C7).imul (x2)
  6268:                               .iadd (ATH_C5).imul (x2)
  6269:                                 .iadd (ATH_C3).imul (x2)
  6270:                                   .iadd (ATH_C1).outer ().mul (x);
  6271:            */
  6272:           this.imul (ATH_C27, x2)
  6273:             .iadd (ATH_C25).imul (x2)
  6274:               .iadd (ATH_C23).imul (x2)
  6275:                 .iadd (ATH_C21).imul (x2)
  6276:                   .iadd (ATH_C19).imul (x2)
  6277:                     .iadd (ATH_C17).imul (x2)
  6278:                       .iadd (ATH_C15).imul (x2)
  6279:                         .iadd (ATH_C13).imul (x2)
  6280:                           .iadd (ATH_C11).imul (x2)
  6281:                             .iadd (ATH_C9).imul (x2)
  6282:                               .iadd (ATH_C7).imul (x2)
  6283:                                 .iadd (ATH_C5).imul (x2)
  6284:                                   .iadd (ATH_C3).imul (x2)
  6285:                                     .iadd (ATH_C1).outer ().mul (x);
  6286:           return this.originLowerUpper (x).correctUnderflow (savedFpsr);
  6287:         }
  6288:         EFP a = new EFP (P, xe, xd, xc);  //|x|
  6289:         EFP t = new EFP ().negdec (a);  //1-|x|
  6290:         int n = -t.epp;  //-floor(log2(1-|x|))
  6291:         if (ATH_T[n].lt (a)) {  //1-2/(2^n*sqrt(2)+1)<|x|
  6292:           n++;
  6293:         }
  6294:         EFP u = new EFP ().iadd (a.inc (), t.shl (n));
  6295:         t.negsub (a).div (u);  //(1+|x|-2^n*(1-|x|))/(1+|x|+2^n*(1-|x|))
  6296:         a.isqu (t);  //t^2
  6297:         /*
  6298:         return this.imul (ATH_C25, a)
  6299:           .iadd (ATH_C23).imul (a)
  6300:             .iadd (ATH_C21).imul (a)
  6301:               .iadd (ATH_C19).imul (a)
  6302:                 .iadd (ATH_C17).imul (a)
  6303:                   .iadd (ATH_C15).imul (a)
  6304:                     .iadd (ATH_C13).imul (a)
  6305:                       .iadd (ATH_C11).imul (a)
  6306:                         .iadd (ATH_C9).imul (a)
  6307:                           .iadd (ATH_C7).imul (a)
  6308:                             .iadd (ATH_C5).imul (a)
  6309:                               .iadd (ATH_C3).imul (a)
  6310:                                 .iadd (ATH_C1).imul (t).iadd (t.muli (LOG_2_2, n)).outer ().neg (xf < 0);  //+n*log(2)/2
  6311:          */
  6312:         return this.imul (ATH_C27, a)
  6313:           .iadd (ATH_C25).imul (a)
  6314:             .iadd (ATH_C23).imul (a)
  6315:               .iadd (ATH_C21).imul (a)
  6316:                 .iadd (ATH_C19).imul (a)
  6317:                   .iadd (ATH_C17).imul (a)
  6318:                     .iadd (ATH_C15).imul (a)
  6319:                       .iadd (ATH_C13).imul (a)
  6320:                         .iadd (ATH_C11).imul (a)
  6321:                           .iadd (ATH_C9).imul (a)
  6322:                             .iadd (ATH_C7).imul (a)
  6323:                               .iadd (ATH_C5).imul (a)
  6324:                                 .iadd (ATH_C3).imul (a)
  6325:                                   .iadd (ATH_C1).imul (t).iadd (t.muli (LOG_2_2, n)).outer ().neg (xf < 0);  //+n*log(2)/2
  6326:       }
  6327:     }  //efp.atanh(EFP)
  6328: 
  6329:     //------------------------------------------------------------------------
  6330:     //x = x.cbrt ()
  6331:     //  x=x^(1/3)
  6332:     //y = y.cbrt (x)
  6333:     //  y=x^(1/3)
  6334:     //  1/3乗(立方根)
  6335:     //
  6336:     //  グラフ
  6337:     //    perl -e "use Graph;$g=new Graph();$g->grid();$g->func(sub{($_[0]<=>0)*abs($_[0])**(1/3)});print$g"
  6338:     //    echo read("efp.gp");eval("cbrt(x)=sign(x)*abs(x)^(1/3)");graph(cbrt) | gp -q
  6339:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
  6340:     //    |                                       |                                       |
  6341:     //    |                                       |                                       |
  6342:     //    |                                       |                                       |
  6343:     //    |                                       |                                       |
  6344:     //    +                                       +                                       +
  6345:     //    |                                       |                                       |
  6346:     //    |                                       |                                       |
  6347:     //    |                                       |                                       |
  6348:     //    |                                       |                                       |
  6349:     //    +                                       +                                       +
  6350:     //    |                                       |                                       |
  6351:     //    |                                       |                                 *******
  6352:     //    |                                       |                     *************     |
  6353:     //    |                                       |            **********                 |
  6354:     //    +                                       +      *******                          +
  6355:     //    |                                       |  *****                                |
  6356:     //    |                                       |***                                    |
  6357:     //    |                                       **                                      |
  6358:     //    |                                       *                                       |
  6359:     //    +---------+---------+---------+---------*---------+---------+---------+---------+
  6360:     //    |                                       *                                       |
  6361:     //    |                                      **                                       |
  6362:     //    |                                    ***|                                       |
  6363:     //    |                                *****  |                                       |
  6364:     //    +                          *******      +                                       +
  6365:     //    |                 **********            |                                       |
  6366:     //    |     *************                     |                                       |
  6367:     //    *******                                 |                                       |
  6368:     //    |                                       |                                       |
  6369:     //    +                                       +                                       +
  6370:     //    |                                       |                                       |
  6371:     //    |                                       |                                       |
  6372:     //    |                                       |                                       |
  6373:     //    |                                       |                                       |
  6374:     //    +                                       +                                       +
  6375:     //    |                                       |                                       |
  6376:     //    |                                       |                                       |
  6377:     //    |                                       |                                       |
  6378:     //    |                                       |                                       |
  6379:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
  6380:     //
  6381:     //  定義域
  6382:     //    -inf<=x<=inf
  6383:     //
  6384:     //  値域
  6385:     //    -inf<=y<=inf
  6386:     //
  6387:     //  ニュートン法
  6388:     //    f(t)=t^3-x
  6389:     //    f'(t)=3*t^2
  6390:     //    t'=t-f(t)/f'(t)
  6391:     //      =t-(t^3-x)/(3*t^2)
  6392:     //      =(2*t^3+x)/(3*t^2)
  6393:     //      =(2*t+x/t^2)/3
  6394:     //
  6395:     public final EFP cbrt () {
  6396:       return this.cbrt (this);
  6397:     }  //efp.cbrt()
  6398:     public final EFP cbrt (EFP x) {
  6399:       int xf = x.flg;
  6400:       if (xf << 1 != 0) {  //±0,±Inf,NaN
  6401:         this.flg = xf;
  6402:         return this;
  6403:       }
  6404:       //±0,±Inf,NaN以外
  6405:       if (false) {  //ニュートン法。[90] 1095.4ns
  6406:         this.inner ();
  6407:         EFP s = new EFP ().sgn (x);
  6408:         EFP a = new EFP ().iabs (x);
  6409:         EFP t = new EFP ().iadd (TWO, a).div3 ();  //t=(2+a)/3
  6410:         EFP w = new EFP ();
  6411:         do {
  6412:           //this.sete (t);
  6413:           this.flg = t.flg;
  6414:           this.epp = t.epp;
  6415:           this.dvl = t.dvl;
  6416:           this.cvl = t.cvl;
  6417:           w.isqu (t).mul3 ();  //3*t^2
  6418:           t.cub ().imul2 ().iadd (a).div (w);  //t=(2*t^3+a)/(3*t^2)
  6419:         } while (this.gt (t));
  6420:         return this.outer ().mul (s);
  6421:       } else {  //Math.cbrtを使う。[91] 214ns
  6422:         this.inner ();
  6423:         int xe = x.epp;  //-32768..32767
  6424:         int xe3 = (int) (xe * 43691L >> 17);  //xe / 3
  6425:         long s = Double.doubleToLongBits (Math.cbrt (Double.longBitsToDouble ((long) (1023 + (xe - xe3 * 3)) << 52 | x.dvl << 1 >>> 12)));
  6426:         EFP t = new EFP (P, (int) (s >>> 52) - 1023 + xe3, MSB | s << 12 >>> 1, 0L);
  6427:         EFP t2 = new EFP ().imul2 (t);
  6428:         t2.flg |= xf;
  6429:         return this.iadd (t2, t.isqu ().rcpdiv (x)).outer ().div3 ();  //(2*t+x/t^2)/3
  6430:       }
  6431:     }  //efp.cbrt(EFP)
  6432: 
  6433:     //------------------------------------------------------------------------
  6434:     //x = x.ceil ()
  6435:     //  x=ceil(x)
  6436:     //y = y.ceil (x)
  6437:     //  y=ceil(x)
  6438:     //  天井関数 ceiling function
  6439:     //
  6440:     //  グラフ
  6441:     //    perl -e "use POSIX;use Graph;$g=new Graph();$g->grid();$g->func(sub{ceil($_[0])});print$g"
  6442:     //    echo read("efp.gp");graph(ceil) | gp -q
  6443:     //    +---------+---------+---------+---------+---------+---------+---------***********
  6444:     //    |                                       |                                       |
  6445:     //    |                                       |                                       |
  6446:     //    |                                       |                                       |
  6447:     //    |                                       |                                       |
  6448:     //    +                                       +                   ***********         +
  6449:     //    |                                       |                                       |
  6450:     //    |                                       |                                       |
  6451:     //    |                                       |                                       |
  6452:     //    |                                       |                                       |
  6453:     //    +                                       +         ***********                   +
  6454:     //    |                                       |                                       |
  6455:     //    |                                       |                                       |
  6456:     //    |                                       |                                       |
  6457:     //    |                                       |                                       |
  6458:     //    +                                       ***********                             +
  6459:     //    |                                       |                                       |
  6460:     //    |                                       |                                       |
  6461:     //    |                                       |                                       |
  6462:     //    |                                       |                                       |
  6463:     //    +---------+---------+---------***********---------+---------+---------+---------+
  6464:     //    |                                       |                                       |
  6465:     //    |                                       |                                       |
  6466:     //    |                                       |                                       |
  6467:     //    |                                       |                                       |
  6468:     //    +                   ***********         +                                       +
  6469:     //    |                                       |                                       |
  6470:     //    |                                       |                                       |
  6471:     //    |                                       |                                       |
  6472:     //    |                                       |                                       |
  6473:     //    +         ***********                   +                                       +
  6474:     //    |                                       |                                       |
  6475:     //    |                                       |                                       |
  6476:     //    |                                       |                                       |
  6477:     //    |                                       |                                       |
  6478:     //    ***********                             +                                       +
  6479:     //    |                                       |                                       |
  6480:     //    |                                       |                                       |
  6481:     //    |                                       |                                       |
  6482:     //    |                                       |                                       |
  6483:     //    *---------+---------+---------+---------+---------+---------+---------+---------+
  6484:     //
  6485:     public final EFP ceil () {
  6486:       return this.ceil (this);
  6487:     }  //efp.ceil()
  6488:     public final EFP ceil (EFP x) {  //2.8ns
  6489:       int xf = x.flg;
  6490:       if (xf << 1 != 0) {  //±0,±Inf,NaN
  6491:         this.flg = xf;
  6492:         return this;
  6493:       }
  6494:       //±0,±Inf,NaN以外
  6495:       int xe = x.epp;
  6496:       if (xe < 0) {  //すべて小数部
  6497:         epbFpsr |= EPB_FPSR_X2;  //不正確な結果
  6498:         if (xf < 0) {  //ceil(-1<x<0)=-0
  6499:           this.flg = M | Z;
  6500:         } else {  //ceil(0<x<1)=+1
  6501:           this.flg = P;
  6502:           this.epp = 0;
  6503:           this.dvl = MSB;
  6504:           this.cvl = 0L;
  6505:         }
  6506:         return this;
  6507:       }
  6508:       //整数部がある
  6509:       long xd = x.dvl;
  6510:       long xc = x.cvl;
  6511:       long m = MSB >> xe;  //整数部のマスク。符号に注意
  6512:       if (xf < 0) {  //ceil(x<0)=trunc(x)。小数部を切り捨てる
  6513:         if (xe <= 63) {  //0..63。dの途中または末尾まで整数部
  6514:           if ((xd & ~m | xc) != 0L) {  //小数部が0ではない
  6515:             epbFpsr |= EPB_FPSR_X2;  //不正確な結果
  6516:             xd &= m;  //小数部を切り捨てる
  6517:             xc = 0L;
  6518:           }
  6519:         } else if (xe <= LEN - 2) {  //64..90。cの途中まで整数部
  6520:           if ((xc & ~m) != 0L) {  //小数部が0ではない
  6521:             epbFpsr |= EPB_FPSR_X2;  //不正確な結果
  6522:             xc &= m;  //小数部を切り捨てる
  6523:           }
  6524:         }
  6525:         //すべて整数部のときはそのまま
  6526:       } else {  //ceil(0<x)。小数部を切り捨てる。小数部が0でなかったときは絶対値に1を加える
  6527:         if (xe <= 63) {  //0..63。dの途中または末尾まで整数部
  6528:           long t = xd;  //保存して
  6529:           xd &= m;  //小数部を切り捨てる
  6530:           if (((t ^ xd) | xc) != 0L) {  //小数部が0でなかった
  6531:             epbFpsr |= EPB_FPSR_X2;  //不正確な結果
  6532:             xd -= m;  //絶対値に1を加える。符号に注意
  6533:             if (xd >= 0L) {  //dから溢れた
  6534:               xd = MSB;
  6535:               xe++;
  6536:               if ((short) xe != xe) {  //オーバーフローした
  6537:                 epbFpsr |= EPB_FPSR_OF;  //オーバーフロー
  6538:                 epbExceptionOperandExponent = xf;
  6539:                 epbExceptionOperandMantissa = xd;
  6540:                 return this.sete (OVFL_RESULTS[epbRoundingPrec << 3 | epbRoundingMode << 1 | xf >>> 31]).finish ();  //±Inf
  6541:               }
  6542:             }
  6543:             xc = 0L;
  6544:           }
  6545:           //小数部が0のときはそのまま
  6546:         } else if (xe <= LEN - 2) {  //64..90。cの途中まで整数部
  6547:           long t = xc;  //保存して
  6548:           xc &= m;  //小数部を切り捨てる
  6549:           if ((t ^ xc) != 0L) {  //小数部が0でなかった
  6550:             epbFpsr |= EPB_FPSR_X2;  //不正確な結果
  6551:             xc -= m;  //絶対値に1を加える。符号に注意
  6552:             if ((t ^ xc) < 0L) {  //cから溢れた
  6553:               xd++;
  6554:               if (xd >= 0L) {  //dから溢れた
  6555:                 xd = MSB;
  6556:                 xe++;
  6557:                 if ((short) xe != xe) {  //オーバーフローした
  6558:                   epbFpsr |= EPB_FPSR_OF;  //オーバーフロー
  6559:                   epbExceptionOperandExponent = xf;
  6560:                   epbExceptionOperandMantissa = xd;
  6561:                   return this.sete (OVFL_RESULTS[epbRoundingPrec << 3 | epbRoundingMode << 1 | xf >>> 31]).finish ();  //±Inf
  6562:                 }
  6563:               }
  6564:             }
  6565:           }
  6566:         }
  6567:         //すべて整数部のときはそのまま
  6568:       }
  6569:       return this.finish (xf, xe, xd, xc, 0L);
  6570:     }  //efp.ceil(EFP)
  6571: 
  6572:     //------------------------------------------------------------------------
  6573:     //s = x.cmp (y)
  6574:     //  s=x<=>y
  6575:     //  比較
  6576:     //
  6577:     //  -Inf==-Inf<-x<-0==+0<+x<+Inf==+Inf
  6578:     //
  6579:     //  NaNの扱い
  6580:     //    どちらかがNaNのときは0を返す
  6581:     //    どちらかがNaNのときにNaNを返すのはx.sgnsub(y)
  6582:     //
  6583:     //  ±0の扱い
  6584:     //    両方が±0のときは符号に関係なく0を返す
  6585:     //
  6586:     //  関係演算子および等価演算子との違い
  6587:     //    doubleのNaNはNaNを含むすべての数と等しくなく大きくなく小さくもないので-1,0,1に分類できない
  6588:     //
  6589:     //  x.compareTo(y)との違い
  6590:     //    x.compareTo(y)はx.equals(y)と一貫性を保つためにNaNを含むすべての数について大小関係が定められている
  6591:     //    -Inf==-Inf<x<-0<+0<+x<+Inf==+Inf<NaN
  6592:     //    ((Double)x).compareTo(y)とDouble.compare(double,double)も同様
  6593:     //
  6594:     //  xn/xd<=>yn/yd
  6595:     //    =xn*yd<=>xd*yn  (xd>0,yd>0)
  6596:     //
  6597:     public int cmp (EFP y) {
  6598:       int xf = this.flg;
  6599:       int yf = y.flg;
  6600:       if ((xf | yf) << 1 != 0) {  //どちらかが±0,±Inf,NaN
  6601:         //return ((xf | yf) << 3 < 0 || (xf & yf) << 1 < 0 || xf == yf ? 0 :  //どちらかがNaNまたは両方±0または両方-Infまたは両方+Inf
  6602:         //        (xf ^ yf) < 0 ? xf >= 0 ? 1 : -1 :  //両方NaN以外でどちらかが±0,±Infで符号が違う
  6603:         //        xf == (P | I) || yf == (P | Z) || xf == (M | Z) || yf == (M | I) ? 1 : -1);  //両方NaN以外でどちらかが±0,±Infで符号が同じ
  6604:         return EFP_CMP_TABLE[xf >>> 28] << (yf >>> 28 - 1) >> 30;
  6605:       }
  6606:       //両方±0,±Inf,NaN以外
  6607:       if (xf != yf) {  //両方±0,±Inf,NaN以外で符号が違う
  6608:         return xf >= 0 ? 1 : -1;
  6609:       }
  6610:       //両方±0,±Inf,NaN以外で符号が同じ
  6611:       int s;
  6612:       long t;
  6613:       return (xf >= 0 ? 1 : -1) * ((s = this.epp - y.epp) != 0 ? s >= 0 ? 1 : -1 :
  6614:                                    (t = this.dvl - y.dvl) != 0L ? t >= 0L ? 1 : -1 :
  6615:                                    (t = (this.cvl >>> 1) - (y.cvl >>> 1)) != 0L ? t >= 0L ? 1 : -1 :
  6616:                                    0);
  6617:     }  //efp.cmp(EFP)
  6618: 
  6619:     //------------------------------------------------------------------------
  6620:     //s = x.cmp0 ()
  6621:     //  s=x<=>0
  6622:     //  0との比較
  6623:     //
  6624:     //  グラフ
  6625:     //    perl -e "use Graph;$g=new Graph();$g->grid();$g->func(sub{$_[0]<=>0});print$g"
  6626:     //    echo read("efp.gp");graph(sign) | gp -q
  6627:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
  6628:     //    |                                       |                                       |
  6629:     //    |                                       |                                       |
  6630:     //    |                                       |                                       |
  6631:     //    |                                       |                                       |
  6632:     //    +                                       +                                       +
  6633:     //    |                                       |                                       |
  6634:     //    |                                       |                                       |
  6635:     //    |                                       |                                       |
  6636:     //    |                                       |                                       |
  6637:     //    +                                       +                                       +
  6638:     //    |                                       |                                       |
  6639:     //    |                                       |                                       |
  6640:     //    |                                       |                                       |
  6641:     //    |                                       |                                       |
  6642:     //    +                                       *****************************************
  6643:     //    |                                       |                                       |
  6644:     //    |                                       |                                       |
  6645:     //    |                                       |                                       |
  6646:     //    |                                       |                                       |
  6647:     //    +---------+---------+---------+---------*---------+---------+---------+---------+
  6648:     //    |                                       |                                       |
  6649:     //    |                                       |                                       |
  6650:     //    |                                       |                                       |
  6651:     //    |                                       |                                       |
  6652:     //    *****************************************                                       +
  6653:     //    |                                       |                                       |
  6654:     //    |                                       |                                       |
  6655:     //    |                                       |                                       |
  6656:     //    |                                       |                                       |
  6657:     //    +                                       +                                       +
  6658:     //    |                                       |                                       |
  6659:     //    |                                       |                                       |
  6660:     //    |                                       |                                       |
  6661:     //    |                                       |                                       |
  6662:     //    +                                       +                                       +
  6663:     //    |                                       |                                       |
  6664:     //    |                                       |                                       |
  6665:     //    |                                       |                                       |
  6666:     //    |                                       |                                       |
  6667:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
  6668:     //
  6669:     //  x.cmp(0)と同じ
  6670:     //
  6671:     public int cmp0 () {
  6672:       int xf = this.flg;
  6673:       return xf << 3 < 0 || xf << 1 < 0 ? 0 : xf >= 0 ? 1 : -1;
  6674:     }  //efp.cmp0()
  6675: 
  6676:     //------------------------------------------------------------------------
  6677:     //s = x.cmp1 ()
  6678:     //  s=x<=>1
  6679:     //  1との比較
  6680:     //
  6681:     //  グラフ
  6682:     //    perl -e "use Graph;$g=new Graph();$g->grid();$g->func(sub{$_[0]<=>1});print$g"
  6683:     //    echo read("efp.gp");eval("cmp1(x)=sign(x-1)");graph(cmp1) | gp -q
  6684:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
  6685:     //    |                                       |                                       |
  6686:     //    |                                       |                                       |
  6687:     //    |                                       |                                       |
  6688:     //    |                                       |                                       |
  6689:     //    +                                       +                                       +
  6690:     //    |                                       |                                       |
  6691:     //    |                                       |                                       |
  6692:     //    |                                       |                                       |
  6693:     //    |                                       |                                       |
  6694:     //    +                                       +                                       +
  6695:     //    |                                       |                                       |
  6696:     //    |                                       |                                       |
  6697:     //    |                                       |                                       |
  6698:     //    |                                       |                                       |
  6699:     //    +                                       +         *******************************
  6700:     //    |                                       |                                       |
  6701:     //    |                                       |                                       |
  6702:     //    |                                       |                                       |
  6703:     //    |                                       |                                       |
  6704:     //    +---------+---------+---------+---------+---------*---------+---------+---------+
  6705:     //    |                                       |                                       |
  6706:     //    |                                       |                                       |
  6707:     //    |                                       |                                       |
  6708:     //    |                                       |                                       |
  6709:     //    ***************************************************                             +
  6710:     //    |                                       |                                       |
  6711:     //    |                                       |                                       |
  6712:     //    |                                       |                                       |
  6713:     //    |                                       |                                       |
  6714:     //    +                                       +                                       +
  6715:     //    |                                       |                                       |
  6716:     //    |                                       |                                       |
  6717:     //    |                                       |                                       |
  6718:     //    |                                       |                                       |
  6719:     //    +                                       +                                       +
  6720:     //    |                                       |                                       |
  6721:     //    |                                       |                                       |
  6722:     //    |                                       |                                       |
  6723:     //    |                                       |                                       |
  6724:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
  6725:     //
  6726:     //  x.cmp(1)と同じ
  6727:     //
  6728:     public int cmp1 () {
  6729:       int xf = this.flg;
  6730:       if (xf != 0) {  //-x,±0,±Inf,NaN
  6731:         return xf << 3 < 0 ? 0 : (xf | xf << 1) < 0 ? -1 : 1;
  6732:       }
  6733:       //+x
  6734:       int xe = this.epp;  //xの指数
  6735:       return xe < 0 ? -1 : xe == 0 && this.dvl == MSB && this.cvl == 0L ? 0 : 1;
  6736:     }  //efp.cmp1()
  6737: 
  6738:     //------------------------------------------------------------------------
  6739:     //s = x.cmp1abs ()
  6740:     //  s=|x|<=>1
  6741:     //  絶対値と1の比較
  6742:     //
  6743:     //  グラフ
  6744:     //    perl -e "use Graph;$g=new Graph();$g->grid();$g->func(sub{abs($_[0])<=>1});print$g"
  6745:     //    echo read("efp.gp");eval("cmp1abs(x)=sign(abs(x)-1)");graph(cmp1abs) | gp -q
  6746:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
  6747:     //    |                                       |                                       |
  6748:     //    |                                       |                                       |
  6749:     //    |                                       |                                       |
  6750:     //    |                                       |                                       |
  6751:     //    +                                       +                                       +
  6752:     //    |                                       |                                       |
  6753:     //    |                                       |                                       |
  6754:     //    |                                       |                                       |
  6755:     //    |                                       |                                       |
  6756:     //    +                                       +                                       +
  6757:     //    |                                       |                                       |
  6758:     //    |                                       |                                       |
  6759:     //    |                                       |                                       |
  6760:     //    |                                       |                                       |
  6761:     //    *******************************         +         *******************************
  6762:     //    |                                       |                                       |
  6763:     //    |                                       |                                       |
  6764:     //    |                                       |                                       |
  6765:     //    |                                       |                                       |
  6766:     //    +---------+---------+---------*---------+---------*---------+---------+---------+
  6767:     //    |                                       |                                       |
  6768:     //    |                                       |                                       |
  6769:     //    |                                       |                                       |
  6770:     //    |                                       |                                       |
  6771:     //    +                             *********************                             +
  6772:     //    |                                       |                                       |
  6773:     //    |                                       |                                       |
  6774:     //    |                                       |                                       |
  6775:     //    |                                       |                                       |
  6776:     //    +                                       +                                       +
  6777:     //    |                                       |                                       |
  6778:     //    |                                       |                                       |
  6779:     //    |                                       |                                       |
  6780:     //    |                                       |                                       |
  6781:     //    +                                       +                                       +
  6782:     //    |                                       |                                       |
  6783:     //    |                                       |                                       |
  6784:     //    |                                       |                                       |
  6785:     //    |                                       |                                       |
  6786:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
  6787:     //
  6788:     //  t.abs(x).cmp1()と同じ
  6789:     //
  6790:     public int cmp1abs () {
  6791:       int xf = this.flg;
  6792:       if (xf << 1 != 0) {  //±0,±Inf,NaN
  6793:         return xf << 3 < 0 ? 0 : xf << 1 < 0 ? -1 : 1;
  6794:       }
  6795:       //±0,±Inf,NaN以外
  6796:       int xe = this.epp;  //xの指数
  6797:       return xe < 0 ? -1 : xe == 0 && this.dvl == MSB && this.cvl == 0L ? 0 : 1;
  6798:     }  //efp.cmp1abs()
  6799: 
  6800:     //------------------------------------------------------------------------
  6801:     //s = x.cmpabs (y)
  6802:     //  s=|x|<=>|y|
  6803:     //  絶対値比較
  6804:     //
  6805:     public int cmpabs (EFP y) {
  6806:       int xf = this.flg & ~M;
  6807:       int yf = y.flg & ~M;
  6808:       if ((xf | yf) << 1 != 0) {  //どちらかが±0,±Inf,NaN
  6809:         return EFP_CMP_TABLE[xf >>> 28] << (yf >>> 28 - 1) >> 30;
  6810:       }
  6811:       //両方±0,±Inf,NaN以外
  6812:       int s;
  6813:       long t;
  6814:       return ((s = this.epp - y.epp) != 0 ? s >= 0 ? 1 : -1 :
  6815:               (t = this.dvl - y.dvl) != 0L ? t >= 0L ? 1 : -1 :
  6816:               (t = (this.cvl >>> 1) - (y.cvl >>> 1)) != 0L ? t >= 0L ? 1 : -1 :
  6817:               0);
  6818:     }  //efp.cmpabs(EFP)
  6819: 
  6820:     //------------------------------------------------------------------------
  6821:     //s = x.compareTo (y)
  6822:     //  s=x<=>y
  6823:     //  比較
  6824:     //
  6825:     //  -Inf==-Inf<-x<-0<+0<+x<+Inf==+Inf<NaN==NaN
  6826:     //
  6827:     //  equalsであるオブジェクトはcompareToが0であることが強く推奨される
  6828:     //  同じクラスだがequalsでないオブジェクトはcompareToが0でないことが強く推奨される
  6829:     //
  6830:     @Override public int compareTo (EFP y) {
  6831:       EFP x = this;
  6832:       int xf = x.flg;
  6833:       int yf = y.flg;
  6834:       if ((xf | yf) << 1 != 0) {  //どちらかが±0,±Inf,NaN
  6835:         //return (xf == yf ? 0 :  //両方-Infまたは両方-0または両方+0または両方+Infまたは両方NaN
  6836:         //        (xf | yf) << 3 < 0 ? xf << 3 < 0 ? 1 : -1 :  //どちらか一方がNaN
  6837:         //        (xf ^ yf) < 0 ? xf >= 0 ? 1 : -1 :  //両方NaN以外でどちらかが±0,±Infで符号が違う
  6838:         //        xf == (P | I) || yf == (P | Z) || xf == (M | Z) || yf == (M | I) ? 1 : -1);  //両方NaN以外でどちらかが±0,±Infで符号が同じ
  6839:         return EFP_COMPARE_TABLE[xf >>> 28] << (yf >>> 28 - 1) >> 30;
  6840:       }
  6841:       //両方±0,±Inf,NaN以外
  6842:       if (xf != yf) {  //両方±0,±Inf,NaN以外で符号が違う
  6843:         return xf >= 0 ? 1 : -1;
  6844:       }
  6845:       //両方±0,±Inf,NaN以外で符号が同じ
  6846:       int s;
  6847:       long t;
  6848:       return (xf >= 0 ? 1 : -1) * ((s = x.epp - y.epp) != 0 ? s >= 0 ? 1 : -1 :
  6849:                                    (t = x.dvl - y.dvl) != 0L ? t >= 0L ? 1 : -1 :
  6850:                                    (t = (x.cvl >>> 1) - (y.cvl >>> 1)) != 0L ? t >= 0L ? 1 : -1 :
  6851:                                    0);
  6852:     }  //efp.compareTo(EFP)
  6853: 
  6854:     //------------------------------------------------------------------------
  6855:     //x = x.cos ()
  6856:     //  x=cos(x)
  6857:     //y = y.cos (x)
  6858:     //  y=cos(x)
  6859:     //  余弦 cosine コサイン
  6860:     //
  6861:     //  グラフ
  6862:     //    perl -e "use Math::Trig;use Graph;$g=new Graph();$g->grid();$g->func(sub{cos($_[0])});print$g"
  6863:     //    echo read("efp.gp");graph(cos) | gp -q
  6864:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
  6865:     //    |                                       |                                       |
  6866:     //    |                                       |                                       |
  6867:     //    |                                       |                                       |
  6868:     //    |                                       |                                       |
  6869:     //    +                                       +                                       +
  6870:     //    |                                       |                                       |
  6871:     //    |                                       |                                       |
  6872:     //    |                                       |                                       |
  6873:     //    |                                       |                                       |
  6874:     //    +                                       +                                       +
  6875:     //    |                                       |                                       |
  6876:     //    |                                       |                                       |
  6877:     //    |                                       |                                       |
  6878:     //    |                                       |                                       |
  6879:     //    +                                  ***********                                  +
  6880:     //    |                               ****    |    ****                               |
  6881:     //    |                             ***       |       ***                             |
  6882:     //    |                          ****         |         ****                          |
  6883:     //    |                        ***            |            ***                        |
  6884:     //    +---------+---------+--***----+---------+---------+----***--+---------+---------+
  6885:     //    |                    ***                |                ***                    |
  6886:     //    |                  ***                  |                  ***                  |
  6887:     //    **               ***                    |                    ***               **
  6888:     //    |****        *****                      |                      *****        ****|
  6889:     //    +   **********                          +                          **********   +
  6890:     //    |                                       |                                       |
  6891:     //    |                                       |                                       |
  6892:     //    |                                       |                                       |
  6893:     //    |                                       |                                       |
  6894:     //    +                                       +                                       +
  6895:     //    |                                       |                                       |
  6896:     //    |                                       |                                       |
  6897:     //    |                                       |                                       |
  6898:     //    |                                       |                                       |
  6899:     //    +                                       +                                       +
  6900:     //    |                                       |                                       |
  6901:     //    |                                       |                                       |
  6902:     //    |                                       |                                       |
  6903:     //    |                                       |                                       |
  6904:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
  6905:     //
  6906:     //  定義域
  6907:     //    -inf<=x<=inf
  6908:     //
  6909:     //  値域
  6910:     //    -1<=y<=1
  6911:     //
  6912:     //  三角関数のとの関係
  6913:     //    cos(x)=(1-tan(x/2)^2)/(1+tan(x/2)^2)
  6914:     //
  6915:     //  変数変換
  6916:     //    収束を速くするために|x|<=pi/4にする
  6917:     //    cos(x)=-sin(x-pi/2)
  6918:     //          =-cos(x-pi)
  6919:     //          =sin(x-3*pi/2)
  6920:     //          =cos(x-2*pi)
  6921:     //                 -sin(x-pi/2)
  6922:     //                             k=1
  6923:     //                       │    ←
  6924:     //            k=2↓\    │    /
  6925:     //                   \  │  /
  6926:     //                     \│/
  6927:     //    -cos(x-pi) ────・──── cos(x)
  6928:     //                     /│\
  6929:     //                   /  │  \
  6930:     //                 /    │    \↑k=0
  6931:     //                 →    │
  6932:     //                k=3
  6933:     //                 sin(x-3*pi/2)
  6934:     //
  6935:     //  メモ
  6936:     //    k=round(x/(pi/2))としてx-k*pi/2を計算するとき、pi/2の近似値3217/2048を用いて
  6937:     //    x-k*pi/2=x-k*(3217/2048+(pi/2-3217/2048))
  6938:     //            =x-k*3217/2048+k*(pi/2-3217/2048)
  6939:     //    を計算するという方法がある
  6940:     //    kは普通は桁数の少ない整数で2048は2の累乗なのでk*3217/2048は正確に計算できる
  6941:     //    xとk*3217/2048はほぼ同じ値なのでx-k*3217/2048は桁落ちを発生させながら正確に計算できる
  6942:     //    k*(pi/2-3217/2048)で発生する誤差は小さい
  6943:     //    echo Pi/2-3217/2048 | gp -q
  6944:     //    -4.4544551033807686783083602485579023568 E-6
  6945:     //
  6946:     //  テイラー展開
  6947:     //    cos(x)=1-x^2/2!+x^4/4!-x^6/6!+...
  6948:     //    f(n,x)=sum(k=0,n,(-1)^k*x^(2*k)/(2*k)!)
  6949:     //    echo read("efp.gp");eval("f(h,x)=sum(k=0,h,(-1)^k/(2*k)!*x^(2*k))");a=-Pi/4;b=-a;hmax=27;print1("    //    ");for(h=0,hmax,n=2*h;printf("%4d",n));print();print1("    //    ");for(h=0,hmax,n=2*h;printf("%4d",floor(closeness(cos,f(h,x),a,b,10000))));print() | gp -q
  6950:     //       0   2   4   6   8  10  12  14  16  18  20  22  24  26  28  30  32  34  36  38  40  42  44  46  48  50  52  54
  6951:     //       1   5  11  17  24  32  40  49  58  67  77  86  96 107 117 128 139 150 161 172 184 195 207 219 231 243 255 267
  6952:     //
  6953:     //  チェビシェフ展開
  6954:     //    echo read("efp.gp");a=-Pi/4;b=-a;hmax=27;print1("    //    ");for(h=0,hmax,n=2*h;printf("%4d",n));print();print1("    //    ");for(h=0,hmax,n=2*h;printf("%4d",floor(closeness(cos,chebyshev(cos,a,b,n),a,b,10000))));print() | gp -q
  6955:     //       0   2   4   6   8  10  12  14  16  18  20  22  24  26  28  30  32  34  36  38  40  42  44  46  48  50  52  54
  6956:     //       2   8  16  24  33  43  53  64  75  86  98 109 121 134 146 159 172 185 198 211 225 238 252 266 280 294 308 322
  6957:     //
  6958:     public final EFP cos () {
  6959:       return this.cos (this);
  6960:     }  //efp.cos()
  6961:     public final EFP cos (EFP x) {
  6962:       int xf = x.flg;
  6963:       if (xf << 1 != 0) {  //±0,±Inf,NaN
  6964:         if (xf << 1 < 0) {  //±0
  6965:           this.flg = P;  //cos(±0)=1
  6966:           this.epp = 0;
  6967:           this.dvl = MSB;
  6968:           this.cvl = 0L;
  6969:         } else if (xf << 2 < 0) {  //±Inf
  6970:           epbFpsr |= EPB_FPSR_OE;
  6971:           epbExceptionOperandExponent = xf & M | 0x7fff << 16;
  6972:           epbExceptionOperandMantissa = 0x0000000000000000L;
  6973:           this.flg = N;  //cos(±Inf)=NaN
  6974:         } else {  //NaN
  6975:           this.flg = N;  //cos(NaN)=NaN
  6976:         }
  6977:         return this;
  6978:       }
  6979:       //±0,±Inf,NaN以外
  6980:       this.inner ();
  6981:       EFP u = new EFP ();
  6982:       EFP u2 = new EFP ();
  6983:       int k = u.ieeerempi2 (x);  //-pi/2<=u<=pi/2。kはx-uの象限
  6984:       if (false) {  //テイラー展開
  6985:         EFP s = new EFP ();
  6986:         EFP t = new EFP ();
  6987:         u2.isqu (u);  //u^2
  6988:         if ((k & 1) != 0) {  //sin
  6989:           //s.sete (u);  //(-1)^k*x^(2*k+1)/(2*k+1)!
  6990:           s.flg = u.flg;
  6991:           s.epp = u.epp;
  6992:           s.dvl = u.dvl;
  6993:           s.cvl = u.cvl;
  6994:           //t.set0 ();
  6995:           t.flg = P | Z;
  6996:           //this.sete (s);
  6997:           this.flg = s.flg;
  6998:           this.epp = s.epp;
  6999:           this.dvl = s.dvl;
  7000:           this.cvl = s.cvl;
  7001:           for (int twok1 = 3; this.ne (t); twok1 += 2) {  //2*k+1
  7002:             s.imul (u2).divi ((1 - twok1) * twok1);  //(-1)^k*x^(2*k+1)/(2*k+1)!
  7003:             //t.sete (this);
  7004:             t.flg = this.flg;
  7005:             t.epp = this.epp;
  7006:             t.dvl = this.dvl;
  7007:             t.cvl = this.cvl;
  7008:             this.iadd (s);
  7009:           }
  7010:         } else {  //cos
  7011:           //s.set1 ();  //(-1)^k*x^(2*k)/(2*k)!
  7012:           s.flg = P;
  7013:           s.epp = 0;
  7014:           s.dvl = MSB;
  7015:           s.cvl = 0L;
  7016:           //t.set0 ();
  7017:           t.flg = P | Z;
  7018:           //this.sete (s);
  7019:           this.flg = s.flg;
  7020:           this.epp = s.epp;
  7021:           this.dvl = s.dvl;
  7022:           this.cvl = s.cvl;
  7023:           for (int twok = 2; this.ne (t); twok += 2) {  //2*k
  7024:             s.imul (u2).divi ((1 - twok) * twok);  //(-1)^k*x^(2*k)/(2*k)!
  7025:             //t.sete (this);
  7026:             t.flg = this.flg;
  7027:             t.epp = this.epp;
  7028:             t.dvl = this.dvl;
  7029:             t.cvl = this.cvl;
  7030:             this.iadd (s);
  7031:           }
  7032:         }
  7033:       } else {  //チェビシェフ展開
  7034:         if ((k & 1) != 0) {  //sin
  7035:           u2.isqu (u);  //u^2
  7036:           this.imul (SIN_C21, u2)
  7037:             .iadd (SIN_C19).imul (u2)
  7038:               .iadd (SIN_C17).imul (u2)
  7039:                 .iadd (SIN_C15).imul (u2)
  7040:                   .iadd (SIN_C13).imul (u2)
  7041:                     .iadd (SIN_C11).imul (u2)
  7042:                       .iadd (SIN_C9).imul (u2)
  7043:                         .iadd (SIN_C7).imul (u2)
  7044:                           .iadd (SIN_C5).imul (u2)
  7045:                             .iadd (SIN_C3).imul (u2)
  7046:                               .iadd (SIN_C1).imul (u);
  7047:         } else {  //cos
  7048:           u2.isqu (u);  //u^2
  7049:           this.imul (COS_C20, u2)
  7050:             .iadd (COS_C18).imul (u2)
  7051:               .iadd (COS_C16).imul (u2)
  7052:                 .iadd (COS_C14).imul (u2)
  7053:                   .iadd (COS_C12).imul (u2)
  7054:                     .iadd (COS_C10).imul (u2)
  7055:                       .iadd (COS_C8).imul (u2)
  7056:                         .iadd (COS_C6).imul (u2)
  7057:                           .iadd (COS_C4).imul (u2)
  7058:                             .iadd (COS_C2).imul (u2)
  7059:                               .iadd (COS_C0);
  7060:         }
  7061:       }
  7062:       //                   0123
  7063:       this.outer ().neg (0b0110 << 28 << k < 0);
  7064:       //  n*pi/2はn==0を除いて正確に表現できないので、
  7065:       //    RZまたはRPでsin(x)およびcos(x)が-1になることはあり得ない
  7066:       //    RZまたはRMでsin(x)およびcos(x)がcos(0)以外で+1になることはあり得ない
  7067:       if (this.flg << 1 == 0 && this.epp == 0) {  //結果が±1
  7068:         if (this.flg < 0) {  //結果が-1
  7069:           if (epbRoundingMode == EPB_MODE_RZ || epbRoundingMode == EPB_MODE_RP) {  //RZまたはRPで結果が-1
  7070:             this.sete (NEXTUP_MINUSONE[epbRoundingPrec]);
  7071:           }
  7072:         } else {  //結果が+1
  7073:           if (epbRoundingMode == EPB_MODE_RZ || epbRoundingMode == EPB_MODE_RM) {  //RZまたはRMで結果が+1
  7074:             this.sete (NEXTDOWN_PLUSONE[epbRoundingPrec]);
  7075:           }
  7076:         }
  7077:       }
  7078:       return this;
  7079:     }  //efp.cos(EFP)
  7080: 
  7081:     //------------------------------------------------------------------------
  7082:     //x = x.cosh ()
  7083:     //  x=cosh(x)
  7084:     //y = y.cosh (x)
  7085:     //  y=cosh(x)
  7086:     //  双曲線余弦 hyperbolic cosine ハイパボリックコサイン
  7087:     //
  7088:     //  グラフ
  7089:     //    perl -e "use Math::Trig;use Graph;$g=new Graph();$g->grid();$g->func(sub{cosh($_[0])});print$g"
  7090:     //    echo read("efp.gp");graph(cosh) | gp -q
  7091:     //    +---------+--------**---------+---------+---------+---------**--------+---------+
  7092:     //    |                   *                   |                   *                   |
  7093:     //    |                   **                  |                  **                   |
  7094:     //    |                    *                  |                  *                    |
  7095:     //    |                    **                 |                 **                    |
  7096:     //    +                     **                +                **                     +
  7097:     //    |                      *                |                *                      |
  7098:     //    |                      **               |               **                      |
  7099:     //    |                       **              |              **                       |
  7100:     //    |                        **             |             **                        |
  7101:     //    +                         **            +            **                         +
  7102:     //    |                          ***          |          ***                          |
  7103:     //    |                            **         |         **                            |
  7104:     //    |                             ***       |       ***                             |
  7105:     //    |                               *****   |   *****                               |
  7106:     //    +                                   *********                                   +
  7107:     //    |                                       |                                       |
  7108:     //    |                                       |                                       |
  7109:     //    |                                       |                                       |
  7110:     //    |                                       |                                       |
  7111:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
  7112:     //    |                                       |                                       |
  7113:     //    |                                       |                                       |
  7114:     //    |                                       |                                       |
  7115:     //    |                                       |                                       |
  7116:     //    +                                       +                                       +
  7117:     //    |                                       |                                       |
  7118:     //    |                                       |                                       |
  7119:     //    |                                       |                                       |
  7120:     //    |                                       |                                       |
  7121:     //    +                                       +                                       +
  7122:     //    |                                       |                                       |
  7123:     //    |                                       |                                       |
  7124:     //    |                                       |                                       |
  7125:     //    |                                       |                                       |
  7126:     //    +                                       +                                       +
  7127:     //    |                                       |                                       |
  7128:     //    |                                       |                                       |
  7129:     //    |                                       |                                       |
  7130:     //    |                                       |                                       |
  7131:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
  7132:     //
  7133:     //  定義域
  7134:     //    -inf<=x<=inf
  7135:     //
  7136:     //  値域
  7137:     //    1<=y<=inf
  7138:     //
  7139:     //  指数関数との関係
  7140:     //    cosh(x)=(e^x+e^-x)/2
  7141:     //           =((e^x)^2+1)/(2*e^x)
  7142:     //
  7143:     //  テイラー展開
  7144:     //    cosh(x)=1+x^2/2!+x^4/4!+x^6/6!+...
  7145:     //    f(n,x)=sum(k=0,n,x^(2*k)/(2*k)!)
  7146:     //    echo read("efp.gp");eval("f(h,x)=sum(k=0,h,1/(2*k)!*x^(2*k))");a=-1;b=-a;hmax=27;print1("    //    ");for(h=0,hmax,n=2*h;printf("%4d",n));print();print1("    //    ");for(h=0,hmax,n=2*h;printf("%4d",floor(closeness(cosh,f(h,x),a,b,10000))));print() | gp -q
  7147:     //       0   2   4   6   8  10  12  14  16  18  20  22  24  26  28  30  32  34  36  38  40  42  44  46  48  50  52  54
  7148:     //       1   5  10  15  22  29  36  44  53  61  70  79  89  98 108 118 128 138 149 159 170 181 192 203 214 226 237 249
  7149:     //
  7150:     //  チェビシェフ展開
  7151:     //    echo read("efp.gp");a=-1;b=-a;nmax=54;print1("    //    ");forstep(n=0,nmax,2,printf("%4d",n));print();print1("    //    ");forstep(n=0,nmax,2,printf("%4d",floor(closeness(cosh,chebyshev(cosh,a,b,n),a,b,10000))));print() | gp -q
  7152:     //       0   2   4   6   8  10  12  14  16  18  20  22  24  26  28  30  32  34  36  38  40  42  44  46  48  50  52  54
  7153:     //       2   7  14  22  30  39  49  59  69  80  90 102 113 124 136 148 160 173 185 198 210 223 236 249 263 276 290 303
  7154:     //
  7155:     public final EFP cosh () {
  7156:       return this.cosh (this);
  7157:     }  //efp.cosh()
  7158:     public final EFP cosh (EFP x) {
  7159:       int xf = x.flg;
  7160:       if (xf << 1 != 0) {  //±0,±Inf,NaN
  7161:         if (xf << 1 < 0) {  //cosh(±0)=1
  7162:           //this.set1 ();
  7163:           this.flg = P;
  7164:           this.epp = 0;
  7165:           this.dvl = MSB;
  7166:           this.cvl = 0L;
  7167:         } else if (xf << 2 < 0) {  //cosh(±Inf)=+Inf
  7168:           this.flg = P | I;
  7169:         } else {  //cosh(NaN)=NaN
  7170:           this.flg = N;
  7171:         }
  7172:         return this;
  7173:       }
  7174:       //±0,±Inf,NaN以外
  7175:       epbFpsr |= EPB_FPSR_X2;  //不正確な結果。オーバーフローまたはアンダーフローのときもセットされる
  7176:       epbExceptionOperandExponent = xf | 0x3fff + x.epp << 16;
  7177:       epbExceptionOperandMantissa = x.dvl;
  7178:       if (15 <= x.epp) {  //x<=-32768||32768<=x。cosh(-big)=+Inf,cosh(+big)=+Inf
  7179:         epbFpsr |= EPB_FPSR_OF;  //オーバーフロー
  7180:         return this.sete (OVFL_RESULTS[epbRoundingPrec << 3 | epbRoundingMode << 1]).finish ();  //+Inf
  7181:       }
  7182:       if (x.epp < -3) {  //|x|<0.125
  7183:         EFP x2 = new EFP ().inner ().isqu (x);  //x^2
  7184:         return this.imul (COSH_C14, x2)
  7185:           .iadd (COSH_C12).imul (x2)
  7186:             .iadd (COSH_C10).imul (x2)
  7187:               .iadd (COSH_C8).imul (x2)
  7188:                 .iadd (COSH_C6).imul (x2)
  7189:                   .iadd (COSH_C4).imul (x2)
  7190:                     .iadd (COSH_C2).imul (x2)
  7191:                       .outer ().add (COSH_C0);
  7192:       }
  7193:       //0.125<=|x|
  7194:       //  xが絶対値の大きい負数のときそのままe^xを計算するとアンダーフローして0になりさらに1/e^xがゼロ除算になる
  7195:       //  オーバーフローだけセットさせるためにxの符号を取ってからe^xを計算する
  7196:       this.inner ().abs (x).exp ();  //e^|x|
  7197:       this.iadd (new EFP ().rcp (this)).outer ().div2 ();  //(e^|x|+e^-|x|)/2
  7198:       if (this.flg << 2 < 0) {
  7199:         epbFpsr |= EPB_FPSR_OF;  //オーバーフロー
  7200:         return this.sete (OVFL_RESULTS[epbRoundingPrec << 3 | epbRoundingMode << 1 | this.flg >>> 31]).finish ();  //±Inf
  7201:       }
  7202:       return this;
  7203:     }  //efp.cosh(EFP)
  7204: 
  7205:     //------------------------------------------------------------------------
  7206:     //x = x.cot ()
  7207:     //  x=cot(x)
  7208:     //y = y.cot (x)
  7209:     //  y=cot(x)
  7210:     //  余接 cotangent コタンジェント
  7211:     //
  7212:     //  グラフ
  7213:     //    perl -e "use Math::Trig;use Graph;$g=new Graph();$g->grid();$g->func(sub{cot($_[0])});print$g"
  7214:     //    echo read("../misc/efp.gp");graph(cotan) | gp -q
  7215:     //    +---------+*--------+---------+---------+-**------+---------+---------+---*-----+
  7216:     //    |          *                            |  *                              *     |
  7217:     //    |          *                            |  *                              *     |
  7218:     //    |          **                           |  *                              *     |
  7219:     //    |           *                           |  *                              **    |
  7220:     //    +           *                           +  *                               *    +
  7221:     //    |           *                           |  **                              *    |
  7222:     //    |           *                           |   *                              *    |
  7223:     //    |           **                          |   *                              **   |
  7224:     //    |            *                          |   *                               *   |
  7225:     //    +            *                          +   **                              *   +
  7226:     //    |            **                         |    *                              **  |
  7227:     //    |             *                         |    **                              *  |
  7228:     //    |             **                        |     **                             ** |
  7229:     //    |              **                       |      *                              **|
  7230:     //    +               **                      +      **                              **
  7231:     //    |                **                     |       ***                             *
  7232:     //    |                 ***                   |         **                            |
  7233:     //    |                   **                  |          ***                          |
  7234:     //    |                    ***                |            ***                        |
  7235:     //    +---------+---------+--***----+---------+---------+----***--+---------+---------+
  7236:     //    |                        ***            |                ***                    |
  7237:     //    |                          ***          |                  **                   |
  7238:     //    |                            **         |                   ***                 |
  7239:     //    *                             ***       |                     **                |
  7240:     //    **                              **      +                      **               +
  7241:     //    |**                              *      |                       **              |
  7242:     //    | **                             **     |                        **             |
  7243:     //    |  *                              **    |                         *             |
  7244:     //    |  **                              *    |                         **            |
  7245:     //    +   *                              **   +                          *            +
  7246:     //    |   *                               *   |                          *            |
  7247:     //    |   **                              *   |                          **           |
  7248:     //    |    *                              *   |                           *           |
  7249:     //    |    *                              **  |                           *           |
  7250:     //    +    *                               *  +                           *           +
  7251:     //    |    **                              *  |                           *           |
  7252:     //    |     *                              *  |                           **          |
  7253:     //    |     *                              *  |                            *          |
  7254:     //    |     *                              *  |                            *          |
  7255:     //    +-----*---+---------+---------+------**-+---------+---------+--------*+---------+
  7256:     //
  7257:     //  定義域
  7258:     //    -inf<=x<=inf
  7259:     //    n*piを除く
  7260:     //
  7261:     //  値域
  7262:     //    -inf<=cot(x)<=inf
  7263:     //
  7264:     //  三角関数との関係
  7265:     //    cot(x)=1/tan(x)
  7266:     //          =cos(x)/sin(x)
  7267:     //          =tan(pi/2-x)
  7268:     //
  7269:     public final EFP cot () {
  7270:       return this.cot (this);
  7271:     }  //efp.cot()
  7272:     public final EFP cot (EFP x) {
  7273:       int xf = x.flg;
  7274:       if (xf << 1 != 0) {  //±0,±Inf,NaN
  7275:         if (xf << 1 < 0) {  //±0
  7276:           epbFpsr |= EPB_FPSR_OE;
  7277:           epbExceptionOperandExponent = xf & M;
  7278:           epbExceptionOperandMantissa = 0x0000000000000000L;
  7279:           this.flg = N;  //cot(±0)=NaN
  7280:         } else if (xf << 2 < 0) {  //±Inf
  7281:           epbFpsr |= EPB_FPSR_OE;
  7282:           epbExceptionOperandExponent = xf & M | 0x7fff << 16;
  7283:           epbExceptionOperandMantissa = 0x0000000000000000L;
  7284:           this.flg = N;  //cot(±Inf)=NaN
  7285:         } else {  //NaN
  7286:           this.flg = N;  //cot(NaN)=NaN
  7287:         }
  7288:         return this;
  7289:       }
  7290:       //±0,±Inf,NaN以外
  7291:       if (false) {  //cos(x)/sin(x)。[90] 810ns
  7292:         EFP s = new EFP ().inner ().sin (x);  //sin(x)
  7293:         return this.cos (x).outer ().div (s);  //cos(x)/sin(x)
  7294:       } else if (false) {  //tan(pi/2-x)。[38]
  7295:         return this.inner ().sub (PI_2, x).iadd (PI_2A).outer ().tan ();  //cot(x)=tan(pi/2-x)
  7296:       } else if (false) {  //1/tan(x)。[90] 415ns
  7297:         return this.inner ().tan (x).outer ().rcp ();  //cot(x)=1/tan(x)
  7298:       } else {  //128分割。[90] 340ns
  7299:         if (15 <= x.epp) {  //|x|が大きすぎる
  7300:           EFP s = new EFP ().inner ().sin (x);  //sin(x)
  7301:           return this.cos (x).outer ().div (s);  //cos(x)/sin(x)
  7302:         }
  7303:         this.inner ();
  7304:         EFP s = new EFP ();
  7305:         EFP t = new EFP ();
  7306:         EFP u = new EFP ().iabs (x);  //|x|
  7307:         EFP u2 = new EFP ();
  7308:         s.iadd (u, TAN7_X).imul (TAN7_Y).trunc ();  //|x|+pi/256をpi/128で割った商
  7309:         //  |x|をpi/128で割った余りを求めるとき|x|がpi/128の整数倍に近いと桁落ちが発生するので倍精度で計算する
  7310:         u.sub (t.imulw (u2, s, TAN7_Z)).sub (u2).sub (t.imul (s, TAN7_ZA));  //|x|をpi/128で割った余り。[-pi/256,pi/256]
  7311:         int k = s.geti () & 127;  //|x|+pi/256をpi/128で割った商の下位7bit
  7312:         u2.isqu (u);  //u^2
  7313:         this.imul (TAN7_C11, u2)
  7314:           .iadd (TAN7_C9).imul (u2)
  7315:             .iadd (TAN7_C7).imul (u2)
  7316:               .iadd (TAN7_C5).imul (u2)
  7317:                 .iadd (TAN7_C3).imul (u2)
  7318:                   .iadd (TAN7_C1).imul (u);
  7319:         if (k == 0) {
  7320:           this.rcp ();  //1/tan(x)
  7321:         } else if (k <= 63) {
  7322:           t = TAN7_T[k];
  7323:           s.iadd (this, t);
  7324:           this.imul (t).negdec ().div (s);  //(1-tan(k*pi/128)*t)/(tan(x-k*pi/128)+t)
  7325:         } else if (k == 64) {
  7326:           this.ineg ();  //-tan(x-pi/2)
  7327:         } else {
  7328:           t = TAN7_T[128 - k];
  7329:           s.sub (this, t);
  7330:           this.imul (t).inc ().div (s);  //(1+tan((128-k)*pi/128)*t)/(tan(x-(128-k)*pi/128)-t)
  7331:         }
  7332:         return this.outer ().neg (xf < 0);  //cotは奇関数なのでxの符号を掛ける
  7333:       }
  7334:     }  //efp.cot(EFP)
  7335: 
  7336:     //------------------------------------------------------------------------
  7337:     //x = x.coth ()
  7338:     //  x=coth(x)
  7339:     //y = y.coth (x)
  7340:     //  y=coth(x)
  7341:     //  双曲線余接 hyperbolic cotangent ハイパボリックコタンジェント
  7342:     //
  7343:     //  グラフ
  7344:     //    perl -e "use Math::Trig;use Graph;$g=new Graph();$g->grid();$g->func(sub{coth($_[0])});print$g"
  7345:     //    echo read("../misc/efp.gp");eval("coth(x)=1/tanh(x)");graph(coth) | gp -q
  7346:     //    +---------+---------+---------+---------+-**------+---------+---------+---------+
  7347:     //    |                                       |  *                                    |
  7348:     //    |                                       |  *                                    |
  7349:     //    |                                       |  *                                    |
  7350:     //    |                                       |  *                                    |
  7351:     //    +                                       +  **                                   +
  7352:     //    |                                       |   *                                   |
  7353:     //    |                                       |   *                                   |
  7354:     //    |                                       |   **                                  |
  7355:     //    |                                       |    *                                  |
  7356:     //    +                                       +    **                                 +
  7357:     //    |                                       |     **                                |
  7358:     //    |                                       |      **                               |
  7359:     //    |                                       |       ***                             |
  7360:     //    |                                       |         ******                        |
  7361:     //    +                                       +              **************************
  7362:     //    |                                       |                                       |
  7363:     //    |                                       |                                       |
  7364:     //    |                                       |                                       |
  7365:     //    |                                       |                                       |
  7366:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
  7367:     //    |                                       |                                       |
  7368:     //    |                                       |                                       |
  7369:     //    |                                       |                                       |
  7370:     //    |                                       |                                       |
  7371:     //    **************************              +                                       +
  7372:     //    |                        ******         |                                       |
  7373:     //    |                             ***       |                                       |
  7374:     //    |                               **      |                                       |
  7375:     //    |                                **     |                                       |
  7376:     //    +                                 **    +                                       +
  7377:     //    |                                  *    |                                       |
  7378:     //    |                                  **   |                                       |
  7379:     //    |                                   *   |                                       |
  7380:     //    |                                   *   |                                       |
  7381:     //    +                                   **  +                                       +
  7382:     //    |                                    *  |                                       |
  7383:     //    |                                    *  |                                       |
  7384:     //    |                                    *  |                                       |
  7385:     //    |                                    *  |                                       |
  7386:     //    +---------+---------+---------+------**-+---------+---------+---------+---------+
  7387:     //
  7388:     //  定義域
  7389:     //    -inf<=x<0
  7390:     //    0<x<=inf
  7391:     //
  7392:     //  値域
  7393:     //    -inf<=y<1
  7394:     //    1<y<=inf
  7395:     //
  7396:     //  双曲線関数との関係
  7397:     //    coth(x)=1/tanh(x)
  7398:     //           =cosh(x)/sinh(x)
  7399:     //
  7400:     //  指数関数との関係
  7401:     //    coth(x)=(e^x+e^(-x))/(e^x-e^(-x))
  7402:     //           =1+2*e^(-x)/(e^x-e^(-x))
  7403:     //           =((e^x)^2+1)/((e^x)^2-1)
  7404:     //
  7405:     //  定義域の制限
  7406:     //    x=log(sqrt(2^(n+1)+1))
  7407:     //    のとき
  7408:     //    (e^x)^2=2^(n+1)+1
  7409:     //    coth(x)=((e^x)^2+1)/((e^x)^2-1)
  7410:     //           =(2^(n+1)+1+1)/(2^(n+1)+1-1)
  7411:     //           =(2^(n+1)+2)/2^(n+1)
  7412:     //           =1+1/2^n
  7413:     //    したがって、仮数部がnbitのとき
  7414:     //    log(sqrt(2^(n+1)+1))<x
  7415:     //    ならばcoth(x)と1を区別できない(cothは奇関数なので負のときも同様)
  7416:     //    > log(sqrt(2^(53+1)+1));
  7417:     //    18.714973875118523382020842894999680078257317575103
  7418:     //    > log(sqrt(2^(92+1)+1));
  7419:     //    32.231343896037456887901293647855697513444901003298
  7420:     //    cosh(x)/sinh(x)ではxの絶対値が大きすぎるとInf/Infで結果がNaNになってしまうので途中で打ち切って1にする必要がある
  7421:     //
  7422:     public final EFP coth () {
  7423:       return this.coth (this);
  7424:     }  //efp.coth()
  7425:     public final EFP coth (EFP x) {
  7426:       int xf = x.flg;
  7427:       if (xf << 1 != 0) {  //±0,±Inf,NaN
  7428:         if (xf << 1 < 0) {  //±0
  7429:           epbFpsr |= EPB_FPSR_OE;
  7430:           epbExceptionOperandExponent = xf & M;
  7431:           epbExceptionOperandMantissa = 0x0000000000000000L;
  7432:           this.flg = N;  //coth(±0)=NaN
  7433:         } else if (xf << 2 < 0) {  //±Inf
  7434:           this.flg = xf & M;  //coth(±Inf)=±1
  7435:           this.epp = 0;
  7436:           this.dvl = MSB;
  7437:           this.cvl = 0L;
  7438:         } else {  //NaN
  7439:           this.flg = N;  //coth(NaN)=NaN
  7440:         }
  7441:         return this;
  7442:       }
  7443:       //±0,±Inf,NaN以外
  7444:       //  e^xを経由する方法はオーバーフローを発生させずに計算できる範囲が狭いので|x|が大きい場合を分ける必要がある
  7445:       int xe = x.epp;
  7446:       if (xe < -2) {  //|x|<0.25
  7447:         EFP x2 = new EFP ().inner ().isqu (x);  //x^2
  7448:         return this.imul (TANH_C27, x2)
  7449:           .iadd (TANH_C25).imul (x2)
  7450:             .iadd (TANH_C23).imul (x2)
  7451:               .iadd (TANH_C21).imul (x2)
  7452:                 .iadd (TANH_C19).imul (x2)
  7453:                   .iadd (TANH_C17).imul (x2)
  7454:                     .iadd (TANH_C15).imul (x2)
  7455:                       .iadd (TANH_C13).imul (x2)
  7456:                         .iadd (TANH_C11).imul (x2)
  7457:                           .iadd (TANH_C9).imul (x2)
  7458:                             .iadd (TANH_C7).imul (x2)
  7459:                               .iadd (TANH_C5).imul (x2)
  7460:                                 .iadd (TANH_C3).imul (x2)
  7461:                                   .iadd (TANH_C1).imul (x).outer ().rcp ();
  7462:       }
  7463:       //0.25<=|x|
  7464:       if (false) {  //cosh/sinh
  7465:         EFP s = new EFP ().inner ().sinh (x);  //sinh(x)
  7466:         return this.cosh (x).outer ().div (s);  //cosh(x)/sinh(x)
  7467:       } else if (EFP_COTH_EPP_MAX < xe) {
  7468:         this.flg = xf & M;  //±1
  7469:         this.epp = 0;
  7470:         this.dvl = MSB;
  7471:         this.cvl = 0L;
  7472:         return this;
  7473:       } else {
  7474:         EFP t = new EFP ().inner ().imul2 (x).exp ();  //e^(2*x)
  7475:         return this.inc (t).outer ().div (t.dec ());  //(e^(2*x)+1)/(e^(2*x)-1)
  7476:       }
  7477:     }  //efp.coth(EFP)
  7478: 
  7479:     //------------------------------------------------------------------------
  7480:     //x = x.csc ()
  7481:     //  x=csc(x)
  7482:     //y = y.csc (x)
  7483:     //  y=csc(x)
  7484:     //  余割 cosecant コセカント
  7485:     //
  7486:     //  グラフ
  7487:     //    perl -e "use Math::Trig;use Graph;$g=new Graph();$g->grid();$g->func(sub{csc($_[0])});print$g"
  7488:     //    echo read("../misc/efp.gp");eval("csc(x)=1/sin(x)");graph(csc) | gp -q
  7489:     //    +-----*---+---------+---------+---------+-**------+---------+--------*+---------+
  7490:     //    |     *                                 |  *                         *          |
  7491:     //    |     *                                 |  *                         *          |
  7492:     //    |     *                                 |  *                        **          |
  7493:     //    |    **                                 |  *                        *           |
  7494:     //    +    *                                  +  **                       *           +
  7495:     //    |    *                                  |   *                       *           |
  7496:     //    |   **                                  |   *                      **           |
  7497:     //    |   *                                   |   *                      *            |
  7498:     //    |   *                                   |   **                    **            |
  7499:     //    +  **                                   +    **                   *             +
  7500:     //    | **                                    |     *                  **             |
  7501:     //    |**                                     |     **                **              |
  7502:     //    **                                      |      ***             **               |
  7503:     //    |                                       |        ***        ****                |
  7504:     //    +                                       +          **********                   +
  7505:     //    |                                       |                                       |
  7506:     //    |                                       |                                       |
  7507:     //    |                                       |                                       |
  7508:     //    |                                       |                                       |
  7509:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
  7510:     //    |                                       |                                       |
  7511:     //    |                                       |                                       |
  7512:     //    |                                       |                                       |
  7513:     //    |                                       |                                       |
  7514:     //    +                   **********          +                                       +
  7515:     //    |                ****        ***        |                                       |
  7516:     //    |               **             ***      |                                      **
  7517:     //    |              **                **     |                                     **|
  7518:     //    |             **                  *     |                                    ** |
  7519:     //    +             *                   **    +                                   **  +
  7520:     //    |            **                    **   |                                   *   |
  7521:     //    |            *                      *   |                                   *   |
  7522:     //    |           **                      *   |                                  **   |
  7523:     //    |           *                       *   |                                  *    |
  7524:     //    +           *                       **  +                                  *    +
  7525:     //    |           *                        *  |                                 **    |
  7526:     //    |          **                        *  |                                 *     |
  7527:     //    |          *                         *  |                                 *     |
  7528:     //    |          *                         *  |                                 *     |
  7529:     //    +---------+*--------+---------+------**-+---------+---------+---------+---*-----+
  7530:     //
  7531:     //  定義域
  7532:     //    -inf<=x<=inf
  7533:     //    n*piを除く
  7534:     //
  7535:     //  値域
  7536:     //    -inf<=y<=-1
  7537:     //    1<=y<=inf
  7538:     //
  7539:     //  三角関数との関係
  7540:     //    csc(x)=1/sin(x)
  7541:     //
  7542:     public final EFP csc () {
  7543:       return this.csc (this);
  7544:     }  //efp.csc()
  7545:     public final EFP csc (EFP x) {
  7546:       return this.inner ().sin (x).outer ().rcp ();  //1/sin(x)
  7547:     }  //efp.csc(EFP)
  7548: 
  7549:     //------------------------------------------------------------------------
  7550:     //x = x.csch ()
  7551:     //  x=csch(x)
  7552:     //y = y.csch (x)
  7553:     //  y=csch(x)
  7554:     //  双曲線余割 hyperbolic cosecant ハイパボリックコセカント
  7555:     //
  7556:     //  グラフ
  7557:     //    perl -e "use Math::Trig;use Graph;$g=new Graph();$g->grid();$g->func(sub{csch($_[0])});print$g"
  7558:     //    echo read("../misc/efp.gp");eval("csch(x)=1/sinh(x)");graph(csch) | gp -q
  7559:     //    +---------+---------+---------+---------+-**------+---------+---------+---------+
  7560:     //    |                                       |  *                                    |
  7561:     //    |                                       |  *                                    |
  7562:     //    |                                       |  *                                    |
  7563:     //    |                                       |  *                                    |
  7564:     //    +                                       +  *                                    +
  7565:     //    |                                       |  **                                   |
  7566:     //    |                                       |   *                                   |
  7567:     //    |                                       |   *                                   |
  7568:     //    |                                       |   **                                  |
  7569:     //    +                                       +    *                                  +
  7570:     //    |                                       |    **                                 |
  7571:     //    |                                       |     *                                 |
  7572:     //    |                                       |     **                                |
  7573:     //    |                                       |      **                               |
  7574:     //    +                                       +       ***                             +
  7575:     //    |                                       |         ***                           |
  7576:     //    |                                       |           ***                         |
  7577:     //    |                                       |             ******                    |
  7578:     //    |                                       |                  ************         |
  7579:     //    ***********---------+---------+---------+---------+---------+---------***********
  7580:     //    |         ************                  |                                       |
  7581:     //    |                    ******             |                                       |
  7582:     //    |                         ***           |                                       |
  7583:     //    |                           ***         |                                       |
  7584:     //    +                             ***       +                                       +
  7585:     //    |                               **      |                                       |
  7586:     //    |                                **     |                                       |
  7587:     //    |                                 *     |                                       |
  7588:     //    |                                 **    |                                       |
  7589:     //    +                                  *    +                                       +
  7590:     //    |                                  **   |                                       |
  7591:     //    |                                   *   |                                       |
  7592:     //    |                                   *   |                                       |
  7593:     //    |                                   **  |                                       |
  7594:     //    +                                    *  +                                       +
  7595:     //    |                                    *  |                                       |
  7596:     //    |                                    *  |                                       |
  7597:     //    |                                    *  |                                       |
  7598:     //    |                                    *  |                                       |
  7599:     //    +---------+---------+---------+------**-+---------+---------+---------+---------+
  7600:     //
  7601:     //  定義域
  7602:     //    -inf<=x<0
  7603:     //    0<x<=inf
  7604:     //
  7605:     //  値域
  7606:     //    -inf<=y<0
  7607:     //    0<y<=inf
  7608:     //
  7609:     //  双曲線関数との関係
  7610:     //    csch(x)=1/sinh(x)
  7611:     //
  7612:     //  指数関数との関係
  7613:     //    csch(x)=2/(e^x-e^-x)
  7614:     //           =2*e^x/((e^x)^2-1)
  7615:     //
  7616:     public final EFP csch () {
  7617:       return this.csch (this);
  7618:     }  //efp.csch()
  7619:     public final EFP csch (EFP x) {
  7620:       int xf = x.flg;
  7621:       if (xf << 1 != 0) {  //±0,±Inf,NaN
  7622:         if (xf << 1 < 0) {  //±0
  7623:           epbFpsr |= EPB_FPSR_OE;
  7624:           epbExceptionOperandExponent = xf & M;
  7625:           epbExceptionOperandMantissa = 0x0000000000000000L;
  7626:           this.flg = N;  //csch(±0)=NaN
  7627:         } else {  //±Inf,NaN
  7628:           this.flg = xf << 2 < 0 ? xf ^ (Z | I) : N;  //csch(±Inf)=±0, csch(NaN)=NaN
  7629:         }
  7630:         return this;
  7631:       }
  7632:       //±0,±Inf,NaN以外
  7633:       if (true) {
  7634:         return this.inner ().sinh (x).outer ().rcp ();  //1/sinh(x) [88] 89以上が多いが88も出ることがある
  7635:       } else if (false) {
  7636:         this.inner ().exp (x);  //e^x
  7637:         return this.sub (new EFP ().rcp (this)).outer ().rcp ().outer ().mul2 ();  //2/(e^x-e^-x) [87]
  7638:       } else {
  7639:         return this.sub (new EFP ().inner ().exp (x), new EFP ().ineg (x).exp ()).rcp ().outer ().mul2 ();  //2/(e^x-e^-x) [88]
  7640:       }
  7641:     }  //efp.csch(EFP)
  7642: 
  7643:     //------------------------------------------------------------------------
  7644:     //x = x.cub ()
  7645:     //  x*=x^2
  7646:     //y = y.cub (x)
  7647:     //  y=x^3
  7648:     //  3乗
  7649:     //
  7650:     //  グラフ
  7651:     //    perl -e "use Graph;$g=new Graph();$g->grid();$g->func(sub{$_[0]**3});print$g"
  7652:     //    echo read("../misc/efp.gp");eval("cub(x)=x^3");graph(cub) | gp -q
  7653:     //    +---------+---------+---------+---------+---------+-----*---+---------+---------+
  7654:     //    |                                       |              **                       |
  7655:     //    |                                       |              *                        |
  7656:     //    |                                       |              *                        |
  7657:     //    |                                       |              *                        |
  7658:     //    +                                       +             **                        +
  7659:     //    |                                       |             *                         |
  7660:     //    |                                       |             *                         |
  7661:     //    |                                       |            **                         |
  7662:     //    |                                       |            *                          |
  7663:     //    +                                       +           **                          +
  7664:     //    |                                       |           *                           |
  7665:     //    |                                       |          **                           |
  7666:     //    |                                       |          *                            |
  7667:     //    |                                       |         **                            |
  7668:     //    +                                       +         *                             +
  7669:     //    |                                       |        **                             |
  7670:     //    |                                       |       **                              |
  7671:     //    |                                       |      **                               |
  7672:     //    |                                       |    ***                                |
  7673:     //    +---------+---------+---------+----***********----+---------+---------+---------+
  7674:     //    |                                ***    |                                       |
  7675:     //    |                               **      |                                       |
  7676:     //    |                              **       |                                       |
  7677:     //    |                             **        |                                       |
  7678:     //    +                             *         +                                       +
  7679:     //    |                            **         |                                       |
  7680:     //    |                            *          |                                       |
  7681:     //    |                           **          |                                       |
  7682:     //    |                           *           |                                       |
  7683:     //    +                          **           +                                       +
  7684:     //    |                          *            |                                       |
  7685:     //    |                         **            |                                       |
  7686:     //    |                         *             |                                       |
  7687:     //    |                         *             |                                       |
  7688:     //    +                        **             +                                       +
  7689:     //    |                        *              |                                       |
  7690:     //    |                        *              |                                       |
  7691:     //    |                        *              |                                       |
  7692:     //    |                       **              |                                       |
  7693:     //    +---------+---------+---*-----+---------+---------+---------+---------+---------+
  7694:     //
  7695:     //  定義域
  7696:     //    -inf<=x<=inf
  7697:     //
  7698:     //  値域
  7699:     //    -inf<=y<=inf
  7700:     //
  7701:     //  (a*x^2+b*x+c)^3 = a^3*x^6 + 3*a^2*b*x^5 + (3*a^2*c + 3*a*b^2)*x^4 + (6*a*b*c + b^3)*x^3 + (3*a*c^2 + 3*b^2*c)*x^2 + 3*b*c^2*x + c^3
  7702:     //
  7703:     public final EFP cub () {
  7704:       return this.mul (new EFP ().isqu (this));  //x*x^2
  7705:     }  //efp.cub()
  7706:     public final EFP cub (EFP x) {
  7707:       return this.mul (x, new EFP ().isqu (x));  //x*x^2
  7708:     }  //efp.cub(EFP)
  7709: 
  7710:     //------------------------------------------------------------------------
  7711:     //x = x.dec ()
  7712:     //  x-=1
  7713:     //y = y.dec (x)
  7714:     //  y=x-1
  7715:     //  1を引く(デクリメント)
  7716:     //
  7717:     //  グラフ
  7718:     //    perl -e "use Graph;$g=new Graph();$g->grid();$g->func(sub{$_[0]-1});print$g"
  7719:     //    echo read("../misc/efp.gp");eval("dec(x)=x-1");graph(dec) | gp -q
  7720:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
  7721:     //    |                                       |                                       |
  7722:     //    |                                       |                                       |
  7723:     //    |                                       |                                       |
  7724:     //    |                                       |                                       |
  7725:     //    +                                       +                                      **
  7726:     //    |                                       |                                    ***|
  7727:     //    |                                       |                                  ***  |
  7728:     //    |                                       |                                ***    |
  7729:     //    |                                       |                              ***      |
  7730:     //    +                                       +                            ***        +
  7731:     //    |                                       |                          ***          |
  7732:     //    |                                       |                        ***            |
  7733:     //    |                                       |                      ***              |
  7734:     //    |                                       |                    ***                |
  7735:     //    +                                       +                  ***                  +
  7736:     //    |                                       |                ***                    |
  7737:     //    |                                       |              ***                      |
  7738:     //    |                                       |            ***                        |
  7739:     //    |                                       |          ***                          |
  7740:     //    +---------+---------+---------+---------+--------***--------+---------+---------+
  7741:     //    |                                       |      ***                              |
  7742:     //    |                                       |    ***                                |
  7743:     //    |                                       |  ***                                  |
  7744:     //    |                                       |***                                    |
  7745:     //    +                                      ***                                      +
  7746:     //    |                                    ***|                                       |
  7747:     //    |                                  ***  |                                       |
  7748:     //    |                                ***    |                                       |
  7749:     //    |                              ***      |                                       |
  7750:     //    +                            ***        +                                       +
  7751:     //    |                          ***          |                                       |
  7752:     //    |                        ***            |                                       |
  7753:     //    |                      ***              |                                       |
  7754:     //    |                    ***                |                                       |
  7755:     //    +                  ***                  +                                       +
  7756:     //    |                ***                    |                                       |
  7757:     //    |              ***                      |                                       |
  7758:     //    |            ***                        |                                       |
  7759:     //    |          ***                          |                                       |
  7760:     //    +--------***--------+---------+---------+---------+---------+---------+---------+
  7761:     //
  7762:     public final EFP dec () {
  7763:       return this.dec (this);
  7764:     }  //efp.dec()
  7765:     public final EFP dec (EFP x) {
  7766:       //return this.sub (x, ONE);  //7.4ns
  7767:       //6.1ns
  7768:       int xf = x.flg;
  7769:       if (xf << 1 != 0) {  //±0,±Inf,NaN
  7770:         if (xf << 1 < 0) {  //±0
  7771:           this.flg = M;  //-1
  7772:           this.epp = 0;
  7773:           this.dvl = MSB;
  7774:           this.cvl = 0L;
  7775:         } else {  //±Inf,NaN
  7776:           this.flg = xf;
  7777:         }
  7778:         return this;
  7779:       }
  7780:       //±0,±Inf,NaN以外
  7781:       int xe = x.epp;
  7782:       if (xe < -LEN) {  //..-LEN-1。xの先頭がguard bitよりも右
  7783:         //絶対値は1の方が大きいのでxを右にシフトするがxの絶対値が小さすぎるので-1になる
  7784:         epbFpsr |= EPB_FPSR_X2;  //不正確な結果
  7785:         this.flg = M;  //-1
  7786:         this.epp = 0;
  7787:         this.dvl = MSB;
  7788:         this.cvl = 0L;
  7789:         return this;
  7790:       }
  7791:       long xd = x.dvl;
  7792:       long xc = x.cvl;
  7793:       if (LEN < xe) {  //LEN+1..。1がguard bitよりも右
  7794:         //絶対値はxの方が大きいので1を右にシフトするが1の絶対値が小さすぎるのでxになる
  7795:         epbFpsr |= EPB_FPSR_X2;  //不正確な結果
  7796:         return this.finish (xf, xe, xd, xc, 0L);  //x
  7797:       }
  7798:       long xb = 0L;
  7799:       if (xe == 0) {  //0。xの最上位bitと1が重なる
  7800:         //絶対値はxの方が大きいか等しいが小数点の位置は同じ
  7801:         if (xf < 0) {  //-x
  7802:           //絶対値に1を加える
  7803:           xb = xc << -1;
  7804:           xc = xd << -1 | xc >>> 1;
  7805:           xd = (xd >>> 1) + (MSB >>> 1);
  7806:           xe++;
  7807:         } else {  //+x
  7808:           //絶対値から1を引く
  7809:           xd -= MSB;
  7810:         }
  7811:       } else if (0 < xe) {  //1..LEN
  7812:         //絶対値はxの方が大きいので1を右にシフトする
  7813:         if (xf < 0) {  //-x
  7814:           //絶対値に1を加える
  7815:           if (xe <= 63) {  //1..63。xの上位と1が重なる
  7816:             if ((xd += MSB >>> xe) >>> ~xe == 0L) {  //絶対値に1を加えたら加えたbitから上がすべて0になって溢れた
  7817:               xb = xc << -1;
  7818:               xc = xd << -1 | xc >>> 1;
  7819:               xd = MSB | xd >>> 1;
  7820:               xe++;
  7821:             }
  7822:           } else {  //64..LEN。xの下位またはguard bitと1が重なる
  7823:             if ((xc += MSB >>> xe) >>> ~xe == 0L && ++xd == 0L) {  //絶対値に1を加えたら加えたbitから上がすべて0になって溢れた
  7824:               xb = xc << -1;
  7825:               xc = xc >>> 1;
  7826:               xd = MSB;
  7827:               xe++;
  7828:             }
  7829:           }
  7830:         } else {  //+x
  7831:           //絶対値から1を引く
  7832:           if (xe <= 63) {  //1..63。xの上位の2bit目以降と1が重なる
  7833:             xd -= MSB >>> xe;  //最上位bitが1なのでボローはなく0にもならない
  7834:           } else {  //64..LEN。xの下位またはguard bitと1が重なる
  7835:             if (xc >>> ~xe != 0L) {  //下位の引く位置から上が0ではない。下位だけで引ける
  7836:               xc -= MSB >>> xe;
  7837:             } else {  //下位の引く位置から上が0なのでボローが発生する
  7838:               xc |= MSB >> xe;  //下位の引く位置から上は-1になる
  7839:               xd--;  //ボローを上位から引く
  7840:             }
  7841:           }
  7842:         }
  7843:       } else {  //-LEN..-1
  7844:         //絶対値は1の方が大きいのでxを右にシフトする
  7845:         if (-63 <= xe) {  //-63..-1。xの先頭が1の右隣から上位の最下位bitまで
  7846:           xb = xc << xe;
  7847:           xc = xd << xe | xc >>> -xe;
  7848:           xd >>>= -xe;
  7849:         } else if (-64 == xe) {  //-64。xの先頭が下位の最上位bit
  7850:           xb = xc;
  7851:           xc = xd;
  7852:           xd = 0L;
  7853:         } else {  //-LEN..-65。xの先頭が下位の上から2bit目からguard bitまで
  7854:           xb = xd << xe | xc >>> -xe;
  7855:           xc = xd >>> -xe;
  7856:           xd = 0L;
  7857:         }
  7858:         xe = 0;
  7859:         if (xf < 0) {  //-x
  7860:           //絶対値に1を加える
  7861:           xd |= MSB;
  7862:         } else {  //+x
  7863:           //絶対値を1から引く
  7864:           if (xb != 0L) {
  7865:             xb = -xb;
  7866:             xc = -1L - xc;
  7867:             xd = MSB - 1L - xd;
  7868:           } else if (xc != 0L) {
  7869:             xc = -xc;
  7870:             xd = MSB - 1L - xd;
  7871:           } else {
  7872:             xd = MSB - xd;
  7873:           }
  7874:           xf ^= M;  //符号反転
  7875:         }
  7876:       }
  7877:       //正規化する
  7878:       if (xd >= 0L) {
  7879:         if (xd != 0L) {
  7880:           int o = Long.numberOfLeadingZeros (xd);  //1..63。左にシフトするbit数
  7881:           xe -= o;
  7882:           xd = xd << o | xc >>> -o;
  7883:           xc = xc << o | xb >>> -o;
  7884:           xb <<= o;
  7885:         } else if (xc < 0L) {
  7886:           xe -= 64;
  7887:           xd = xc;
  7888:           xc = xb;
  7889:           xb = 0L;
  7890:         } else if (xc != 0L) {
  7891:           int o = 64 + Long.numberOfLeadingZeros (xc);  //65..127。左にシフトするbit数
  7892:           xe -= o;
  7893:           xd = xc << o | xb >>> -o;
  7894:           xc = xb << o;
  7895:           xb = 0L;
  7896:         } else if (xb < 0L) {
  7897:           xe -= 128;
  7898:           xd = xb;
  7899:           xc = 0L;
  7900:           xb = 0L;
  7901:         } else if (xb != 0L) {
  7902:           int o = 128 + Long.numberOfLeadingZeros (xb);  //129..191。左にシフトするbit数
  7903:           xe -= o;
  7904:           xd = xb << o;
  7905:           xc = 0L;
  7906:           xb = 0L;
  7907:         } else {
  7908:           this.flg = P | Z;  //-1+1=+0
  7909:           return this;
  7910:         }
  7911:       }
  7912:       return this.finish (xf, xe, xd, xc, xb);
  7913:     }  //efp.dec(EFP)
  7914: 
  7915:     //------------------------------------------------------------------------
  7916:     //x = x.deg ()
  7917:     //  x*=180/pi
  7918:     //y = y.deg (x)
  7919:     //  y=x*180/pi
  7920:     //  180/pi倍(デグリー)
  7921:     //
  7922:     //  グラフ
  7923:     //    perl -e "use Graph;$g=new Graph();$g->grid();$g->func(sub{45/atan2(1,1)*$_[0]});print$g"
  7924:     //    echo read("../misc/efp.gp");eval("deg(x)=x*180/Pi");graph(deg) | gp -q
  7925:     //    +---------+---------+---------+---------+*--------+---------+---------+---------+
  7926:     //    |                                       |*                                      |
  7927:     //    |                                       |*                                      |
  7928:     //    |                                       |*                                      |
  7929:     //    |                                       |*                                      |
  7930:     //    +                                       +*                                      +
  7931:     //    |                                       **                                      |
  7932:     //    |                                       *                                       |
  7933:     //    |                                       *                                       |
  7934:     //    |                                       *                                       |
  7935:     //    +                                       *                                       +
  7936:     //    |                                       *                                       |
  7937:     //    |                                       *                                       |
  7938:     //    |                                       *                                       |
  7939:     //    |                                       *                                       |
  7940:     //    +                                       *                                       +
  7941:     //    |                                       *                                       |
  7942:     //    |                                       *                                       |
  7943:     //    |                                       *                                       |
  7944:     //    |                                       *                                       |
  7945:     //    +---------+---------+---------+---------*---------+---------+---------+---------+
  7946:     //    |                                       *                                       |
  7947:     //    |                                       *                                       |
  7948:     //    |                                       *                                       |
  7949:     //    |                                       *                                       |
  7950:     //    +                                       *                                       +
  7951:     //    |                                       *                                       |
  7952:     //    |                                       *                                       |
  7953:     //    |                                       *                                       |
  7954:     //    |                                       *                                       |
  7955:     //    +                                       *                                       +
  7956:     //    |                                       *                                       |
  7957:     //    |                                       *                                       |
  7958:     //    |                                       *                                       |
  7959:     //    |                                      **                                       |
  7960:     //    +                                      *+                                       +
  7961:     //    |                                      *|                                       |
  7962:     //    |                                      *|                                       |
  7963:     //    |                                      *|                                       |
  7964:     //    |                                      *|                                       |
  7965:     //    +---------+---------+---------+--------*+---------+---------+---------+---------+
  7966:     //
  7967:     //  定義域
  7968:     //    -inf<=x<=inf
  7969:     //
  7970:     //  値域
  7971:     //    -inf<=y<=inf
  7972:     //
  7973:     public final EFP deg () {
  7974:       return this.deg (this);
  7975:     }  //efp.deg()
  7976:     public final EFP deg (EFP x) {
  7977:       return this.mul (x, TO_DEG);  //x*180/pi
  7978:     }  //efp.deg(EFP)
  7979: 
  7980:     //------------------------------------------------------------------------
  7981:     //x = x.div (y)
  7982:     //  x/=y
  7983:     //z = z.div (x, y)
  7984:     //  z=x/y
  7985:     //  除算
  7986:     //
  7987:     //  (xn/xd)/(yn/yd)
  7988:     //    =(xn*yd)/(xd*yn)
  7989:     //
  7990:     public final EFP div (EFP y) {
  7991:       return this.div (this, y);
  7992:     }  //efp.div(EFP)
  7993:     public final EFP div (EFP x, EFP y) {
  7994:       int xf = x.flg;
  7995:       int yf = y.flg;
  7996:       if ((xf | yf) << 1 != 0) {  //どちらかが±0,±Inf,NaN
  7997:         if ((xf | yf) << 3 != 0) {  //どちらかがNaNのときNaN
  7998:           this.flg = N;
  7999:         } else if ((xf & yf & (Z | I)) != 0) {  //±0/±0または±Inf/±InfのときNaN
  8000:           epbFpsr |= EPB_FPSR_OE;
  8001:           if (yf << 1 < 0) {  //±0/±0
  8002:             epbExceptionOperandExponent = yf & M;
  8003:             epbExceptionOperandMantissa = 0x0000000000000000L;
  8004:           } else {  //±Inf/±Inf
  8005:             epbExceptionOperandExponent = yf & M | 0x7fff << 16;
  8006:             epbExceptionOperandMantissa = 0x0000000000000000L;
  8007:           }
  8008:           this.flg = N;
  8009:         } else if (xf << 1 == 0 && yf << 1 < 0) {  //(±0,NaN以外)/±0のとき±Inf
  8010:           epbFpsr |= EPB_FPSR_DZ;
  8011:           epbExceptionOperandExponent = yf & M;
  8012:           epbExceptionOperandMantissa = 0x0000000000000000L;
  8013:           this.flg = (xf ^ yf) & M | I;
  8014:         } else {  //±0/(±0,NaN以外)または(±Inf,NaN以外)/±Infのとき±0、±Inf/(±Inf,NaN以外)のとき±Inf
  8015:           this.flg = (xf ^ yf) & M | ((xf & Z | yf & I) != 0 ? Z : I);
  8016:         }
  8017:         return this;
  8018:       }
  8019:       //±0,±Inf,NaN以外
  8020:       long r01 = x.dvl;
  8021:       long y01 = y.dvl;
  8022:       long r2 = (r01 << -2 | x.cvl >>> 2) >>> 33;
  8023:       long y2 = (y01 << -2 | y.cvl >>> 2) >>> 33;
  8024:       r01 >>>= 2;
  8025:       y01 >>>= 2;
  8026:       long y0 = y01 >>> 31;
  8027:       long y1 = y01 & 0x7fffffffL;
  8028:       //先頭1bit
  8029:       boolean qq;
  8030:       if (r01 < y01 || (r01 == y01 && r2 < y2)) {  //x<y
  8031:         qq = false;
  8032:       } else {
  8033:         qq = true;
  8034:         r2 -= y2;
  8035:         r01 -= y01;
  8036:         if (r2 < 0L) {
  8037:           r2 += 0x80000000L;
  8038:           r01--;
  8039:         }
  8040:       }
  8041:       //1桁目
  8042:       long q0 = r01 >> 31 == y0 ? 0x7fffffffL : r01 / y0;
  8043:       r01 = (r01 - q0 * y0 << 31) + r2 - q0 * y1;
  8044:       if (r01 < 0L) {
  8045:         q0--;
  8046:         r01 += y01;
  8047:       }
  8048:       r2 = q0 * y2 + 0x7fffffffL;
  8049:       r01 -= r2 >> 31;
  8050:       r2 = ~r2 & 0x7fffffffL;  //~(r2 | ~0x7fffffffL)
  8051:       if (r01 < 0L) {
  8052:         q0--;
  8053:         r2 += y2;
  8054:         r01 += y01 + (r2 >> 31);
  8055:         r2 &= 0x7fffffffL;
  8056:       }
  8057:       //2桁目
  8058:       long q1 = r01 >> 31 == y0 ? 0x7fffffffL : r01 / y0;
  8059:       r01 = (r01 - q1 * y0 << 31) + r2 - q1 * y1;
  8060:       if (r01 < 0L) {
  8061:         q1--;
  8062:         r01 += y01;
  8063:       }
  8064:       r2 = q1 * y2 + 0x7fffffffL;
  8065:       r01 -= r2 >> 31;
  8066:       r2 = ~r2 & 0x7fffffffL;  //~(r2 | ~0x7fffffffL)
  8067:       if (r01 < 0L) {
  8068:         q1--;
  8069:         r2 += y2;
  8070:         r01 += y01 + (r2 >> 31);
  8071:         r2 &= 0x7fffffffL;
  8072:       }
  8073:       //3桁目
  8074:       long q2 = r01 >> 31 == y0 ? 0x7fffffffL : r01 / y0;
  8075:       r01 = (r01 - q2 * y0 << 31) + r2 - q2 * y1;
  8076:       if (r01 < 0L) {
  8077:         q2--;
  8078:         r01 += y01;
  8079:       }
  8080:       r2 = q2 * y2 + 0x7fffffffL;
  8081:       r01 -= r2 >> 31;
  8082:       r2 = ~r2 & 0x7fffffffL;  //~(r2 | ~0x7fffffffL)
  8083:       if (r01 < 0L) {
  8084:         q2--;
  8085:         r2 += y2;
  8086:         r01 += y01 + (r2 >> 31);
  8087:         r2 &= 0x7fffffffL;
  8088:       }
  8089:       //商  (((qq ? MSB : 0) | q0) << 31 | q1) << 31 | q2
  8090:       //余り  r01 << 31 | r2
  8091:       //正規化する
  8092:       int ze = x.epp - y.epp;
  8093:       if (qq) {  //商は94bit
  8094:         q0 = MSB | q0 << 32 | q1 << 1 | q2 >>> 30;
  8095:         q2 <<= -30;
  8096:       } else {  //商は93bit
  8097:         ze--;
  8098:         q0 = q0 << -31 | q1 << 2 | q2 >>> 29;
  8099:         q2 <<= -29;
  8100:       }
  8101:       return this.finish2 (xf ^ yf, ze, q0, q2, r01 | r2);
  8102:     }  //efp.div(EFP,EFP)
  8103: 
  8104:     //------------------------------------------------------------------------
  8105:     //x = x.div2 ()
  8106:     //  x/=2
  8107:     //y = y.div2 (x)
  8108:     //  y=x/2
  8109:     //  1/2倍
  8110:     //
  8111:     //  グラフ
  8112:     //    perl -e "use Graph;$g=new Graph();$g->grid();$g->func(sub{$_[0]/2});print$g"
  8113:     //    echo read("../misc/efp.gp");eval("div2(x)=x/2");graph(div2) | gp -q
  8114:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
  8115:     //    |                                       |                                       |
  8116:     //    |                                       |                                       |
  8117:     //    |                                       |                                       |
  8118:     //    |                                       |                                       |
  8119:     //    +                                       +                                       +
  8120:     //    |                                       |                                       |
  8121:     //    |                                       |                                       |
  8122:     //    |                                       |                                       |
  8123:     //    |                                       |                                       |
  8124:     //    +                                       +                                     ***
  8125:     //    |                                       |                                 ***** |
  8126:     //    |                                       |                             *****     |
  8127:     //    |                                       |                         *****         |
  8128:     //    |                                       |                     *****             |
  8129:     //    +                                       +                 *****                 +
  8130:     //    |                                       |             *****                     |
  8131:     //    |                                       |         *****                         |
  8132:     //    |                                       |     *****                             |
  8133:     //    |                                       | *****                                 |
  8134:     //    +---------+---------+---------+-------*****-------+---------+---------+---------+
  8135:     //    |                                 ***** |                                       |
  8136:     //    |                             *****     |                                       |
  8137:     //    |                         *****         |                                       |
  8138:     //    |                     *****             |                                       |
  8139:     //    +                 *****                 +                                       +
  8140:     //    |             *****                     |                                       |
  8141:     //    |         *****                         |                                       |
  8142:     //    |     *****                             |                                       |
  8143:     //    | *****                                 |                                       |
  8144:     //    ***                                     +                                       +
  8145:     //    |                                       |                                       |
  8146:     //    |                                       |                                       |
  8147:     //    |                                       |                                       |
  8148:     //    |                                       |                                       |
  8149:     //    +                                       +                                       +
  8150:     //    |                                       |                                       |
  8151:     //    |                                       |                                       |
  8152:     //    |                                       |                                       |
  8153:     //    |                                       |                                       |
  8154:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
  8155:     //
  8156:     //  定義域
  8157:     //    -inf<=x<=inf
  8158:     //
  8159:     //  値域
  8160:     //    -inf<=y<=inf
  8161:     //
  8162:     public final EFP div2 () {
  8163:       return this.finish (this.flg, this.epp - 1, this.dvl, this.cvl, 0L);
  8164:     }  //efp.div2()
  8165:     public final EFP idiv2 () {
  8166:       this.epp--;
  8167:       return this;
  8168:     }  //efp.idiv2()
  8169:     public final EFP div2 (EFP x) {
  8170:       return this.finish (x.flg, x.epp - 1, x.dvl, x.cvl, 0L);
  8171:     }  //efp.div2(EFP)
  8172:     public final EFP idiv2 (EFP x) {
  8173:       this.flg = x.flg;
  8174:       this.epp = x.epp - 1;
  8175:       this.dvl = x.dvl;
  8176:       this.cvl = x.cvl;
  8177:       return this;
  8178:     }  //efp.idiv2(EFP)
  8179: 
  8180:     //------------------------------------------------------------------------
  8181:     //x = x.div3 ()
  8182:     //  x/=3
  8183:     //y = y.div3 (x)
  8184:     //  y=x/3
  8185:     //  1/3倍
  8186:     //
  8187:     //  グラフ
  8188:     //    perl -e "use Graph;$g=new Graph();$g->grid();$g->func(sub{$_[0]/3});print$g"
  8189:     //    echo read("../misc/efp.gp");eval("div3(x)=x/3");graph(div3) | gp -q
  8190:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
  8191:     //    |                                       |                                       |
  8192:     //    |                                       |                                       |
  8193:     //    |                                       |                                       |
  8194:     //    |                                       |                                       |
  8195:     //    +                                       +                                       +
  8196:     //    |                                       |                                       |
  8197:     //    |                                       |                                       |
  8198:     //    |                                       |                                       |
  8199:     //    |                                       |                                       |
  8200:     //    +                                       +                                       +
  8201:     //    |                                       |                                       |
  8202:     //    |                                       |                                       |
  8203:     //    |                                       |                                      **
  8204:     //    |                                       |                                *******|
  8205:     //    +                                       +                          *******      +
  8206:     //    |                                       |                    *******            |
  8207:     //    |                                       |              *******                  |
  8208:     //    |                                       |        *******                        |
  8209:     //    |                                       |  *******                              |
  8210:     //    +---------+---------+---------+------*******------+---------+---------+---------+
  8211:     //    |                              *******  |                                       |
  8212:     //    |                        *******        |                                       |
  8213:     //    |                  *******              |                                       |
  8214:     //    |            *******                    |                                       |
  8215:     //    +      *******                          +                                       +
  8216:     //    |*******                                |                                       |
  8217:     //    **                                      |                                       |
  8218:     //    |                                       |                                       |
  8219:     //    |                                       |                                       |
  8220:     //    +                                       +                                       +
  8221:     //    |                                       |                                       |
  8222:     //    |                                       |                                       |
  8223:     //    |                                       |                                       |
  8224:     //    |                                       |                                       |
  8225:     //    +                                       +                                       +
  8226:     //    |                                       |                                       |
  8227:     //    |                                       |                                       |
  8228:     //    |                                       |                                       |
  8229:     //    |                                       |                                       |
  8230:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
  8231:     //
  8232:     //  定義域
  8233:     //    -inf<=x<=inf
  8234:     //
  8235:     //  値域
  8236:     //    -inf<=y<=inf
  8237:     //
  8238:     public final EFP div3 () {
  8239:       return this.div3 (this);
  8240:     }  //efp.div3()
  8241:     public final EFP div3 (EFP x) {
  8242:       //return this.divi (x, 3);  //x/3
  8243:       int xf = x.flg;
  8244:       if (xf << 1 != 0) {  //±0,±Inf,NaN
  8245:         this.flg = xf;
  8246:         return this;
  8247:       }
  8248:       //±0,±Inf,NaN以外
  8249:       //2分割して割る
  8250:       int ze = x.epp;
  8251:       long zc = x.dvl;
  8252:       long zb = x.cvl;
  8253:       zb = (zc << -1 | zb >>> 1) >>> 3;  //被除数の下位61bit
  8254:       zc >>>= 1;  //被除数の上位63bit
  8255:       long zd = zc / 3L;  //商の上位61..62bit
  8256:       zb |= zc - zd * 3L << -3;  //上位の余りを下位に連結する
  8257:       zc = zb / 3L;  //商の下位61bit
  8258:       zb -= zc * 3L;  //余り
  8259:       zc <<= 3;
  8260:       //正規化する
  8261:       if (zd << 2 < 0L) {  //1bit減った
  8262:         ze--;
  8263:         zd = zd << 2 | zc >>> -2;
  8264:         zc <<= 2;
  8265:       } else {  //2bit減った
  8266:         ze -= 2;
  8267:         zd = zd << 3 | zc >>> -3;
  8268:         zc <<= 3;
  8269:       }
  8270:       return this.finish (xf, ze, zd, zc, zb);
  8271:     }  //efp.div3(EFP)
  8272: 
  8273:     //------------------------------------------------------------------------
  8274:     //x = x.divi (n)
  8275:     //  x/=n
  8276:     //z = z.divi (x, n)
  8277:     //  z=x/n
  8278:     //  int除算
  8279:     //
  8280:     public final EFP divi (int n) {
  8281:       return this.divi (this, n);
  8282:     }  //efp.divi(int)
  8283:     public final EFP divi (EFP x, int n) {
  8284:       //return this.div (x, new EFP (n));  //x/n
  8285:       int xf = x.flg;
  8286:       if (n == 0) {  //yが0
  8287:         if (xf << 1 != 0) {  //xが±0,±Inf,NaN
  8288:           if (xf << 1 < 0) {  //xが±0
  8289:             epbFpsr |= EPB_FPSR_OE;
  8290:             epbExceptionOperandExponent = P;
  8291:             epbExceptionOperandMantissa = 0x0000000000000000L;
  8292:             this.flg = N;  //±0/0=NaN
  8293:           } else {
  8294:             this.flg = xf;  //NaN/0=NaN, ±Inf/0=±Inf
  8295:           }
  8296:         } else {  //xが±0,±Inf,NaN以外
  8297:           epbFpsr |= EPB_FPSR_DZ;
  8298:           epbExceptionOperandExponent = P;
  8299:           epbExceptionOperandMantissa = 0x0000000000000000L;
  8300:           this.flg = (xf & M) | I;  //±x/0=±Inf
  8301:         }
  8302:         return this;
  8303:       }
  8304:       if (xf << 1 != 0) {  //xが±0,±Inf,NaN
  8305:         this.flg = xf << 3 < 0 ? N : xf ^ (n & M);  //NaN/±n=NaN, ±Inf/±n=±Inf, ±0/±n=±0
  8306:         return this;
  8307:       }
  8308:       //両方±0,±Inf,NaN以外
  8309:       int ze = x.epp;
  8310:       long zd = x.dvl;
  8311:       long zc = x.cvl;
  8312:       long zb = 0L;
  8313:       if (n < 0) {  //yが負
  8314:         xf ^= M;
  8315:         //0x80000000を取り除く
  8316:         if (n == 0x80000000) {
  8317:           ze -= 31;
  8318:           if ((short) ze != ze) {  //アンダーフロー
  8319:             epbFpsr |= EPB_FPSR_UF;  //アンダーフロー
  8320:             epbExceptionOperandExponent = xf;
  8321:             epbExceptionOperandMantissa = zd;
  8322:             return this.sete (UNFL_RESULTS[epbRoundingPrec << 3 | epbRoundingMode << 1 | xf >>> 31]).finish ();  //±0
  8323:           }
  8324:           this.flg = xf;
  8325:           this.epp = ze;
  8326:           this.dvl = zd;
  8327:           this.cvl = zc;
  8328:           return this;
  8329:         }
  8330:         n = -n;
  8331:       }
  8332:       if (n != 1) {  //0x80000000を取り除いていない場合はn>1は不可
  8333:         long y = (long) n;  //0x80000000を取り除いていない場合は&0xffffffffLが必要
  8334:         if (n >>> 16 == 0) {  //除数が2..16bit
  8335:           //2分割して割る
  8336:           zb = (zd << -1 | zc >>> 1) >>> 17;  //被除数の下位47bit
  8337:           zc = zd >>> 1;  //被除数の上位63bit
  8338:           zd = zc / y;  //商の上位47..62bit
  8339:           zb |= zc - zd * y << 47;  //上位の余り16bitと被除数の下位47bitを連結する
  8340:           zc = zb / y;  //商の下位47bit。上位の余り16bitは除数よりも小さいので47bit以内に収まる
  8341:           zb -= zc * y;  //余り16bit
  8342:           zc <<= 17;
  8343:         } else {  //除数が17..32bit
  8344:           //3分割して割る
  8345:           zb = (zd << -1 | zc >>> 1) >>> 33;  //被除数の中位31bit
  8346:           zc = zd >>> 1;  //被除数の上位63bit
  8347:           zd = zc / y;  //商の上位31..47bit
  8348:           zb |= zc - zd * y << 31;  //上位の余り32bitと被除数の中位31bitを連結する
  8349:           zc = zb / y;  //商の中位31bit。上位の余り32bitは除数よりも小さいので31bit以内に収まる
  8350:           zb = zb - zc * y << 31;  //中位の余り32bitと被除数の下位31bit(0)を連結する
  8351:           long t = zb / y;  //商の下位31bit
  8352:           zc = (zc << 31 | t) << 2;  //商の下位62bit
  8353:           zb -= t * y;  //余り
  8354:         }
  8355:         //正規化する
  8356:         int o = Long.numberOfLeadingZeros (zd);
  8357:         ze -= o - 1;
  8358:         zd = zd << o | zc >>> -o;
  8359:         zc <<= o;
  8360:       }  //n!=1
  8361:       return this.finish (xf, ze, zd, zc, zb);
  8362:     }  //efp.divi(EFP,int)
  8363: 
  8364:     //------------------------------------------------------------------------
  8365:     //x = x.divpi ()
  8366:     //  x/=pi
  8367:     //y = y.divpi (x)
  8368:     //  y=x/pi
  8369:     //  1/pi倍
  8370:     //
  8371:     //  グラフ
  8372:     //    perl -e "use Graph;$g=new Graph();$g->grid();$g->func(sub{$_[0]/(4*atan2(1,1))});print$g"
  8373:     //    echo read("../misc/efp.gp");eval("divpi(x)=x/Pi");graph(divpi) | gp -q
  8374:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
  8375:     //    |                                       |                                       |
  8376:     //    |                                       |                                       |
  8377:     //    |                                       |                                       |
  8378:     //    |                                       |                                       |
  8379:     //    +                                       +                                       +
  8380:     //    |                                       |                                       |
  8381:     //    |                                       |                                       |
  8382:     //    |                                       |                                       |
  8383:     //    |                                       |                                       |
  8384:     //    +                                       +                                       +
  8385:     //    |                                       |                                       |
  8386:     //    |                                       |                                       |
  8387:     //    |                                       |                                       |
  8388:     //    |                                       |                                  ******
  8389:     //    +                                       +                           ********    +
  8390:     //    |                                       |                     *******           |
  8391:     //    |                                       |               *******                 |
  8392:     //    |                                       |        ********                       |
  8393:     //    |                                       |  *******                              |
  8394:     //    +---------+---------+---------+------*******------+---------+---------+---------+
  8395:     //    |                              *******  |                                       |
  8396:     //    |                       ********        |                                       |
  8397:     //    |                 *******               |                                       |
  8398:     //    |           *******                     |                                       |
  8399:     //    +    ********                           +                                       +
  8400:     //    ******                                  |                                       |
  8401:     //    |                                       |                                       |
  8402:     //    |                                       |                                       |
  8403:     //    |                                       |                                       |
  8404:     //    +                                       +                                       +
  8405:     //    |                                       |                                       |
  8406:     //    |                                       |                                       |
  8407:     //    |                                       |                                       |
  8408:     //    |                                       |                                       |
  8409:     //    +                                       +                                       +
  8410:     //    |                                       |                                       |
  8411:     //    |                                       |                                       |
  8412:     //    |                                       |                                       |
  8413:     //    |                                       |                                       |
  8414:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
  8415:     //
  8416:     //  定義域
  8417:     //    -inf<=x<=inf
  8418:     //
  8419:     //  値域
  8420:     //    -inf<=y<=inf
  8421:     //
  8422:     public final EFP divpi () {
  8423:       return this.mul (this, ONE_PI);  //x*1/pi
  8424:     }  //efp.divpi()
  8425:     public final EFP divpi (EFP x) {
  8426:       return this.mul (x, ONE_PI);  //x*1/pi
  8427:     }  //efp.divpi(EFP)
  8428: 
  8429:     //------------------------------------------------------------------------
  8430:     //x = x.divrz (y)
  8431:     //  x/=y
  8432:     //z = z.divrz (x, y)
  8433:     //  z=x/y
  8434:     //  除算(RZ)
  8435:     //
  8436:     public final EFP divrz (EFP y) {
  8437:       return this.divrz (this, y);
  8438:     }  //efp.divrz(EFP)
  8439:     public final EFP divrz (EFP x, EFP y) {
  8440:       int xf = x.flg;
  8441:       int yf = y.flg;
  8442:       if ((xf | yf) << 1 != 0) {  //どちらかが±0,±Inf,NaN
  8443:         if ((xf | yf) << 3 != 0) {  //どちらかがNaNのときNaN
  8444:           this.flg = N;
  8445:         } else if ((xf & yf & (Z | I)) != 0) {  //±0/±0または±Inf/±InfのときNaN
  8446:           epbFpsr |= EPB_FPSR_OE;
  8447:           if (yf << 1 < 0) {  //±0/±0
  8448:             epbExceptionOperandExponent = yf & M;
  8449:             epbExceptionOperandMantissa = 0x0000000000000000L;
  8450:           } else {  //±Inf/±Inf
  8451:             epbExceptionOperandExponent = yf & M | 0x7fff << 16;
  8452:             epbExceptionOperandMantissa = 0x0000000000000000L;
  8453:           }
  8454:           this.flg = N;
  8455:         } else if (xf << 1 == 0 && yf << 1 < 0) {  //(±0,NaN以外)/±0のとき±Inf
  8456:           epbFpsr |= EPB_FPSR_DZ;
  8457:           epbExceptionOperandExponent = yf & M;
  8458:           epbExceptionOperandMantissa = 0x0000000000000000L;
  8459:           this.flg = (xf ^ yf) & M | I;
  8460:         } else {  //±0/(±0,NaN以外)または(±Inf,NaN以外)/±Infのとき±0、±Inf/(±Inf,NaN以外)のとき±Inf
  8461:           this.flg = (xf ^ yf) & M | ((xf & Z | yf & I) != 0 ? Z : I);
  8462:         }
  8463:         return this;
  8464:       }
  8465:       //±0,±Inf,NaN以外
  8466:       long r01 = x.dvl;
  8467:       long y01 = y.dvl;
  8468:       long r2 = (r01 << -2 | x.cvl >>> 2) >>> 33;
  8469:       long y2 = (y01 << -2 | y.cvl >>> 2) >>> 33;
  8470:       r01 >>>= 2;
  8471:       y01 >>>= 2;
  8472:       long y0 = y01 >>> 31;
  8473:       long y1 = y01 & 0x7fffffffL;
  8474:       //先頭1bit
  8475:       boolean qq;
  8476:       if (r01 < y01 || (r01 == y01 && r2 < y2)) {  //x<y
  8477:         qq = false;
  8478:       } else {
  8479:         qq = true;
  8480:         r2 -= y2;
  8481:         r01 -= y01;
  8482:         if (r2 < 0L) {
  8483:           r2 += 0x80000000L;
  8484:           r01--;
  8485:         }
  8486:       }
  8487:       //1桁目
  8488:       long q0 = r01 >> 31 == y0 ? 0x7fffffffL : r01 / y0;
  8489:       r01 = (r01 - q0 * y0 << 31) + r2 - q0 * y1;
  8490:       if (r01 < 0L) {
  8491:         q0--;
  8492:         r01 += y01;
  8493:       }
  8494:       r2 = q0 * y2 + 0x7fffffffL;
  8495:       r01 -= r2 >> 31;
  8496:       r2 = ~r2 & 0x7fffffffL;  //~(r2 | ~0x7fffffffL)
  8497:       if (r01 < 0L) {
  8498:         q0--;
  8499:         r2 += y2;
  8500:         r01 += y01 + (r2 >> 31);
  8501:         r2 &= 0x7fffffffL;
  8502:       }
  8503:       //2桁目
  8504:       long q1 = r01 >> 31 == y0 ? 0x7fffffffL : r01 / y0;
  8505:       r01 = (r01 - q1 * y0 << 31) + r2 - q1 * y1;
  8506:       if (r01 < 0L) {
  8507:         q1--;
  8508:         r01 += y01;
  8509:       }
  8510:       r2 = q1 * y2 + 0x7fffffffL;
  8511:       r01 -= r2 >> 31;
  8512:       r2 = ~r2 & 0x7fffffffL;  //~(r2 | ~0x7fffffffL)
  8513:       if (r01 < 0L) {
  8514:         q1--;
  8515:         r2 += y2;
  8516:         r01 += y01 + (r2 >> 31);
  8517:         r2 &= 0x7fffffffL;
  8518:       }
  8519:       //3桁目
  8520:       long q2 = r01 >> 31 == y0 ? 0x7fffffffL : r01 / y0;
  8521:       r01 = (r01 - q2 * y0 << 31) + r2 - q2 * y1;
  8522:       if (r01 < 0L) {
  8523:         q2--;
  8524:         r01 += y01;
  8525:       }
  8526:       r2 = q2 * y2 + 0x7fffffffL;
  8527:       r01 -= r2 >> 31;
  8528:       r2 = ~r2 & 0x7fffffffL;  //~(r2 | ~0x7fffffffL)
  8529:       if (r01 < 0L) {
  8530:         q2--;
  8531:         r2 += y2;
  8532:         r01 += y01 + (r2 >> 31);
  8533:         r2 &= 0x7fffffffL;
  8534:       }
  8535:       //商  (((qq ? MSB : 0) | q0) << 31 | q1) << 31 | q2
  8536:       //余り  r01 << 31 | r2
  8537:       //正規化する
  8538:       int ze = x.epp - y.epp;
  8539:       if (qq) {  //商は94bit
  8540:         q0 = MSB | q0 << 32 | q1 << 1 | q2 >>> 30;
  8541:         q2 <<= -30;
  8542:       } else {  //商は93bit
  8543:         ze--;
  8544:         q0 = q0 << -31 | q1 << 2 | q2 >>> 29;
  8545:         q2 <<= -29;
  8546:       }
  8547:       return this.finish (xf ^ yf, ze, q0, q2, r01 | r2);
  8548:     }  //efp.divrz(EFP,EFP)
  8549: 
  8550:     //------------------------------------------------------------------------
  8551:     //b = x.eq (y)
  8552:     //  b=x==y
  8553:     //  等しいか
  8554:     //
  8555:     //  -Inf==-Inf<-x<-0==+0<+x<+Inf==+Inf
  8556:     //
  8557:     //  NaNの扱い
  8558:     //    どちらかがNaNのときはfalseを返す
  8559:     //
  8560:     public boolean eq (EFP y) {
  8561:       int xf = this.flg;
  8562:       int yf = y.flg;
  8563:       return ((xf | yf) << 1 != 0 ?  //どちらかが±0,±Inf,NaN
  8564:               EFP_EQ_TABLE[xf >>> 28] << (yf >>> 28 - 1) < 0
  8565:               : //両方±0,±Inf,NaN以外
  8566:               xf == yf && this.epp == y.epp && this.dvl == y.dvl && this.cvl == y.cvl);
  8567:     }  //efp.eq(EFP)
  8568: 
  8569:     //------------------------------------------------------------------------
  8570:     //b = x.equals (y)
  8571:     //  b=x==y
  8572:     //  一致
  8573:     //
  8574:     //  equalsであるオブジェクトはクラスと内容の両方が一致していなければならない
  8575:     //  equalsであるオブジェクトはhashCodeが同じでなければならない
  8576:     //  equalsでないオブジェクトはhashCodeがなるべく違う方がよい
  8577:     //  equalsであるオブジェクトはcompareToが0であることが強く推奨される
  8578:     //  equalsでないオブジェクトはcompareToが0でないことが強く推奨される
  8579:     //
  8580:     @Override public boolean equals (Object yo) {
  8581:       if (yo instanceof EFP) {
  8582:         EFP x = this;
  8583:         EFP y = (EFP) yo;
  8584:         return (x.flg == y.flg &&
  8585:                 x.epp == y.epp &&
  8586:                 x.dvl == y.dvl &&
  8587:                 x.cvl == y.cvl);
  8588:       }
  8589:       return false;
  8590:     }  //efp.equals(Object)
  8591: 
  8592:     //------------------------------------------------------------------------
  8593:     //x = x.exp ()
  8594:     //  x=e^x
  8595:     //y = y.exp (x)
  8596:     //  y=e^x
  8597:     //  指数関数 exponential
  8598:     //
  8599:     //  グラフ
  8600:     //    perl -e "use Graph;$g=new Graph();$g->grid();$g->func(sub{exp($_[0])});print$g"
  8601:     //    echo read("../misc/efp.gp");graph(exp) | gp -q
  8602:     //    +---------+---------+---------+---------+---------+---*-----+---------+---------+
  8603:     //    |                                       |            **                         |
  8604:     //    |                                       |            *                          |
  8605:     //    |                                       |           **                          |
  8606:     //    |                                       |          **                           |
  8607:     //    +                                       +          *                            +
  8608:     //    |                                       |         **                            |
  8609:     //    |                                       |        **                             |
  8610:     //    |                                       |       **                              |
  8611:     //    |                                       |      **                               |
  8612:     //    +                                       +     **                                +
  8613:     //    |                                       |    **                                 |
  8614:     //    |                                       |   **                                  |
  8615:     //    |                                       |  **                                   |
  8616:     //    |                                       |***                                    |
  8617:     //    +                                      ***                                      +
  8618:     //    |                                   ****|                                       |
  8619:     //    |                                ****   |                                       |
  8620:     //    |                           ******      |                                       |
  8621:     //    |                ************           |                                       |
  8622:     //    ******************--+---------+---------+---------+---------+---------+---------+
  8623:     //    |                                       |                                       |
  8624:     //    |                                       |                                       |
  8625:     //    |                                       |                                       |
  8626:     //    |                                       |                                       |
  8627:     //    +                                       +                                       +
  8628:     //    |                                       |                                       |
  8629:     //    |                                       |                                       |
  8630:     //    |                                       |                                       |
  8631:     //    |                                       |                                       |
  8632:     //    +                                       +                                       +
  8633:     //    |                                       |                                       |
  8634:     //    |                                       |                                       |
  8635:     //    |                                       |                                       |
  8636:     //    |                                       |                                       |
  8637:     //    +                                       +                                       +
  8638:     //    |                                       |                                       |
  8639:     //    |                                       |                                       |
  8640:     //    |                                       |                                       |
  8641:     //    |                                       |                                       |
  8642:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
  8643:     //
  8644:     //  定義域
  8645:     //    -inf<=x<=inf
  8646:     //
  8647:     //  値域
  8648:     //    0<y<=inf
  8649:     //
  8650:     //  テイラー展開
  8651:     //    e^x=1+1/1!*x+1/2!*x^2+1/3!*x^3+1/4!*x^4+1/5!*x^5+1/6!*x^6+...
  8652:     //    f(n,x)=sum(k=0,n,1/k!*x^k)
  8653:     //
  8654:     //  対数関数との関係
  8655:     //    e^log(x)=x
  8656:     //    log(e^x)=x
  8657:     //
  8658:     //  双曲線関数との関係
  8659:     //    e^x=cosh(x)+sinh(x)
  8660:     //    e^-x=cosh(x)-sinh(x)
  8661:     //    cosh(x)=(e^x+e^-x)/2
  8662:     //    sinh(x)=(e^x-e^-x)/2
  8663:     //
  8664:     public final EFP exp () {
  8665:       return this.exp (this);
  8666:     }  //efp.exp()
  8667:     public final EFP exp (EFP x) {
  8668:       int xf = x.flg;
  8669:       if (xf << 1 != 0) {  //±0,±Inf,NaN
  8670:         if (xf << 1 < 0) {  //e^±0=1
  8671:           //this.set1 ();
  8672:           this.flg = P;
  8673:           this.epp = 0;
  8674:           this.dvl = MSB;
  8675:           this.cvl = 0L;
  8676:         } else {
  8677:           this.flg = (xf == (P | I) ? P | I :  //e^+Inf=+Inf。オーバーフローはセットされない
  8678:                       xf == (M | I) ? P | Z :  //e^-Inf=+0。アンダーフローはセットされない
  8679:                       N);  //e^NaN=NaN
  8680:         }
  8681:         return this;
  8682:       }
  8683:       //±0,±Inf,NaN以外
  8684:       epbFpsr |= EPB_FPSR_X2;  //不正確な結果。オーバーフローまたはアンダーフローのときもセットされる
  8685:       epbExceptionOperandExponent = xf | 0x3fff + x.epp << 16;
  8686:       epbExceptionOperandMantissa = x.dvl;
  8687:       if (15 <= x.epp) {  //x<=-32768||32768<=x
  8688:         if (xf < 0) {  //x<=-32768。exp(-big)=+0
  8689:           epbFpsr |= EPB_FPSR_UF;  //アンダーフロー
  8690:           return this.sete (UNFL_RESULTS[epbRoundingPrec << 3 | epbRoundingMode << 1]).finish ();  //+0
  8691:         } else {  //32768<=x。exp(+big)=+Inf
  8692:           epbFpsr |= EPB_FPSR_OF;  //オーバーフロー
  8693:           return this.sete (OVFL_RESULTS[epbRoundingPrec << 3 | epbRoundingMode << 1]).finish ();  //+Inf
  8694:         }
  8695:       }
  8696:       if (false) {  //テイラー展開 [71]
  8697:         this.inner ();
  8698:         EFP s = new EFP (1);  //x^k/k!
  8699:         EFP t = new EFP (0);
  8700:         EFP u = new EFP (x);  //thisが破壊されるのでxをコピーしておく
  8701:         //this.sete (s);
  8702:         this.flg = s.flg;
  8703:         this.epp = s.epp;
  8704:         this.dvl = s.dvl;
  8705:         this.cvl = s.cvl;
  8706:         for (int k = 1; this.ne (t); k++) {
  8707:           s.imul (u).divi (k);  //x^k/k!
  8708:           //t.sete (this);
  8709:           t.flg = this.flg;
  8710:           t.epp = this.epp;
  8711:           t.dvl = this.dvl;
  8712:           t.cvl = this.cvl;
  8713:           this.iadd (s);
  8714:         }
  8715:         return this.outer ().finish ();
  8716:       } else if (false) {  //powを使う。powがexpを使っている場合は不可
  8717:         return this.pow (E, x);  //e^x [89]
  8718:       } else if (true) {  //exp2を使う。exp2がexpを使っている場合は不可 [85] 228ns
  8719:         this.inner ();
  8720:         if (this == x) {
  8721:           x = new EFP (x);
  8722:         }
  8723:         if (x.epp < -32) {  //|x|<2^-32
  8724:           this.imul (x, ONE_3).inc ().imul (x).idiv2 ().inc ().imul (x).outer ().inc ();  //e^x=1+x*(1+x/2*(1+x/3))
  8725:           if (epbRoundingMode == EPB_MODE_RZ || epbRoundingMode == EPB_MODE_RM) {
  8726:             if (xf < 0) {
  8727:               //x<0のときe^x<1なのでRZ,RMで1<=yとなってはならない
  8728:               if (this.flg << 1 == 0 && 0 <= this.epp) {
  8729:                 this.set1 ().nextdown (epbRoundingPrec);
  8730:               }
  8731:             }
  8732:           } else if (epbRoundingMode == EPB_MODE_RP) {
  8733:             //x!=0のとき1+x<e^xなのでRPでy<=1+xとなってはならない
  8734:             if (new EFP (this.flg, this.epp, this.dvl, this.cvl).dec ().le (x)) {  //y-1<=x
  8735:               this.inner ().inc(x).outer ().nextup (epbRoundingPrec);  //y=nextup(1+x)
  8736:             }
  8737:           }
  8738:         } else {
  8739:           this.imul (LOG2_E, x).outer ().exp2 ();  //e^x=2^(log2(e)*x)
  8740:         }
  8741:         return this;
  8742:       } else if (false) {  //小数部分だけexp2を使う。[90] 257ns
  8743:         int xe = x.epp;
  8744:         if (xe < 0) {  //|x|<1
  8745:           return this.inner ().imul (LOG2_E, x).outer ().exp2 ();
  8746:         }
  8747:         //1<=|x|
  8748:         this.inner ();
  8749:         int o = (int) (x.dvl >>> ~xe);  //整数部分
  8750:         this.frac (x).imul (LOG2_E).exp2 ();
  8751:         EFP[] a = xf >= 0 ? EXP_P_I : EXP_M_I;
  8752:         for (int i = 0; o != 0; i++) {
  8753:           if ((o & 1) != 0) {
  8754:             this.imul (a[i]);
  8755:           }
  8756:           o >>>= 1;
  8757:         }
  8758:         return this.outer ().finish ();
  8759:       } else {  //64分割。[90] 270ns
  8760:         int xe = x.epp;
  8761:         this.inner ();
  8762:         long xd = x.dvl;  //整数部分は高々16bit
  8763:         long xc = x.cvl;
  8764:         EFP u;
  8765:         if (false) {
  8766:           u = new EFP ().shl (x, 6).frac ().shr (6);  //xの小数点以下7桁目以降
  8767:         } else {
  8768:           int uf = xf;
  8769:           int ue;
  8770:           long ud;
  8771:           long uc;
  8772:           int o = xe + 7;
  8773:           if (o <= 0) {
  8774:             ue = xe;
  8775:             ud = xd;
  8776:             uc = xc;
  8777:           } else if (o <= 63) {
  8778:             ue = -7;
  8779:             ud = xd << o | xc >>> -o;
  8780:             uc = xc << o;
  8781:           } else if (o <= LEN - 1) {
  8782:             ue = -7;
  8783:             ud = xc << o;
  8784:             uc = 0L;
  8785:           } else {
  8786:             ue = 0;
  8787:             ud = 0L;
  8788:             uc = 0L;
  8789:           }
  8790:           if (ud >= 0L) {
  8791:             if (ud != 0L) {
  8792:               o = Long.numberOfLeadingZeros (ud);
  8793:               ue -= o;
  8794:               ud = ud << o | uc >>> -o;
  8795:               uc <<= o;
  8796:             } else if (uc != 0L) {
  8797:               o = 64 + Long.numberOfLeadingZeros (uc);
  8798:               ue -= o;
  8799:               ud = uc << o;
  8800:               uc = 0L;
  8801:             } else {
  8802:               uf |= Z;
  8803:             }
  8804:           }
  8805:           u = new EFP (uf, ue, ud, uc);  //xの小数点以下7桁目以降
  8806:         }
  8807:         this.imul (EXP_C10, u)
  8808:           .iadd (EXP_C9).imul (u)
  8809:             .iadd (EXP_C8).imul (u)
  8810:               .iadd (EXP_C7).imul (u)
  8811:                 .iadd (EXP_C6).imul (u)
  8812:                   .iadd (EXP_C5).imul (u)
  8813:                     .iadd (EXP_C4).imul (u)
  8814:                       .iadd (EXP_C3).imul (u)
  8815:                         .iadd (EXP_C2).imul (u)
  8816:                           .iadd (EXP_C1).imul (u)
  8817:                             //.iadd (EXP_C0);
  8818:                             .inc ();
  8819:         if (xf >= 0) {
  8820:           if (xe >= 0) {
  8821:             this.imul (EXP_P_T[(int) (xd << xe + 1 >>> -6)]);
  8822:             int o = (int) (xd >>> ~xe);  //整数部分
  8823:             for (int i = 0; o != 0; i++) {
  8824:               if ((o & 1) != 0) {
  8825:                 this.imul (EXP_P_I[i]);
  8826:               }
  8827:               o >>>= 1;
  8828:             }
  8829:           } else if (xe >= -6) {
  8830:             this.imul (EXP_P_T[(int) (xd >>> ~xe - 6)]);
  8831:           }
  8832:         } else {
  8833:           if (xe >= 0) {
  8834:             this.imul (EXP_M_T[(int) (xd << xe + 1 >>> -6)]);
  8835:             int o = (int) (xd >>> ~xe);  //整数部分
  8836:             for (int i = 0; o != 0; i++) {
  8837:               if ((o & 1) != 0) {
  8838:                 this.imul (EXP_M_I[i]);
  8839:               }
  8840:               o >>>= 1;
  8841:             }
  8842:           } else if (xe >= -6) {
  8843:             this.imul (EXP_M_T[(int) (xd >>> ~xe - 6)]);
  8844:           }
  8845:         }
  8846:         return this.outer ().finish ();
  8847:       }
  8848:     }  //efp.exp(EFP)
  8849: 
  8850:     //------------------------------------------------------------------------
  8851:     //x = x.exp10 ()
  8852:     //  x=10^x
  8853:     //y = y.exp10 (x)
  8854:     //  y=10^x
  8855:     //  底が10の指数関数 exponential with base 10
  8856:     //
  8857:     //  グラフ
  8858:     //    perl -e "use Graph;$g=new Graph();$g->grid();$g->func(sub{10**$_[0]});print$g"
  8859:     //    echo read("../misc/efp.gp");eval("exp10(x)=10^x");graph(exp10) | gp -q
  8860:     //    +---------+---------+---------+---------+-----*---+---------+---------+---------+
  8861:     //    |                                       |     *                                 |
  8862:     //    |                                       |    **                                 |
  8863:     //    |                                       |    *                                  |
  8864:     //    |                                       |    *                                  |
  8865:     //    +                                       +    *                                  +
  8866:     //    |                                       |   **                                  |
  8867:     //    |                                       |   *                                   |
  8868:     //    |                                       |   *                                   |
  8869:     //    |                                       |  **                                   |
  8870:     //    +                                       +  *                                    +
  8871:     //    |                                       | **                                    |
  8872:     //    |                                       | *                                     |
  8873:     //    |                                       |**                                     |
  8874:     //    |                                       **                                      |
  8875:     //    +                                       *                                       +
  8876:     //    |                                     ***                                       |
  8877:     //    |                                    ** |                                       |
  8878:     //    |                                  ***  |                                       |
  8879:     //    |                             ******    |                                       |
  8880:     //    *******************************---------+---------+---------+---------+---------+
  8881:     //    |                                       |                                       |
  8882:     //    |                                       |                                       |
  8883:     //    |                                       |                                       |
  8884:     //    |                                       |                                       |
  8885:     //    +                                       +                                       +
  8886:     //    |                                       |                                       |
  8887:     //    |                                       |                                       |
  8888:     //    |                                       |                                       |
  8889:     //    |                                       |                                       |
  8890:     //    +                                       +                                       +
  8891:     //    |                                       |                                       |
  8892:     //    |                                       |                                       |
  8893:     //    |                                       |                                       |
  8894:     //    |                                       |                                       |
  8895:     //    +                                       +                                       +
  8896:     //    |                                       |                                       |
  8897:     //    |                                       |                                       |
  8898:     //    |                                       |                                       |
  8899:     //    |                                       |                                       |
  8900:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
  8901:     //
  8902:     //  定義域
  8903:     //    -inf<=x<=inf
  8904:     //
  8905:     //  値域
  8906:     //    0<y<=inf
  8907:     //
  8908:     //  指数関数との関係
  8909:     //    10^x=(e^log(10))^x
  8910:     //        =e^(log(10)*x)
  8911:     //
  8912:     //  チェビシェフ展開1
  8913:     //    10^x=10^(trunc(x)+frac(x))
  8914:     //        =10^trunc(x)*10^frac(x)
  8915:     //    xの整数部分は10^(±2^k),0<=k<=13のテーブルを参照して後から掛ける
  8916:     //    以下は-1<x<1とする
  8917:     //    echo read("../misc/efp.gp");eval("f(x)=10^x");a=-1;b=1;for(n=0,31,printf("%4d",floor(closeness(f,chebyshev(f,a,b,n),a,b,10000)))) | gp -q
  8918:     //       0   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31
  8919:     //      -5  -4  -3  -1   1   3   6   9  12  15  18  22  25  29  32  36  40  44  48  52  56  61  65  69  74  78  83  87  92  97 102 106
  8920:     //
  8921:     //  チェビシェフ展開2
  8922:     //    偶関数と奇関数に分けてそれぞれ展開する
  8923:     //    10^x=(10^x+10^-x)/2+(10^x-10^-x)/2
  8924:     //    echo read("../misc/efp.gp");eval("f(x)=(10^x+10^-x)/2");a=-1;b=1;forstep(n=0,30,2,printf("%4d",floor(closeness(f,chebyshev(f,a,b,n),a,b,10000)))) | gp -q
  8925:     //       0   2   4   6   8  10  12  14  16  18  20  22  24  26  28  30
  8926:     //      -1   2   7  12  18  25  32  39  47  55  64  73  82  91 100 110
  8927:     //    echo read("../misc/efp.gp");eval("f(x)=(10^x-10^-x)/2");a=-1;b=1;forstep(n=1,31,2,printf("%4d",floor(closeness(f,chebyshev(f,a,b,n),a,b,10000)))) | gp -q
  8928:     //       1   3   5   7   9  11  13  15  17  19  21  23  25  27  29  31
  8929:     //       0   3   8  13  19  26  33  40  48  56  65  74  83  92 101 111
  8930:     //    評価が高くなったように見えるが係数は同じなので偶関数と奇関数に分ける意味はない
  8931:     //
  8932:     public final EFP exp10 () {
  8933:       return this.exp10 (this);
  8934:     }  //efp.exp10()
  8935:     public final EFP exp10 (EFP x) {
  8936:       int xf = x.flg;
  8937:       if (xf << 1 != 0) {  //±0,±Inf,NaN
  8938:         if (xf << 1 < 0) {  //10^±0=1
  8939:           //this.set1 ();
  8940:           this.flg = P;
  8941:           this.epp = 0;
  8942:           this.dvl = MSB;
  8943:           this.cvl = 0L;
  8944:         } else {
  8945:           this.flg = (xf == (P | I) ? P | I :  //10^+Inf=+Inf。オーバーフローはセットされない
  8946:                       xf == (M | I) ? P | Z :  //10^-Inf=+0。アンダーフローはセットされない
  8947:                       N);  //10^NaN=NaN
  8948:         }
  8949:         return this;
  8950:       }
  8951:       //±0,±Inf,NaN以外
  8952:       epbFpsr |= EPB_FPSR_X2;  //不正確な結果。オーバーフローまたはアンダーフローのときもセットされる
  8953:       epbExceptionOperandExponent = xf | 0x3fff + x.epp << 16;
  8954:       epbExceptionOperandMantissa = x.dvl;
  8955:       if (15 <= x.epp) {  //x<=-32768||32768<=x
  8956:         if (xf < 0) {  //x<=-32768。exp10(-big)=+0
  8957:           epbFpsr |= EPB_FPSR_UF;  //アンダーフロー
  8958:           return this.sete (UNFL_RESULTS[epbRoundingPrec << 3 | epbRoundingMode << 1]).finish ();  //+0
  8959:         } else {  //32768<=x。exp10(+big)=+Inf
  8960:           epbFpsr |= EPB_FPSR_OF;  //オーバーフロー
  8961:           return this.sete (OVFL_RESULTS[epbRoundingPrec << 3 | epbRoundingMode << 1]).finish ();  //+Inf
  8962:         }
  8963:       }
  8964:       if (false) {  //powを使う。powがexp10を使っている場合は不可
  8965:         return this.pow (TEN, x);  //10^x
  8966:       } else if (false) {  //expを使う。expがexp10を使っている場合は不可
  8967:         return this.inner ().imul (LOG_10, x).outer ().exp ();  //10^x=e^(log(10)*x)
  8968:       } else if (true) {  //exp2を使う
  8969:         //  10^x=(2^log2(10))^x
  8970:         //      =2^(log2(10)*x)
  8971:         return this.inner ().imul (LOG2_10, x).outer ().exp2 ();
  8972:       } else if (false) {  //exp2とexp2m1と高精度のlog2(10)を使う
  8973:         //  10^x=(2^log2(10))^x
  8974:         //      =2^(log2(10)*x)
  8975:         //      =2^((log2(10)-ε+ε)*x)
  8976:         //      =2^((log2(10)-ε)*x+ε*x)
  8977:         //      =2^((log2(10)-ε)*x)*(1+2^(ε*x)-1)
  8978:         //      =2^((log2(10)-ε)*x)+2^((log2(10)-ε)*x)*(2^(ε*x)-1)
  8979:         this.inner ();
  8980:         EFP t = new EFP ().imul (LOG2_10A, x).exp2m1 ();
  8981:         this.imul (LOG2_10, x).exp2 ();
  8982:         t.imul (this);
  8983:         return this.outer ().add (t);
  8984:       } else if (false) {  //小数部分だけexp2を使う。[90] 258ns
  8985:         int xe = x.epp;
  8986:         this.inner ();
  8987:         if (xe < 0) {  //|x|<1
  8988:           this.imul (LOG2_10, x).exp2 ();
  8989:         } else {
  8990:           int o = (int) (x.dvl >>> ~xe);  //整数部分
  8991:           this.frac (x).imul (LOG2_10).exp2 ();
  8992:           EFP[] a = xf >= 0 ? EXP10_P_I : EXP10_M_I;
  8993:           for (int i = 0; o != 0; i++) {
  8994:             if ((o & 1) != 0) {
  8995:               this.imul (a[i]);
  8996:             }
  8997:             o >>>= 1;
  8998:           }
  8999:         }
  9000:         return this.outer ().finish ();
  9001:       } else {  //64分割。[90] 315ns
  9002:         int xe = x.epp;
  9003:         this.inner ();
  9004:         long xd = x.dvl;  //整数部分は高々16bit
  9005:         long xc = x.cvl;
  9006:         EFP u;
  9007:         if (false) {
  9008:           u = new EFP ().shl (x, 6).frac ().shr (6);  //xの小数点以下7桁目以降
  9009:         } else {
  9010:           int uf = xf;
  9011:           int ue;
  9012:           long ud;
  9013:           long uc;
  9014:           int o = xe + 7;
  9015:           if (o <= 0) {
  9016:             ue = xe;
  9017:             ud = xd;
  9018:             uc = xc;
  9019:           } else if (o <= 63) {
  9020:             ue = -7;
  9021:             ud = xd << o | xc >>> -o;
  9022:             uc = xc << o;
  9023:           } else if (o <= LEN - 1) {
  9024:             ue = -7;
  9025:             ud = xc << o;
  9026:             uc = 0L;
  9027:           } else {
  9028:             ue = 0;
  9029:             ud = 0L;
  9030:             uc = 0L;
  9031:           }
  9032:           if (ud >= 0L) {
  9033:             if (ud != 0L) {
  9034:               o = Long.numberOfLeadingZeros (ud);
  9035:               ue -= o;
  9036:               ud = ud << o | uc >>> -o;
  9037:               uc <<= o;
  9038:             } else if (uc != 0L) {
  9039:               o = 64 + Long.numberOfLeadingZeros (uc);
  9040:               ue -= o;
  9041:               ud = uc << o;
  9042:               uc = 0L;
  9043:             } else {
  9044:               uf |= Z;
  9045:             }
  9046:           }
  9047:           u = new EFP (uf, ue, ud, uc);  //xの小数点以下7桁目以降
  9048:         }
  9049:         this.imul (EXP10_C11, u)
  9050:           .iadd (EXP10_C10).imul (u)
  9051:             .iadd (EXP10_C9).imul (u)
  9052:               .iadd (EXP10_C8).imul (u)
  9053:                 .iadd (EXP10_C7).imul (u)
  9054:                   .iadd (EXP10_C6).imul (u)
  9055:                     .iadd (EXP10_C5).imul (u)
  9056:                       .iadd (EXP10_C4).imul (u)
  9057:                         .iadd (EXP10_C3).imul (u)
  9058:                           .iadd (EXP10_C2).imul (u)
  9059:                             .iadd (EXP10_C1).imul (u)
  9060:                               //.iadd (EXP10_C0);
  9061:                               .inc ();
  9062:         if (xf >= 0) {
  9063:           if (xe >= 0) {
  9064:             this.imul (EXP10_P_T[(int) (xd << xe + 1 >>> -6)]);
  9065:             int o = (int) (xd >>> ~xe);  //整数部分
  9066:             for (int i = 0; o != 0; i++) {
  9067:               if ((o & 1) != 0) {
  9068:                 this.imul (EXP10_P_I[i]);
  9069:               }
  9070:               o >>>= 1;
  9071:             }
  9072:           } else if (xe >= -6) {
  9073:             this.imul (EXP10_P_T[(int) (xd >>> ~xe - 6)]);
  9074:           }
  9075:           this.outer ().finish ();
  9076:           if (epbRoundingMode == EPB_MODE_RP) {
  9077:             //0<xのとき1<10^xなのでRPでy<=1となってはならない
  9078:             if (this.flg << 1 == 0 && (this.epp < 0 ||
  9079:                                        this.epp == 0 && this.dvl == MSB && this.cvl == 0L)) {
  9080:               this.set1 ().nextup (epbRoundingPrec);
  9081:             }
  9082:           }
  9083:         } else {
  9084:           if (xe >= 0) {
  9085:             this.imul (EXP10_M_T[(int) (xd << xe + 1 >>> -6)]);
  9086:             int o = (int) (xd >>> ~xe);  //整数部分
  9087:             for (int i = 0; o != 0; i++) {
  9088:               if ((o & 1) != 0) {
  9089:                 this.imul (EXP10_M_I[i]);
  9090:               }
  9091:               o >>>= 1;
  9092:             }
  9093:           } else if (xe >= -6) {
  9094:             this.imul (EXP10_M_T[(int) (xd >>> ~xe - 6)]);
  9095:           }
  9096:           this.outer ().finish ();
  9097:           if (epbRoundingMode == EPB_MODE_RZ || epbRoundingMode == EPB_MODE_RM) {
  9098:             //x<0のとき10^x<1なのでRZ,RMで1<=yとなってはならない
  9099:             if (this.flg << 1 == 0 && 0 <= this.epp) {
  9100:               this.set1 ().nextdown (epbRoundingPrec);
  9101:             }
  9102:           }
  9103:         }
  9104:         return this;
  9105:       }
  9106:     }  //efp.exp10(EFP)
  9107: 
  9108:     //------------------------------------------------------------------------
  9109:     //x = x.exp2 ()
  9110:     //  x=2^x
  9111:     //y = y.exp2 (x)
  9112:     //  y=2^x
  9113:     //  底が2の指数関数 exponential with base 2
  9114:     //
  9115:     //  グラフ
  9116:     //    perl -e "use Graph;$g=new Graph();$g->grid();$g->func(sub{2**$_[0]});print$g"
  9117:     //    echo read("../misc/efp.gp");eval("exp2(x)=2^x");graph(exp2) | gp -q
  9118:     //    +---------+---------+---------+---------+---------+---------*---------+---------+
  9119:     //    |                                       |                  **                   |
  9120:     //    |                                       |                 **                    |
  9121:     //    |                                       |                **                     |
  9122:     //    |                                       |               **                      |
  9123:     //    +                                       +              **                       +
  9124:     //    |                                       |             **                        |
  9125:     //    |                                       |            **                         |
  9126:     //    |                                       |           **                          |
  9127:     //    |                                       |          **                           |
  9128:     //    +                                       +        ***                            +
  9129:     //    |                                       |       **                              |
  9130:     //    |                                       |     ***                               |
  9131:     //    |                                       |   ***                                 |
  9132:     //    |                                       |****                                   |
  9133:     //    +                                     ****                                      +
  9134:     //    |                                  **** |                                       |
  9135:     //    |                             ******    |                                       |
  9136:     //    |                      ********         |                                       |
  9137:     //    |      *****************                |                                       |
  9138:     //    ********--+---------+---------+---------+---------+---------+---------+---------+
  9139:     //    |                                       |                                       |
  9140:     //    |                                       |                                       |
  9141:     //    |                                       |                                       |
  9142:     //    |                                       |                                       |
  9143:     //    +                                       +                                       +
  9144:     //    |                                       |                                       |
  9145:     //    |                                       |                                       |
  9146:     //    |                                       |                                       |
  9147:     //    |                                       |                                       |
  9148:     //    +                                       +                                       +
  9149:     //    |                                       |                                       |
  9150:     //    |                                       |                                       |
  9151:     //    |                                       |                                       |
  9152:     //    |                                       |                                       |
  9153:     //    +                                       +                                       +
  9154:     //    |                                       |                                       |
  9155:     //    |                                       |                                       |
  9156:     //    |                                       |                                       |
  9157:     //    |                                       |                                       |
  9158:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
  9159:     //
  9160:     //  定義域
  9161:     //    -inf<=x<=inf
  9162:     //
  9163:     //  値域
  9164:     //    0<y<=inf
  9165:     //
  9166:     //  指数関数との関係
  9167:     //    2^x=(e^log(2))^x
  9168:     //       =e^(log(2)*x)
  9169:     //    e^x=(2^log2(e))^x
  9170:     //       =2^(log2(e)*x)
  9171:     //
  9172:     //  手順
  9173:     //    abs(x)<2^-LENのときは1を返す
  9174:     //      x→0のとき2^x→1+log(2)*x≒1+0.693*xなので1+xが情報落ちで1になるときは2^xも1になる
  9175:     //    xを整数部と小数部に分ける
  9176:     //    整数部はそのまま指数部にする
  9177:     //    小数部はチェビシェフ展開を行う
  9178:     //
  9179:     //  exp2(x)
  9180:     //    echo read("../misc/efp.gp");eval("f(n,x)=sum(k=0,n,log(2)^k/k!*x^k)");eval("g(x)=2^x");for(n=0,26,printf("%4d",floor(closeness(g,f(n,x),-1,1,10000)))) | gp -q
  9181:     //    echo read("../misc/efp.gp");eval("f(x)=2^x");a=-1;b=0;for(n=0,26,printf("%4d",floor(closeness(f,chebyshev(f,a,b,n),a,b,10000)))) | gp -q
  9182:     //    echo read("../misc/efp.gp");eval("f(x)=2^x");a=0;b=1;for(n=0,26,printf("%4d",floor(closeness(f,chebyshev(f,a,b,n),a,b,10000)))) | gp -q
  9183:     //                次数   0   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26
  9184:     //        テイラー展開   0   1   3   5   8  11  15  18  22  26  30  34  38  42  47  51  56  61  65  70  75  80  85  90  95 101 106
  9185:     //    チェビシェフ展開
  9186:     //              [-1,0]   1   4   8  13  18  23  38  34  39  45  51  57  63  70  76  83  89  96 103 110 117 124 131 138 145 152 159
  9187:     //               [0,1]   1   4   8  13  18  23  38  34  39  45  51  57  63  70  76  83  89  96 103 110 117 124 131 138 145 152 159
  9188:     //
  9189:     //  累乗の方法
  9190:     //    例
  9191:     //      2^1.375=2^(1+1/4+1/8)
  9192:     //             =2^1*2^(1/4)*2^(1/8)
  9193:     //    2^(1/4)や2^(1/8)をテーブルに展開しておいて必要なものを掛けるだけ
  9194:     //    1bitずつやると効率が悪いので数bitずつまとめる
  9195:     //       bit  ブロック  サイズ
  9196:     //         1      92    1*92=92
  9197:     //         2      46    3*46=138
  9198:     //         3      31    7*31=217
  9199:     //         4      23    15*23=345
  9200:     //
  9201:     //  チェビシェフ展開
  9202:     //    [0,1]を8分割
  9203:     //    echo read("../misc/efp.gp");eval("f(x)=2^x");a=0;b=0.125;for(n=0,25,printf("%4d",floor(closeness(f,chebyshev(f,a,b,n),a,b,10000)))) | gp -q
  9204:     //    echo read("../misc/efp.gp");eval("f(x)=2^x");a=0.125;b=0.25;for(n=0,25,printf("%4d",floor(closeness(f,chebyshev(f,a,b,n),a,b,10000)))) | gp -q
  9205:     //    echo read("../misc/efp.gp");eval("f(x)=2^x");a=0.25;b=0.375;for(n=0,25,printf("%4d",floor(closeness(f,chebyshev(f,a,b,n),a,b,10000)))) | gp -q
  9206:     //    echo read("../misc/efp.gp");eval("f(x)=2^x");a=0.375;b=0.5;for(n=0,25,printf("%4d",floor(closeness(f,chebyshev(f,a,b,n),a,b,10000)))) | gp -q
  9207:     //    echo read("../misc/efp.gp");eval("f(x)=2^x");a=0.5;b=0.625;for(n=0,25,printf("%4d",floor(closeness(f,chebyshev(f,a,b,n),a,b,10000)))) | gp -q
  9208:     //    echo read("../misc/efp.gp");eval("f(x)=2^x");a=0.625;b=0.75;for(n=0,25,printf("%4d",floor(closeness(f,chebyshev(f,a,b,n),a,b,10000)))) | gp -q
  9209:     //    echo read("../misc/efp.gp");eval("f(x)=2^x");a=0.75;b=0.875;for(n=0,25,printf("%4d",floor(closeness(f,chebyshev(f,a,b,n),a,b,10000)))) | gp -q
  9210:     //    echo read("../misc/efp.gp");eval("f(x)=2^x");a=0.875;b=1;for(n=0,25,printf("%4d",floor(closeness(f,chebyshev(f,a,b,n),a,b,10000)))) | gp -q
  9211:     //                   0   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25
  9212:     //       [0,0.125]   4  11  18  25  33  41  49  58  67  76  85  94 103 112 122 131 141 150 160 170 180 190 200 210 220 231
  9213:     //    [0.125,0.25]   4  11  18  25  33  41  49  58  67  76  85  94 103 112 122 131 141 150 160 170 180 190 200 210 220 231
  9214:     //    [0.25,0.375]   4  11  18  25  33  41  49  58  67  76  85  94 103 112 122 131 141 150 160 170 180 190 200 210 220 231
  9215:     //     [0.375,0.5]   4  11  18  25  33  41  49  58  67  76  85  94 103 112 122 131 141 150 160 170 180 190 200 210 220 231
  9216:     //     [0.5,0.625]   4  11  18  25  33  41  49  58  67  76  85  94 103 112 122 131 141 150 160 170 180 190 200 210 220 231
  9217:     //    [0.625,0.75]   4  11  18  25  33  41  49  58  67  76  85  94 103 112 122 131 141 150 160 170 180 190 200 210 220 231
  9218:     //    [0.75,0.875]   4  11  18  25  33  41  49  58  67  76  85  94 103 112 122 131 141 150 160 170 180 190 200 210 220 231
  9219:     //       [0.875,1]   4  11  18  25  33  41  49  58  67  76  85  94 103 112 122 131 141 150 160 170 180 190 200 210 220 231
  9220:     //
  9221:     public final EFP exp2 () {
  9222:       return this.exp2 (this);
  9223:     }  //efp.exp2()
  9224:     public final EFP exp2 (EFP x) {
  9225:       int xf = x.flg;
  9226:       if (xf << 1 != 0) {  //±0,±Inf,NaN
  9227:         if (xf << 1 < 0) {  //2^±0=1
  9228:           //this.set1 ();
  9229:           this.flg = P;
  9230:           this.epp = 0;
  9231:           this.dvl = MSB;
  9232:           this.cvl = 0L;
  9233:         } else {
  9234:           this.flg = (xf == (P | I) ? P | I :  //2^+Inf=+Inf。オーバーフローはセットされない
  9235:                       xf == (M | I) ? P | Z :  //2^-Inf=+0。アンダーフローはセットされない
  9236:                       N);  //2^NaN=NaN
  9237:         }
  9238:         return this;
  9239:       }
  9240:       //±0,±Inf,NaN以外
  9241:       epbFpsr |= EPB_FPSR_X2;  //不正確な結果。オーバーフローまたはアンダーフローのときもセットされる
  9242:       epbExceptionOperandExponent = xf | 0x3fff + x.epp << 16;
  9243:       epbExceptionOperandMantissa = x.dvl;
  9244:       if (15 <= x.epp) {  //x<=-32768||32768<=x
  9245:         if (xf < 0) {  //x<=-32768。exp2(-big)=+0
  9246:           epbFpsr |= EPB_FPSR_UF;  //アンダーフロー
  9247:           return this.sete (UNFL_RESULTS[epbRoundingPrec << 3 | epbRoundingMode << 1]).finish ();  //+0
  9248:         } else {  //32768<=x。exp2(+big)=+Inf
  9249:           epbFpsr |= EPB_FPSR_OF;  //オーバーフロー
  9250:           return this.sete (OVFL_RESULTS[epbRoundingPrec << 3 | epbRoundingMode << 1]).finish ();  //+Inf
  9251:         }
  9252:       }
  9253:       if (false) {  //powを使う。powがexp2を使っている場合は不可
  9254:         return this.pow (TWO, x);  //2^x
  9255:       } else if (false) {  //expを使う。expがexp2を使っている場合は不可
  9256:         return this.inner ().imul (LOG_2, x).outer ().exp ();  //2^x=e^(log(2)*x)
  9257:       } else {  //64分割。[91] 205ns
  9258:         int xe = x.epp;
  9259:         long xd = x.dvl;  //整数部分は高々16bit
  9260:         long xc = x.cvl;
  9261:         this.inner ();
  9262:         EFP u;
  9263:         if (false) {
  9264:           u = new EFP ().shl (x, 6).frac ().shr (6);  //xの小数点以下7桁目以降
  9265:         } else {
  9266:           int uf = xf;
  9267:           int ue;
  9268:           long ud;
  9269:           long uc;
  9270:           int o = xe + 7;
  9271:           if (o <= 0) {
  9272:             ue = xe;
  9273:             ud = xd;
  9274:             uc = xc;
  9275:           } else if (o <= 63) {
  9276:             ue = -7;
  9277:             ud = xd << o | xc >>> -o;
  9278:             uc = xc << o;
  9279:           } else if (o <= LEN - 1) {
  9280:             ue = -7;
  9281:             ud = xc << o;
  9282:             uc = 0L;
  9283:           } else {
  9284:             ue = 0;
  9285:             ud = 0L;
  9286:             uc = 0L;
  9287:           }
  9288:           if (ud >= 0L) {
  9289:             if (ud != 0L) {
  9290:               o = Long.numberOfLeadingZeros (ud);
  9291:               ue -= o;
  9292:               ud = ud << o | uc >>> -o;
  9293:               uc <<= o;
  9294:             } else if (uc != 0L) {
  9295:               o = 64 + Long.numberOfLeadingZeros (uc);
  9296:               ue -= o;
  9297:               ud = uc << o;
  9298:               uc = 0L;
  9299:             } else {
  9300:               uf |= Z;
  9301:             }
  9302:           }
  9303:           u = new EFP (uf, ue, ud, uc);  //xの小数点以下7桁目以降
  9304:         }
  9305:         if (xf >= 0) {
  9306:           this.imul (EXP2P_C8, u)
  9307:             .iadd (EXP2P_C7).imul (u)
  9308:               .iadd (EXP2P_C6).imul (u)
  9309:                 .iadd (EXP2P_C5).imul (u)
  9310:                   .iadd (EXP2P_C4).imul (u)
  9311:                     .iadd (EXP2P_C3).imul (u)
  9312:                       .iadd (EXP2P_C2).imul (u)
  9313:                         .iadd (EXP2P_C1).imul (u)
  9314:                           //.iadd (EXP2P_C0);
  9315:                           .inc ();
  9316:           if (xe >= 0) {
  9317:             this.imul (EXP2P_T[(int) (xd << xe + 1 >>> -6)]).shl ((int) (xd >>> ~xe));
  9318:           } else if (xe >= -6) {
  9319:             this.imul (EXP2P_T[(int) (xd >>> ~xe - 6)]);
  9320:           }
  9321:           this.outer ().finish ();
  9322:           if (epbRoundingMode == EPB_MODE_RP) {
  9323:             //0<xのとき1<2^xなのでRPでy<=1となってはならない
  9324:             if (this.flg << 1 == 0 &&  (this.epp < 0 ||
  9325:                                         this.epp == 0 && this.dvl == MSB && this.cvl == 0L)) {
  9326:               this.set1 ().nextup (epbRoundingPrec);
  9327:             }
  9328:           }
  9329:         } else {
  9330:           this.imul (EXP2M_C8, u)
  9331:             .iadd (EXP2M_C7).imul (u)
  9332:               .iadd (EXP2M_C6).imul (u)
  9333:                 .iadd (EXP2M_C5).imul (u)
  9334:                   .iadd (EXP2M_C4).imul (u)
  9335:                     .iadd (EXP2M_C3).imul (u)
  9336:                       .iadd (EXP2M_C2).imul (u)
  9337:                         .iadd (EXP2M_C1).imul (u)
  9338:                           //.iadd (EXP2M_C0);
  9339:                           .inc ();
  9340:           if (xe >= 0) {
  9341:             this.imul (EXP2M_T[(int) (xd << xe + 1 >>> -6)]).shr ((int) (xd >>> ~xe));
  9342:           } else if (xe >= -6) {
  9343:             this.imul (EXP2M_T[(int) (xd >>> ~xe - 6)]);
  9344:           }
  9345:           this.outer ().finish ();
  9346:           if (epbRoundingMode == EPB_MODE_RZ || epbRoundingMode == EPB_MODE_RM) {
  9347:             //x<0のとき2^x<1なのでRZ,RMで1<=yとなってはならない
  9348:             if (this.flg << 1 == 0 && 0 <= this.epp) {
  9349:               this.set1 ().nextdown (epbRoundingPrec);
  9350:             }
  9351:           }
  9352:         }
  9353:         return this;
  9354:       }
  9355:     }  //efp.exp2(EFP)
  9356: 
  9357:     //------------------------------------------------------------------------
  9358:     //x = x.exp2m1 ()
  9359:     //  x=2^x-1
  9360:     //y = y.exp2m1 (x)
  9361:     //  y=2^x-1
  9362:     //  0に近い数の底が2の指数関数 exponential of number being close to 0 with base 2
  9363:     //
  9364:     //  グラフ
  9365:     //    perl -e "use Graph;$g=new Graph();$g->grid();$g->func(sub{my($x)=@_;2**$x-1});print$g"
  9366:     //    echo read("../misc/efp.gp");eval("f(x)=2^x-1");graph(f) | gp -q
  9367:     //    +---------+---------+---------+---------+---------+---------+--**-----+---------+
  9368:     //    |                                       |                     **                |
  9369:     //    |                                       |                     *                 |
  9370:     //    |                                       |                    **                 |
  9371:     //    |                                       |                   **                  |
  9372:     //    +                                       +                   *                   +
  9373:     //    |                                       |                  **                   |
  9374:     //    |                                       |                 **                    |
  9375:     //    |                                       |                **                     |
  9376:     //    |                                       |               **                      |
  9377:     //    +                                       +              **                       +
  9378:     //    |                                       |             **                        |
  9379:     //    |                                       |            **                         |
  9380:     //    |                                       |           **                          |
  9381:     //    |                                       |          **                           |
  9382:     //    +                                       +        ***                            +
  9383:     //    |                                       |       **                              |
  9384:     //    |                                       |     ***                               |
  9385:     //    |                                       |   ***                                 |
  9386:     //    |                                       |****                                   |
  9387:     //    +---------+---------+---------+-------****--------+---------+---------+---------+
  9388:     //    |                                  **** |                                       |
  9389:     //    |                             ******    |                                       |
  9390:     //    |                      ********         |                                       |
  9391:     //    |      *****************                |                                       |
  9392:     //    ********                                +                                       +
  9393:     //    |                                       |                                       |
  9394:     //    |                                       |                                       |
  9395:     //    |                                       |                                       |
  9396:     //    |                                       |                                       |
  9397:     //    +                                       +                                       +
  9398:     //    |                                       |                                       |
  9399:     //    |                                       |                                       |
  9400:     //    |                                       |                                       |
  9401:     //    |                                       |                                       |
  9402:     //    +                                       +                                       +
  9403:     //    |                                       |                                       |
  9404:     //    |                                       |                                       |
  9405:     //    |                                       |                                       |
  9406:     //    |                                       |                                       |
  9407:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
  9408:     //
  9409:     //  定義域
  9410:     //    -inf<=x<=inf
  9411:     //
  9412:     //  値域
  9413:     //    -1<y<=inf
  9414:     //
  9415:     //  メモ
  9416:     //    |x|が0に極端に近いとき、exp2(x)-1を計算しようとすると情報落ちで1になってしまうが、exp2m1(x)は真の値に近い結果を返す
  9417:     //
  9418:     //  加算
  9419:     //    2^(x+y)-1=(2^x-1)*(2^y-1)+(2^x-1)+(2^y-1)
  9420:     //
  9421:     //  テイラー展開
  9422:     //    > coeff(sub(a=0,for n:=0:4 sum sub(x=a,df(2^x-1,x,n))/factorial(n)*(x-a)^n),x);
  9423:     //    {0,
  9424:     //     log(2),
  9425:     //            2
  9426:     //      log(2)
  9427:     //     ---------,
  9428:     //         2
  9429:     //            3
  9430:     //      log(2)
  9431:     //     ---------,
  9432:     //         6
  9433:     //            4
  9434:     //      log(2)
  9435:     //     ---------}
  9436:     //        24
  9437:     //
  9438:     //  チェビシェフ展開
  9439:     //    [0,1]を8分割する
  9440:     //    echo read("../misc/efp.gp");eval("f(x)=2^x-1");for(s=0,7,a=s/8;b=(s+1)/8;printf("  //    [%6.3f,%6.3f]",a,b);for(n=0,15,printf("%4d",floor(closeness(f,chebyshev(f,a,b,n),a,b,10000))));print()) | gp -q
  9441:     //                      0   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15
  9442:     //    [ 0.000, 0.125] -13  -6   1   8  16  24  33  41  50  59  68  77  86  95 105 114
  9443:     //    [ 0.125, 0.250]   0   7  14  22  29  38  46  54  63  72  81  90  99 109 118 128
  9444:     //    [ 0.250, 0.375]   1   8  15  22  30  38  47  55  64  73  82  91 100 110 119 128
  9445:     //    [ 0.375, 0.500]   2   8  15  23  31  39  47  56  65  73  82  91 101 110 119 129
  9446:     //    [ 0.500, 0.625]   2   9  16  23  31  39  48  56  65  74  83  92 101 110 120 129
  9447:     //    [ 0.625, 0.750]   2   9  16  24  31  40  48  56  65  74  83  92 101 111 120 130
  9448:     //    [ 0.750, 0.875]   3   9  16  24  32  40  48  57  65  74  83  92 102 111 120 130
  9449:     //    [ 0.875, 1.000]   3   9  16  24  32  40  48  57  66  74  83  92 102 111 120 130
  9450:     //
  9451:     public final EFP exp2m1 () {
  9452:       return this.exp2m1 (this);
  9453:     }  //efp.exp2m1()
  9454:     public final EFP exp2m1 (EFP x) {
  9455:       int xf = x.flg;
  9456:       if (xf << 1 != 0) {  //±0,±Inf,NaN
  9457:         if (xf == (M | I)) {  //exp2m1(-Inf)=-1
  9458:           this.flg = M;  //-1
  9459:           this.epp = 0;
  9460:           this.dvl = MSB;
  9461:           this.cvl = 0L;
  9462:         } else {  //exp2m1(±0)=±0, exp2m1(+Inf)=+Inf, exp2m1(NaN)=NaN
  9463:           this.flg = xf;  //x
  9464:         }
  9465:         return this;
  9466:       }
  9467:       //±0,±Inf,NaN以外
  9468:       epbFpsr |= EPB_FPSR_X2;  //不正確な結果。オーバーフローまたはアンダーフローのときもセットされる
  9469:       epbExceptionOperandExponent = xf | 0x3fff + x.epp << 16;
  9470:       epbExceptionOperandMantissa = x.dvl;
  9471:       if (xf < 0) {  //x<0
  9472:         if (8 <= x.epp) {  //x<=-256。exp2m1(-big)=-1
  9473:           //exp2(-big).dec()だとアンダーフローがセットされてしまう場合がある
  9474:           if (epbRoundingMode == EPB_MODE_RZ || epbRoundingMode == EPB_MODE_RP) {
  9475:             return this.sete (NEXTUP_MINUSONE[epbRoundingPrec]).finish ();  //-1
  9476:           } else {
  9477:             return this.negset1 ().finish ();  //-1
  9478:           }
  9479:         }
  9480:       } else {  //0<x
  9481:         if (15 <= x.epp) {  //32768<=x。exp2m1(+big)=+Inf
  9482:           epbFpsr |= EPB_FPSR_OF;  //オーバーフロー
  9483:           return this.sete (OVFL_RESULTS[epbRoundingPrec << 3 | epbRoundingMode << 1]).finish ();  //+Inf
  9484:         }
  9485:       }
  9486:       int xe = x.epp;
  9487:       if (xe < -2) {  //|x|<1/4
  9488:         this.inner ();
  9489:         if (this == x) {
  9490:           x = new EFP (x);  //必要なときだけコピーする
  9491:         }
  9492:         return this.imul (EXP2M1_C17, x)
  9493:           .iadd (EXP2M1_C16).imul (x)
  9494:             .iadd (EXP2M1_C15).imul (x)
  9495:               .iadd (EXP2M1_C14).imul (x)
  9496:                 .iadd (EXP2M1_C13).imul (x)
  9497:                   .iadd (EXP2M1_C12).imul (x)
  9498:                     .iadd (EXP2M1_C11).imul (x)
  9499:                       .iadd (EXP2M1_C10).imul (x)
  9500:                         .iadd (EXP2M1_C9).imul (x)
  9501:                           .iadd (EXP2M1_C8).imul (x)
  9502:                             .iadd (EXP2M1_C7).imul (x)
  9503:                               .iadd (EXP2M1_C6).imul (x)
  9504:                                 .iadd (EXP2M1_C5).imul (x)
  9505:                                   .iadd (EXP2M1_C4).imul (x)
  9506:                                     .iadd (EXP2M1_C3).imul (x)
  9507:                                       .iadd (EXP2M1_C2).imul (x)
  9508:                                         .iadd (EXP2M1_C1).outer ().mul (x);
  9509:       }
  9510:       int savedFpsr = epbFpsr;
  9511:       this.inner ().exp2 (x).outer ().dec ();
  9512:       //exp2(x).dec()だとRZ,RPのとき-1になってしまう場合がある
  9513:       if (this.flg << 1 == 0 && (this.flg < 0 && 0 <= this.epp)) {  //this<=-1
  9514:         if (epbRoundingMode == EPB_MODE_RZ || epbRoundingMode == EPB_MODE_RP) {
  9515:           this.sete (NEXTUP_MINUSONE[epbRoundingPrec]).finish ();  //-1
  9516:         }
  9517:       }
  9518:       return this.correctUnderflow (savedFpsr);
  9519:     }  //efp.exp2m1(EFP)
  9520: 
  9521:     //------------------------------------------------------------------------
  9522:     //x = x.expm1 ()
  9523:     //  x=e^x-1
  9524:     //y = y.expm1 (x)
  9525:     //  y=e^x-1
  9526:     //  0に近い数の指数関数 exponential of number being close to 0
  9527:     //
  9528:     //  グラフ
  9529:     //    perl -e "use Graph;$g=new Graph();$g->grid();$g->func(sub{my($x)=@_;exp($x)-1});print$g"
  9530:     //    echo read("../misc/efp.gp");graph(expm1) | gp -q
  9531:     //    +---------+---------+---------+---------+---------+-----*---+---------+---------+
  9532:     //    |                                       |              **                       |
  9533:     //    |                                       |              *                        |
  9534:     //    |                                       |              *                        |
  9535:     //    |                                       |             **                        |
  9536:     //    +                                       +             *                         +
  9537:     //    |                                       |            **                         |
  9538:     //    |                                       |            *                          |
  9539:     //    |                                       |           **                          |
  9540:     //    |                                       |          **                           |
  9541:     //    +                                       +          *                            +
  9542:     //    |                                       |         **                            |
  9543:     //    |                                       |        **                             |
  9544:     //    |                                       |       **                              |
  9545:     //    |                                       |      **                               |
  9546:     //    +                                       +     **                                +
  9547:     //    |                                       |    **                                 |
  9548:     //    |                                       |   **                                  |
  9549:     //    |                                       |  **                                   |
  9550:     //    |                                       |***                                    |
  9551:     //    +---------+---------+---------+--------***--------+---------+---------+---------+
  9552:     //    |                                   ****|                                       |
  9553:     //    |                                ****   |                                       |
  9554:     //    |                           ******      |                                       |
  9555:     //    |                ************           |                                       |
  9556:     //    ******************                      +                                       +
  9557:     //    |                                       |                                       |
  9558:     //    |                                       |                                       |
  9559:     //    |                                       |                                       |
  9560:     //    |                                       |                                       |
  9561:     //    +                                       +                                       +
  9562:     //    |                                       |                                       |
  9563:     //    |                                       |                                       |
  9564:     //    |                                       |                                       |
  9565:     //    |                                       |                                       |
  9566:     //    +                                       +                                       +
  9567:     //    |                                       |                                       |
  9568:     //    |                                       |                                       |
  9569:     //    |                                       |                                       |
  9570:     //    |                                       |                                       |
  9571:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
  9572:     //
  9573:     //  定義域
  9574:     //    -inf<=x<=inf
  9575:     //
  9576:     //  値域
  9577:     //    -1<y<=inf
  9578:     //
  9579:     //  メモ
  9580:     //    |x|が0に極端に近いとき、exp(x)-1を計算しようとすると情報落ちで1になってしまうが、expm1(x)は真の値に近い結果を返す
  9581:     //    e^x-e^-xは|x|が0に極端に近いときexp(x)-exp(-x)よりもexpm1(x)-expm1(-x)の方が正確
  9582:     //
  9583:     //  加算
  9584:     //    e^(x+y)-1=(e^x-1)*(e^y-1)+(e^x-1)+(e^y-1)
  9585:     //
  9586:     //  テイラー展開
  9587:     //    e^x-1=1/1!*x+1/2!*x^2+1/3!*x^3+1/4!*x^4+1/5!*x^5+1/6!*x^6+...
  9588:     //    f(n,x)=sum(k=1,n,1/k!*x^k)
  9589:     //    > coeff(sub(a=0,for n:=0:8 sum sub(x=a,df(e^x-1,x,n))/factorial(n)*(x-a)^n),x);
  9590:     //          1   1   1     1     1     1       1
  9591:     //    {0,1,---,---,----,-----,-----,------,-------}
  9592:     //          2   6   24   120   720   5040   40320
  9593:     //    e^xのテイラー展開から定数項の1を除いたもの
  9594:     //
  9595:     //  チェビシェフ展開
  9596:     //    echo read("../misc/efp.gp");eval("f(x)=expm1(x)");a=-1;b=1;forstep(n=0,30,2,printf("%4d",floor(closeness(f,chebyshev(f,a,b,n),a,b,10000)))) | gp -q
  9597:     //       0   2   4   6   8  10  12  14  16  18  20  22  24  26  28  30
  9598:     //     -11  -5   2   9  18  27  36  46  57  67  78  89 100 112 123 135
  9599:     //
  9600:     public final EFP expm1 () {
  9601:       return this.expm1 (this);
  9602:     }  //efp.expm1()
  9603:     public final EFP expm1 (EFP x) {
  9604:       int xf = x.flg;
  9605:       if (xf << 1 != 0) {  //±0,±Inf,NaN
  9606:         if (xf == (M | I)) {  //expm1(-Inf)=-1
  9607:           this.flg = M;  //-1
  9608:           this.epp = 0;
  9609:           this.dvl = MSB;
  9610:           this.cvl = 0L;
  9611:         } else {  //expm1(±0)=±0, expm1(+Inf)=+Inf, expm1(NaN)=NaN
  9612:           this.flg = xf;  //x
  9613:         }
  9614:         return this;
  9615:       }
  9616:       //±0,±Inf,NaN以外
  9617:       epbFpsr |= EPB_FPSR_X2;  //不正確な結果。オーバーフローまたはアンダーフローのときもセットされる
  9618:       epbExceptionOperandExponent = xf | 0x3fff + x.epp << 16;
  9619:       epbExceptionOperandMantissa = x.dvl;
  9620:       if (xf < 0) {  //x<0
  9621:         if (8 <= x.epp) {  //x<=-256。expm1(-big)=-1
  9622:           //exp(-big).dec()だとアンダーフローがセットされてしまう場合がある
  9623:           if (epbRoundingMode == EPB_MODE_RZ || epbRoundingMode == EPB_MODE_RP) {
  9624:             return this.sete (NEXTUP_MINUSONE[epbRoundingPrec]).finish ();  //-1
  9625:           } else {
  9626:             return this.negset1 ().finish ();  //-1
  9627:           }
  9628:         }
  9629:       } else {  //0<x
  9630:         if (15 <= x.epp) {  //32768<=x。expm1(+big)=+Inf
  9631:           epbFpsr |= EPB_FPSR_OF;  //オーバーフロー
  9632:           return this.sete (OVFL_RESULTS[epbRoundingPrec << 3 | epbRoundingMode << 1]).finish ();  //+Inf
  9633:         }
  9634:       }
  9635:       int savedFpsr = epbFpsr;
  9636:       this.inner ();
  9637:       if (x.epp < -2) {  //|x|<1/4
  9638:         if (this == x) {
  9639:           x = new EFP (x);
  9640:         }
  9641:         this.imul (EXPM1_C18, x)
  9642:           .iadd (EXPM1_C17).imul (x)
  9643:             .iadd (EXPM1_C16).imul (x)
  9644:               .iadd (EXPM1_C15).imul (x)
  9645:                 .iadd (EXPM1_C14).imul (x)
  9646:                   .iadd (EXPM1_C13).imul (x)
  9647:                     .iadd (EXPM1_C12).imul (x)
  9648:                       .iadd (EXPM1_C11).imul (x)
  9649:                         .iadd (EXPM1_C10).imul (x)
  9650:                           .iadd (EXPM1_C9).imul (x)
  9651:                             .iadd (EXPM1_C8).imul (x)
  9652:                               .iadd (EXPM1_C7).imul (x)
  9653:                                 .iadd (EXPM1_C6).imul (x)
  9654:                                   .iadd (EXPM1_C5).imul (x)
  9655:                                     .iadd (EXPM1_C4).imul (x)
  9656:                                       .iadd (EXPM1_C3).imul (x)
  9657:                                         .iadd (EXPM1_C2).imul (x)
  9658:                                           .iadd (EXPM1_C1).outer ().mul (x);
  9659:         return this.originUpperUpper (x).correctUnderflow (savedFpsr);
  9660:       }
  9661:       return this.imul (LOG2_E, x).outer ().exp2m1 ();
  9662:     }  //efp.expm1(EFP)
  9663: 
  9664:     //------------------------------------------------------------------------
  9665:     //x = x.floor ()
  9666:     //  x=floor(x)
  9667:     //y = y.floor (x)
  9668:     //  y=floor(x)
  9669:     //  床関数 floor function
  9670:     //
  9671:     //  グラフ
  9672:     //    perl -e "use POSIX;use Graph;$g=new Graph();$g->grid();$g->func(sub{floor($_[0])});print$g"
  9673:     //    echo read("../misc/efp.gp");graph(floor) | gp -q
  9674:     //    +---------+---------+---------+---------+---------+---------+---------+---------*
  9675:     //    |                                       |                                       |
  9676:     //    |                                       |                                       |
  9677:     //    |                                       |                                       |
  9678:     //    |                                       |                                       |
  9679:     //    +                                       +                             ***********
  9680:     //    |                                       |                                       |
  9681:     //    |                                       |                                       |
  9682:     //    |                                       |                                       |
  9683:     //    |                                       |                                       |
  9684:     //    +                                       +                   ***********         +
  9685:     //    |                                       |                                       |
  9686:     //    |                                       |                                       |
  9687:     //    |                                       |                                       |
  9688:     //    |                                       |                                       |
  9689:     //    +                                       +         ***********                   +
  9690:     //    |                                       |                                       |
  9691:     //    |                                       |                                       |
  9692:     //    |                                       |                                       |
  9693:     //    |                                       |                                       |
  9694:     //    +---------+---------+---------+---------***********---------+---------+---------+
  9695:     //    |                                       |                                       |
  9696:     //    |                                       |                                       |
  9697:     //    |                                       |                                       |
  9698:     //    |                                       |                                       |
  9699:     //    +                             ***********                                       +
  9700:     //    |                                       |                                       |
  9701:     //    |                                       |                                       |
  9702:     //    |                                       |                                       |
  9703:     //    |                                       |                                       |
  9704:     //    +                   ***********         +                                       +
  9705:     //    |                                       |                                       |
  9706:     //    |                                       |                                       |
  9707:     //    |                                       |                                       |
  9708:     //    |                                       |                                       |
  9709:     //    +         ***********                   +                                       +
  9710:     //    |                                       |                                       |
  9711:     //    |                                       |                                       |
  9712:     //    |                                       |                                       |
  9713:     //    |                                       |                                       |
  9714:     //    ***********---------+---------+---------+---------+---------+---------+---------+
  9715:     //
  9716:     //  x以下で最大の整数を返す
  9717:     //  +0<=x<1のときは+0を返す
  9718:     //  x==-0のときだけ-0を返す
  9719:     //  floor(x)==-ceil(-x)
  9720:     //
  9721:     public final EFP floor () {
  9722:       return this.floor (this);
  9723:     }  //efp.floor()
  9724:     public final EFP floor (EFP x) {  //2.7ns
  9725:       int xf = x.flg;
  9726:       if (xf << 1 != 0) {  //±0,±Inf,NaN
  9727:         this.flg = xf;
  9728:         return this;
  9729:       }
  9730:       //±0,±Inf,NaN以外
  9731:       int xe = x.epp;
  9732:       if (xe < 0) {  //すべて小数部
  9733:         epbFpsr |= EPB_FPSR_X2;  //不正確な結果
  9734:         if (xf >= 0) {  //floor(0<x<1)=+0
  9735:           this.flg = P | Z;
  9736:         } else {  //floor(-1<x<0)=-1
  9737:           this.flg = M;
  9738:           this.epp = 0;
  9739:           this.dvl = MSB;
  9740:           this.cvl = 0L;
  9741:         }
  9742:         return this;
  9743:       }
  9744:       //整数部がある
  9745:       long xd = x.dvl;
  9746:       long xc = x.cvl;
  9747:       long m = MSB >> xe;  //整数部のマスク。符号に注意
  9748:       if (xf >= 0) {  //floor(0<x)=trunc(x)。小数部を切り捨てる
  9749:         if (xe <= 63) {  //0..63。dの途中または末尾まで整数部
  9750:           if ((xd & ~m | xc) != 0L) {  //小数部が0ではない
  9751:             epbFpsr |= EPB_FPSR_X2;  //不正確な結果
  9752:             xd &= m;  //小数部を切り捨てる
  9753:             xc = 0L;
  9754:           }
  9755:         } else if (xe <= LEN - 2) {  //64..90。cの途中まで整数部
  9756:           if ((xc & ~m) != 0L) {  //小数部が0ではない
  9757:             epbFpsr |= EPB_FPSR_X2;  //不正確な結果
  9758:             xc &= m;  //小数部を切り捨てる
  9759:           }
  9760:         }
  9761:         //すべて整数部のときはそのまま
  9762:       } else {  //floor(x<0)。小数部を切り捨てる。小数部が0でなかったときは絶対値に1を加える
  9763:         if (xe <= 63) {  //0..63。dの途中または末尾まで整数部
  9764:           long t = xd;  //保存して
  9765:           xd &= m;  //小数部を切り捨てる
  9766:           if (((t ^ xd) | xc) != 0L) {  //小数部が0でなかった
  9767:             epbFpsr |= EPB_FPSR_X2;  //不正確な結果
  9768:             xd -= m;  //絶対値に1を加える。符号に注意
  9769:             if (xd >= 0L) {  //dから溢れた
  9770:               xd = MSB;
  9771:               xe++;
  9772:               if ((short) xe != xe) {  //オーバーフローした
  9773:                 epbFpsr |= EPB_FPSR_OF;  //オーバーフロー
  9774:                 epbExceptionOperandExponent = xf;
  9775:                 epbExceptionOperandMantissa = xd;
  9776:                 return this.sete (OVFL_RESULTS[epbRoundingPrec << 3 | epbRoundingMode << 1 | 1]).finish ();  //-Inf
  9777:               }
  9778:             }
  9779:             xc = 0L;
  9780:           }
  9781:           //小数部が0のときはそのまま
  9782:         } else if (xe <= LEN - 2) {  //64..90。cの途中まで整数部
  9783:           long t = xc;  //保存して
  9784:           xc &= m;  //小数部を切り捨てる
  9785:           if ((t ^ xc) != 0L) {  //小数部が0でなかった
  9786:             epbFpsr |= EPB_FPSR_X2;  //不正確な結果
  9787:             xc -= m;  //絶対値に1を加える。符号に注意
  9788:             if ((t ^ xc) < 0L) {  //cから溢れた
  9789:               xd++;
  9790:               if (xd >= 0L) {  //dから溢れた
  9791:                 xd = MSB;
  9792:                 xe++;
  9793:                 if ((short) xe != xe) {  //オーバーフローした
  9794:                   epbFpsr |= EPB_FPSR_OF;  //オーバーフロー
  9795:                   epbExceptionOperandExponent = xf;
  9796:                   epbExceptionOperandMantissa = xd;
  9797:                   return this.sete (OVFL_RESULTS[epbRoundingPrec << 3 | epbRoundingMode << 1 | 1]).finish ();  //-Inf
  9798:                 }
  9799:               }
  9800:             }
  9801:           }
  9802:         }
  9803:         //すべて整数部のときはそのまま
  9804:       }
  9805:       return this.finish (xf, xe, xd, xc, 0L);
  9806:     }  //efp.floor(EFP)
  9807: 
  9808:     //------------------------------------------------------------------------
  9809:     //x = x.frac ()
  9810:     //  x=frac(x)
  9811:     //y = y.frac (x)
  9812:     //  y=frac(x)
  9813:     //  小数部 fractional part
  9814:     //
  9815:     //  グラフ
  9816:     //    perl -e "use Graph;$g=new Graph();$g->grid();$g->func(sub{$_[0]-int$_[0]});print$g"
  9817:     //    echo read("../misc/efp.gp");eval("f(x)=x-truncate(x)");graph(f) | gp -q
  9818:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
  9819:     //    |                                       |                                       |
  9820:     //    |                                       |                                       |
  9821:     //    |                                       |                                       |
  9822:     //    |                                       |                                       |
  9823:     //    +                                       +                                       +
  9824:     //    |                                       |                                       |
  9825:     //    |                                       |                                       |
  9826:     //    |                                       |                                       |
  9827:     //    |                                       |                                       |
  9828:     //    +                                       +                                       +
  9829:     //    |                                       |                                       |
  9830:     //    |                                       |                                       |
  9831:     //    |                                       |                                       |
  9832:     //    |                                       |                                       |
  9833:     //    +                                       +        **        **        **        **
  9834:     //    |                                       |      ***       ***       ***       ***|
  9835:     //    |                                       |    ***       ***       ***       ***  |
  9836:     //    |                                       |  ***       ***       ***       ***    |
  9837:     //    |                                       |***       ***       ***       ***      |
  9838:     //    *--------**--------**--------**--------***--------**--------**--------**--------*
  9839:     //    |      ***       ***       ***       ***|                                       |
  9840:     //    |    ***       ***       ***       ***  |                                       |
  9841:     //    |  ***       ***       ***       ***    |                                       |
  9842:     //    |***       ***       ***       ***      |                                       |
  9843:     //    **        **        **        **        +                                       +
  9844:     //    |                                       |                                       |
  9845:     //    |                                       |                                       |
  9846:     //    |                                       |                                       |
  9847:     //    |                                       |                                       |
  9848:     //    +                                       +                                       +
  9849:     //    |                                       |                                       |
  9850:     //    |                                       |                                       |
  9851:     //    |                                       |                                       |
  9852:     //    |                                       |                                       |
  9853:     //    +                                       +                                       +
  9854:     //    |                                       |                                       |
  9855:     //    |                                       |                                       |
  9856:     //    |                                       |                                       |
  9857:     //    |                                       |                                       |
  9858:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
  9859:     //
  9860:     //  frac(x)=(t=x-trunc(x))==0?copySign(0,x):t
  9861:     //
  9862:     //  整数部を切り捨てて符号と小数部だけ残す
  9863:     //
  9864:     //  doubleの場合
  9865:     //    frac(x)=Double.doubleToLongBits(x)>=0L?x-Math.floor(x):-(-x-Math.floor(-x))
  9866:     //      符号の判別がx>=+0.0でない理由
  9867:     //        doubleの比較演算子は-0.0と+0.0を区別しないのでx>=+0.0だとfrac(-0.0)が+0.0になってしまう
  9868:     //        Double.compare(x,+0.0)>=+0.0でも-0.0と+0.0を区別できるがDouble.doubleToLongBits(x)>=0Lの方が速そう
  9869:     //      負のときの式がx-Math.ceil(x)でない理由
  9870:     //        doubleの(-1.0)-(-1.0)は+0.0なのでx-ceil(x)だとfrac(-1.0)が+0.0になってしまう
  9871:     //
  9872:     public final EFP frac () {
  9873:       return this.frac (this);
  9874:     }  //efp.frac()
  9875:     public final EFP frac (EFP x) {  //5.6ns
  9876:       int xf = x.flg;
  9877:       if (xf << 1 != 0) {  //±0,±Inf,NaN
  9878:         this.flg = xf << 2 != 0 ? N : xf;  //frac(±Inf)=frac(NaN)=NaN,frac(±0)=±0
  9879:         return this;
  9880:       }
  9881:       //±0,±Inf,NaN以外
  9882:       int xe = x.epp;
  9883:       if (xe >= LEN - 1) {  //91..。すべて整数部
  9884:         this.flg = xf | Z;  //±0
  9885:         return this;
  9886:       }
  9887:       long xd = x.dvl;
  9888:       long xc = x.cvl;
  9889:       if (xe >= 0) {  //0..90。整数部がある
  9890:         if (xe < 63) {  //0..62。dの途中まで整数部
  9891:           xe++;  //整数部のbit数
  9892:           xd = xd << xe | xc >>> -xe;  //整数部を押し出す
  9893:           xc <<= xe;
  9894:           if (xd != 0L) {  //小数部の上位64bitが0でない
  9895:             xe = Long.numberOfLeadingZeros (xd);
  9896:             if (xe > 0) {
  9897:               xd = xd << xe | xc >>> -xe;
  9898:               xc <<= xe;
  9899:             }
  9900:             xe = ~xe;  //xe=-1-xe
  9901:           } else if (xc != 0L) {  //小数部の上位64bitが0で続く64bitが0でない
  9902:             xe = Long.numberOfLeadingZeros (xc);
  9903:             xd = xc << xe;
  9904:             xc = 0L;
  9905:             xe = -65 - xe;
  9906:           } else {  //小数部がすべて0
  9907:             this.flg = xf | Z;  //±0
  9908:             return this;
  9909:           }
  9910:         } else {  //63..90。cの先頭または途中まで整数部
  9911:           xe++;  //整数部のbit数
  9912:           xc <<= xe;  //xc<<=xe-64
  9913:           if (xc != 0L) {  //小数部が0でない
  9914:             xe = Long.numberOfLeadingZeros (xc);
  9915:             xd = xc << xe;
  9916:             xc = 0L;
  9917:             xe = ~xe;  //xe=-1-xe
  9918:           } else {  //小数部がすべて0
  9919:             this.flg = xf | Z;  //±0
  9920:             return this;
  9921:           }
  9922:         }
  9923:       }
  9924:       this.flg = xf;
  9925:       this.epp = xe;
  9926:       this.dvl = xd;
  9927:       this.cvl = xc;
  9928:       return this;
  9929:     }  //efp.frac(EFP)
  9930: 
  9931:     //------------------------------------------------------------------------
  9932:     //b = x.ge (y)
  9933:     //  b=x>=y
  9934:     //  より大きいか等しいか
  9935:     //
  9936:     //  -Inf==-Inf<-x<-0==+0<+x<+Inf==+Inf
  9937:     //
  9938:     //  NaNの扱い
  9939:     //    どちらかがNaNのときはfalseを返す
  9940:     //
  9941:     public boolean ge (EFP y) {
  9942:       int xf = this.flg;
  9943:       int yf = y.flg;
  9944:       if ((xf | yf) << 1 != 0) {  //どちらかが±0,±Inf,NaN
  9945:         return EFP_GE_TABLE[xf >>> 28] << (yf >>> 28 - 1) < 0;
  9946:       }
  9947:       //両方±0,±Inf,NaN以外
  9948:       if (xf != yf) {  //両方±0,±Inf,NaN以外で符号が違う
  9949:         return xf > yf;
  9950:       }
  9951:       //両方±0,±Inf,NaN以外で符号が同じ
  9952:       int s;
  9953:       long t;
  9954:       return (xf >= 0 ? 1 : -1) * ((s = this.epp - y.epp) != 0 ? s >= 0 ? 1 : -1 :
  9955:                                    (t = this.dvl - y.dvl) != 0L ? t >= 0L ? 1 : -1 :
  9956:                                    (t = (this.cvl >>> 1) - (y.cvl >>> 1)) != 0L ? t >= 0L ? 1 : -1 :
  9957:                                    0) >= 0;
  9958:     }  //efp.ge(EFP)
  9959: 
  9960:     //------------------------------------------------------------------------
  9961:     //i = x.getb ()
  9962:     //i = x.getb (roundingMode)
  9963:     //  byte値
  9964:     //
  9965:     //  丸めモードを省略したときは小数点以下を切り捨てる(RZ)
  9966:     //  2^7-1よりも大きい数は2^7-1に、-2^7よりも小さい数は-2^7に変換する(飽和変換)
  9967:     //  NaNは-1に変換する
  9968:     //
  9969:     //  Javaのdoubleからbyteへのキャストは飽和変換ではない(intに飽和変換してから下位8bitを取り出す)ことに注意
  9970:     //
  9971:     public int getb () {
  9972:       int xf = this.flg;
  9973:       if (xf << 1 != 0) {  //±0,±Inf,NaN
  9974:         if (xf << 1 < 0) {  //±0
  9975:           return 0;
  9976:         } else if (xf << 2 < 0) {  //±Inf
  9977:           epbFpsr |= EPB_FPSR_OE;
  9978:           epbExceptionOperandExponent = xf & M | 0x7fff << 16;
  9979:           epbExceptionOperandMantissa = 0x0000000000000000L;
  9980:           return xf >> 31 ^ 0x0000007f;  //+Infは0x0000007f,-Infは0xffffff80
  9981:         } else {  //NaN
  9982:           epbFpsr |= EPB_FPSR_OE | EPB_FPSR_AV;
  9983:           epbExceptionOperandExponent = 0x7fff << 16;
  9984:           epbExceptionOperandMantissa = 0xffffffffffffffffL;
  9985:           return -1;  //NaNは-1
  9986:         }
  9987:       }
  9988:       //±0,±Inf,NaN以外
  9989:       int xe = this.epp;
  9990:       long xd = this.dvl;
  9991:       long xc = this.cvl;
  9992:       if (xe < 0) {  //0<|x|<1
  9993:         if (false) {
  9994:           epbFpsr |= EPB_FPSR_X2;  //不正確な結果
  9995:           epbExceptionOperandExponent = xf | 0x3fff + xe << 16;
  9996:           epbExceptionOperandMantissa = xd;
  9997:         }
  9998:         return 0;
  9999:       }
 10000:       //1<=|x|
 10001:       if (xe < 7) {  //1<=|x|<2^7
 10002:         if (false) {
 10003:           if ((xd << 1 + xe | xc) != 0L) {  //端数がある
 10004:             epbFpsr |= EPB_FPSR_X2;  //不正確な結果
 10005:             epbExceptionOperandExponent = xf | 0x3fff + xe << 16;
 10006:             epbExceptionOperandMantissa = xd;
 10007:           }
 10008:         }
 10009:         return xf >= 0 ? (int) (xd >>> ~xe) : -(int) (xd >>> ~xe);
 10010:       }
 10011:       //2^7<=|x|
 10012:       if (xf >= 0) {  //2^7<=x
 10013:         epbFpsr |= EPB_FPSR_OE;
 10014:         epbExceptionOperandExponent = 0x3fff + xe << 16;
 10015:         epbExceptionOperandMantissa = xd;
 10016:         return 0x0000007f;
 10017:       }
 10018:       //x<=-2^7
 10019:       if (xe != 7 || xd != MSB || xc != 0L) {  //x!=-2^7
 10020:         epbFpsr |= EPB_FPSR_OE;
 10021:         epbExceptionOperandExponent = M | 0x3fff + xe << 16;
 10022:         epbExceptionOperandMantissa = this.dvl;
 10023:       }
 10024:       return 0xffffff80;
 10025:     }  //efp.getb()
 10026:     public int getb (int roundingMode) {
 10027:       return (roundingMode == EPB_MODE_RN ? new EFP ().inner ().rint (this).outer ().getb () :
 10028:               roundingMode == EPB_MODE_RM ? new EFP ().inner ().floor (this).outer ().getb () :
 10029:               roundingMode == EPB_MODE_RP ? new EFP ().inner ().ceil (this).outer ().getb () :
 10030:               new EFP ().inner ().trunc (this).outer ().getb ());
 10031:     }  //efp.getb(int)
 10032: 
 10033:     //------------------------------------------------------------------------
 10034:     //d = x.getd ()
 10035:     //d = x.getd (roundingMode)
 10036:     //l = x.getd01 ()
 10037:     //l = x.getd01 (roundingMode)
 10038:     //l = x.getd01 (b, a)
 10039:     //l = x.getd01 (b, a, roundingMode)
 10040:     //  double値
 10041:     //
 10042:     //    0x7fffffffffffffffL  Non-Signaling NaN
 10043:     //    0x7ff7ffffffffffffL  Signaling NaN
 10044:     //    0x7ff0000000000000L  +Inf
 10045:     //    0x7fefffffffffffffL  2^1024-2^971    = 1.7976931348623157081452742373170435680 E308   正規化数の最大値
 10046:     //    0x3ff0000000000000L  2^0             = 1
 10047:     //    0x0010000000000000L  2^-1022         = 2.2250738585072013830902327173324040642 E-308  正規化数の最小値
 10048:     //    0x000fffffffffffffL  2^-1022-2^-1074 = 2.2250738585072008890245868760858598877 E-308  非正規化数の最大値
 10049:     //    0x0000000000000001L  2^-1074         = 4.9406564584124654417656879286822137237 E-324  非正規化数の最小値
 10050:     //    0x0000000000000000L  +0
 10051:     //    NaNの符号はDon't Care、出力は0
 10052:     //    Non-Signaling NaNの小数部の先頭は1
 10053:     //    Signaling NaNの小数部の先頭は0
 10054:     //      Signaling NaNが返ることはない
 10055:     //    NaNの小数部の先頭以外はNon-Zero、出力はすべて1
 10056:     //    ±Infの小数部はすべて0
 10057:     //
 10058:     //    for (long l : new long[] {
 10059:     //      0x7ff0000000000000L,
 10060:     //      0x7fefffffffffffffL,
 10061:     //      0x3ff0000000000000L,
 10062:     //      0x0010000000000000L,
 10063:     //      0x000fffffffffffffL,
 10064:     //      0x0000000000000001L,
 10065:     //      0x0000000000000000L,
 10066:     //    }) {
 10067:     //      System.out.printf ("      //  0x%016x  %.17g\n", l, Double.longBitsToDouble (l));
 10068:     //    }
 10069:     //    0x7ff0000000000000  Infinity
 10070:     //    0x7fefffffffffffff  1.7976931348623157e+308
 10071:     //    0x3ff0000000000000  1.0000000000000000
 10072:     //    0x0010000000000000  2.2250738585072014e-308
 10073:     //    0x000fffffffffffff  2.2250738585072010e-308
 10074:     //    0x0000000000000001  4.9000000000000000e-324  不正確なのではなくて非正規化数の有効桁数が調整されている
 10075:     //    0x0000000000000000  0.0000000000000000
 10076:     //
 10077:     //  丸めモードを省略したときは最も近い値に丸める(RN)
 10078:     //
 10079:     public double getd () {
 10080:       return Double.longBitsToDouble (this.getd01 (EPB_MODE_RN));
 10081:     }  //efp.getd()
 10082:     public double getd (int roundingMode) {
 10083:       return Double.longBitsToDouble (this.getd01 (roundingMode));
 10084:     }  //efp.getd(int)
 10085:     public long getd01 () {
 10086:       return this.getd01 (EPB_MODE_RN);
 10087:     }  //efp.getd01()
 10088:     public long getd01 (int roundingMode) {
 10089:       int xf = this.flg;
 10090:       if (xf << 1 != 0) {  //±0,±Inf,NaN
 10091:         return (xf << 1 < 0 ? 0 <= xf ? 0x0000000000000000L : 0x8000000000000000L :  //±0
 10092:                 xf << 2 < 0 ? 0 <= xf ? 0x7ff0000000000000L : 0xfff0000000000000L :  //±Inf
 10093:                 EFP_FPCP_NAN ? 0x7fffffffffffffffL : 0x7ff8000000000000L);  //NaN
 10094:       }
 10095:       //±0,±Inf,NaN以外
 10096:       int xe = this.epp;  //正規化数は-1022<=xe<=1023、非正規化数は-1075<=xe<=-1023
 10097:       long xd = this.dvl;
 10098:       long xc = this.cvl;
 10099:       if (xe < -1075) {  //指数部が小さすぎる。非正規化数の最小値は2^-1074だが丸めで繰り上がる場合があるので一旦2^-1075まで受け入れる
 10100:         epbFpsr |= EPB_FPSR_UF | EPB_FPSR_X2;  //アンダーフロー、不正確な結果
 10101:         epbExceptionOperandExponent = xf | 0x3fff + 0x6000 + xe << 16;
 10102:         epbExceptionOperandMantissa = xd;
 10103:         return (0 <= xf ?
 10104:                 roundingMode == EPB_MODE_RP ? 0x0000000000000001L : 0x0000000000000000L :  //RPのとき+eps,RN,RZ,RMのとき+0
 10105:                 roundingMode == EPB_MODE_RM ? 0x8000000000000001L : 0x8000000000000000L);  //RMのとき-eps,RN,RZ,RPのとき-0
 10106:       }
 10107:       if (1023 < xe) {  //指数部が大きすぎる
 10108:         if (true) {
 10109:           epbFpsr |= EPB_FPSR_OF;  //オーバーフロー
 10110:           if ((xd << 53 | xc) != 0L) {  //端数が0ではない
 10111:             epbFpsr |= EPB_FPSR_X2;  //不正確な結果
 10112:           }
 10113:         } else {
 10114:           epbFpsr |= EPB_FPSR_OF | EPB_FPSR_X2;  //オーバーフロー、不正確な結果
 10115:         }
 10116:         epbExceptionOperandExponent = xf | 0x3fff - 0x6000 + xe << 16;
 10117:         epbExceptionOperandMantissa = xd;
 10118:         return (0 <= xf ?
 10119:                 roundingMode == EPB_MODE_RZ || roundingMode == EPB_MODE_RM ? 0x7fefffffffffffffL : 0x7ff0000000000000L :  //RZ,RMのとき+max,RN,RPのとき+Inf
 10120:                 roundingMode == EPB_MODE_RZ || roundingMode == EPB_MODE_RP ? 0xffefffffffffffffL : 0xfff0000000000000L);  //RZ,RPのとき-max,RN,RMのとき-Inf
 10121:       }
 10122:       long xb = 0L;
 10123:       int o = xe <= -1023 ? 11 + -1022 - xe : 11;  //右にずらすbit数。正規化数は11、非正規化数は11+1<=o<=11+53
 10124:       if (o < 64) {
 10125:         xb = xc << -o;
 10126:         xc = xd << -o | xc >>> o;
 10127:         xd >>>= o;
 10128:       } else {
 10129:         xb = xc;
 10130:         xc = xd;
 10131:         xd = 0L;
 10132:       }
 10133:       if ((xc | xb) != 0L) {  //端数が0ではない
 10134:         epbFpsr |= EPB_FPSR_X2;  //不正確な結果
 10135:         if (roundingMode == EPB_MODE_RN && xc < 0L && (xd << 63 | xc << 1 | xb) != 0L ||  //RNでguard bitが1かつLSBまたはguard bit以外の端数が0ではないまたは
 10136:             roundingMode == EPB_MODE_RM && xf < 0 ||  //端数が0ではなくてRMで-または
 10137:             roundingMode == EPB_MODE_RP && 0 <= xf) {  //端数が0ではなくてRPで+のとき
 10138:           xd++;  //繰り上げる
 10139:           if (xd >>> 53 != 0L) {  //繰り上がって溢れたとき
 10140:             xd = 1L << 52;
 10141:             xe++;  //指数部をインクリメントする。ここでxe=1024になる場合がある
 10142:             if (1023 < xe) {  //指数部が大きすぎる
 10143:               epbFpsr |= EPB_FPSR_OF | EPB_FPSR_X2;  //オーバーフロー、不正確な結果
 10144:               epbExceptionOperandExponent = xf | 0x3fff - 0x6000 + xe << 16;
 10145:               epbExceptionOperandMantissa = xd;
 10146:               return (0 <= xf ?
 10147:                       roundingMode == EPB_MODE_RZ || roundingMode == EPB_MODE_RM ? 0x7fefffffffffffffL : 0x7ff0000000000000L :  //RZ,RMのとき+max,RN,RPのとき+Inf
 10148:                       roundingMode == EPB_MODE_RZ || roundingMode == EPB_MODE_RP ? 0xffefffffffffffffL : 0xfff0000000000000L);  //RZ,RPのとき-max,RN,RMのとき-Inf
 10149:             }  //if 指数部が大きすぎる
 10150:           } else if (11 < o) {  //非正規化数のとき
 10151:             if (xd << o - 1 < 0L) {  //1bit増えたとき
 10152:               xe++;  //指数部をインクリメントする
 10153: /* getd01 */
 10154:               if (xe == -1022) {  //非正規化数が繰り上がって正規化数になったとき
 10155:                 //xd = 1L << 52;
 10156:                 epbFpsr |= EPB_FPSR_UF | EPB_FPSR_X2;  //アンダーフロー、不正確な結果
 10157:                 epbExceptionOperandExponent = xf | 0x3fff + 0x6000 + xe << 16;
 10158:                 epbExceptionOperandMantissa = xd;
 10159:               }
 10160: /**/
 10161:             }
 10162:           }
 10163:         }
 10164:         //RZ toward zeroのときは端数を切り捨てるだけなので何もしなくてよい
 10165:         if (xe <= -1023) {  //非正規化数
 10166:           epbFpsr |= EPB_FPSR_UF | EPB_FPSR_X2;  //アンダーフロー、不正確な結果
 10167:           epbExceptionOperandExponent = xf | 0x3fff + 0x6000 + xe << 16;
 10168:           epbExceptionOperandMantissa = xd;
 10169:           if (xd == 0L) {  //非正規化数でxe==-1075だったとき、先頭の1がxcにあって丸めで繰り上がらなかった
 10170:             return (0 <= xf ?
 10171:                     roundingMode == EPB_MODE_RP ? 0x0000000000000001L : 0x0000000000000000L :  //RPのとき+eps,RN,RZ,RMのとき+0
 10172:                     roundingMode == EPB_MODE_RM ? 0x8000000000000001L : 0x8000000000000000L);  //RMのとき-eps,RN,RZ,RPのとき-0
 10173:           }
 10174:         }  //if 非正規化数
 10175:       } else {  //端数が0
 10176:         if (xe <= -1023) {  //非正規化数
 10177:           epbFpsr |= EPB_FPSR_UF;  //アンダーフロー
 10178:           epbExceptionOperandExponent = xf | 0x3fff + 0x6000 + xe << 16;
 10179:           epbExceptionOperandMantissa = xd;
 10180:           if (xd == 0L) {  //非正規化数でxe==-1075だったとき、先頭の1がxcにあって丸めで繰り上がらなかった
 10181:             return (0 <= xf ?
 10182:                     roundingMode == EPB_MODE_RP ? 0x0000000000000001L : 0x0000000000000000L :  //RPのとき+eps,RN,RZ,RMのとき+0
 10183:                     roundingMode == EPB_MODE_RM ? 0x8000000000000001L : 0x8000000000000000L);  //RMのとき-eps,RN,RZ,RPのとき-0
 10184:           }
 10185:         }  //if 非正規化数
 10186:       }  //if 端数が0ではない/端数が0
 10187:       return ((long) (xf | Math.max (0, xe + 1023) << 52 - 32) << 32 |  //符号と指数部
 10188:               xd & ((1L << 52) - 1L));  //仮数部。正規化数のときは先頭の1を取り除く
 10189:     }  //efp.getd01(int)
 10190:     public long getd01 (byte[] b, int a) {
 10191:       long l = this.getd01 (EPB_MODE_RN);
 10192:       b[a    ] = (byte) (l >>> 56);
 10193:       b[a + 1] = (byte) (l >>> 48);
 10194:       b[a + 2] = (byte) (l >>> 40);
 10195:       b[a + 3] = (byte) (l >>> 32);
 10196:       b[a + 4] = (byte) (l >>> 24);
 10197:       b[a + 5] = (byte) (l >>> 16);
 10198:       b[a + 6] = (byte) (l >>>  8);
 10199:       b[a + 7] = (byte)  l;
 10200:       return l;
 10201:     }  //efp.getd01(byte[],int)
 10202:     public long getd01 (byte[] b, int a, int roundingMode) {
 10203:       long l = this.getd01 (roundingMode);
 10204:       b[a    ] = (byte) (l >>> 56);
 10205:       b[a + 1] = (byte) (l >>> 48);
 10206:       b[a + 2] = (byte) (l >>> 40);
 10207:       b[a + 3] = (byte) (l >>> 32);
 10208:       b[a + 4] = (byte) (l >>> 24);
 10209:       b[a + 5] = (byte) (l >>> 16);
 10210:       b[a + 6] = (byte) (l >>>  8);
 10211:       b[a + 7] = (byte)  l;
 10212:       return l;
 10213:     }  //efp.getd01(byte[],int,int)
 10214: 
 10215:     //------------------------------------------------------------------------
 10216:     //x = x.getexp ()
 10217:     //y = y.getexp (x)
 10218:     //  指数部
 10219:     //
 10220:     //  getexp(±0)=±0, getexp(±Inf)=NaN, getexp(NaN)=NaN
 10221:     //
 10222:     public final EFP getexp () {
 10223:       return this.getexp (this);
 10224:     }  //efp.getexp()
 10225:     public final EFP getexp (EFP x) {
 10226:       int xf = x.flg;
 10227:       if (xf << 1 != 0) {  //±0,±Inf,NaN
 10228:         if (xf << 2 < 0) {  //±Inf
 10229:           epbFpsr |= EPB_FPSR_OE;
 10230:           epbExceptionOperandExponent = xf & M | 0x7fff << 16;
 10231:           epbExceptionOperandMantissa = 0x0000000000000000L;
 10232:           this.flg = N;  //getexp(±Inf)=NaN
 10233:         } else {  //±0,NaN
 10234:           this.flg = xf;  //getexp(±0)=±0, getexp(NaN)=NaN
 10235:         }
 10236:         return this;
 10237:       }
 10238:       return this.seti (x.epp);  //指数部
 10239:     }  //efp.getexp(EFP)
 10240: 
 10241:     //------------------------------------------------------------------------
 10242:     //f = x.getf ()
 10243:     //f = x.getf (roundingMode)
 10244:     //i = x.getf0 ()
 10245:     //i = x.getf0 (roundingMode)
 10246:     //i = x.getf0 (b, a)
 10247:     //i = x.getf0 (b, a, roundingMode)
 10248:     //  float値
 10249:     //
 10250:     //    0x7fffffff  Non-Signaling NaN
 10251:     //    0x7fbfffff  Signaling NaN
 10252:     //    0x7f800000  +Inf
 10253:     //    0x7f7fffff  2^128-2^104   = 3.4028234663852885981170418348451692544 E38   正規化数の最大値
 10254:     //    0x3f800000  2^0           = 1
 10255:     //    0x00800000  2^-126        = 1.1754943508222875079687365372222456778 E-38  正規化数の最小値
 10256:     //    0x007fffff  2^-126-2^-149 = 1.1754942106924410754870294448492873488 E-38  非正規化数の最大値
 10257:     //    0x00000001  2^-149        = 1.4012984643248170709237295832899161313 E-45  非正規化数の最小値
 10258:     //    0x00000000  +0
 10259:     //    NaNの符号はDon't Care、出力は0
 10260:     //    Non-Signaling NaNの小数部の先頭は1
 10261:     //    Signaling NaNの小数部の先頭は0
 10262:     //      Signaling NaNが返ることはない
 10263:     //    NaNの小数部の先頭以外はNon-Zero、出力はすべて1
 10264:     //    ±Infの小数部はすべて0
 10265:     //
 10266:     //    for (int i : new int[] {
 10267:     //      0x7f800000,
 10268:     //      0x7f7fffff,
 10269:     //      0x3f800000,
 10270:     //      0x00800000,
 10271:     //      0x007fffff,
 10272:     //      0x00000001,
 10273:     //      0x00000000,
 10274:     //    }) {
 10275:     //      System.out.printf ("      //  0x%08x  %.17g\n", i, Float.intBitsToFloat (i));
 10276:     //    }
 10277:     //    0x7f800000  Infinity
 10278:     //    0x7f7fffff  3.4028234663852886e+38
 10279:     //    0x3f800000  1.0000000000000000
 10280:     //    0x00800000  1.1754943508222875e-38
 10281:     //    0x007fffff  1.1754942106924411e-38
 10282:     //    0x00000001  1.4012984643248170e-45  doubleでは正規化数なので有効桁数は17桁
 10283:     //    0x00000000  0.0000000000000000
 10284:     //
 10285:     //  丸めモードを省略したときは最も近い値に丸める(RN)
 10286:     //
 10287:     public float getf () {
 10288:       return Float.intBitsToFloat (this.getf0 (EPB_MODE_RN));
 10289:     }  //efp.getf()
 10290:     public float getf (int roundingMode) {
 10291:       return Float.intBitsToFloat (this.getf0 (roundingMode));
 10292:     }  //efp.getf(int)
 10293:     public int getf0 () {
 10294:       return this.getf0 (EPB_MODE_RN);
 10295:     }  //efp.getf0()
 10296:     public int getf0 (int roundingMode) {
 10297:       int xf = this.flg;
 10298:       if (xf << 1 != 0) {  //±0,±Inf,NaN
 10299:         return (xf << 1 < 0 ? xf & M :  //±0
 10300:                 xf << 2 < 0 ? (xf & M) | 0x7f800000 :  //±Inf
 10301:                 EFP_FPCP_NAN ? 0x7fffffff : 0x7fc00000);  //NaN
 10302:       }
 10303:       //±0,±Inf,NaN以外
 10304:       int xe = this.epp;  //正規化数は-126<=xe<=127、非正規化数は-149<=xe<=-127
 10305:       long xd = this.dvl;
 10306:       long xc = this.cvl;
 10307:       if (xe < -150) {  //指数部が小さすぎる。非正規化数の最小値は2^-149だが丸めで繰り上がる場合があるので一旦2^-150まで受け入れる
 10308:         epbFpsr |= EPB_FPSR_UF | EPB_FPSR_X2;  //アンダーフロー、不正確な結果
 10309:         epbExceptionOperandExponent = xf | 0x3fff + 0x6000 + xe << 16;
 10310:         epbExceptionOperandMantissa = xd;
 10311:         return (0 <= xf ?
 10312:                 roundingMode == EPB_MODE_RP ? 0x00000001 : 0x00000000 :  //RPのとき+eps,RN,RZ,RMのとき+0
 10313:                 roundingMode == EPB_MODE_RM ? 0x80000001 : 0x80000000);  //RMのとき-eps,RN,RZ,RPのとき-0
 10314:       }
 10315:       if (127 < xe) {  //指数部が大きすぎる
 10316:         if (true) {
 10317:           epbFpsr |= EPB_FPSR_OF;  //オーバーフロー
 10318:           if ((xd << 24 | xc) != 0L) {  //端数が0ではない
 10319:             epbFpsr |= EPB_FPSR_X2;  //不正確な結果
 10320:           }
 10321:         } else {
 10322:           epbFpsr |= EPB_FPSR_OF | EPB_FPSR_X2;  //オーバーフロー、不正確な結果
 10323:         }
 10324:         epbExceptionOperandExponent = xf | 0x3fff - 0x6000 + xe << 16;
 10325:         epbExceptionOperandMantissa = xd;
 10326:         return (0 <= xf ?
 10327:                 roundingMode == EPB_MODE_RZ || roundingMode == EPB_MODE_RM ? 0x7f7fffff : 0x7f800000 :  //RZ,RMのとき+max,RN,RPのとき+Inf
 10328:                 roundingMode == EPB_MODE_RZ || roundingMode == EPB_MODE_RP ? 0xff7fffff : 0xff800000);  //RZ,RPのとき-max,RN,RMのとき-Inf
 10329:       }
 10330:       long xb = 0L;
 10331:       int o = xe <= -127 ? 40 + -126 - xe : 40;  //右にずらすbit数。正規化数は40、非正規化数は40+1<=o<=40+24
 10332:       if (o < 64) {
 10333:         xb = xc << -o;
 10334:         xc = xd << -o | xc >>> o;
 10335:         xd >>>= o;
 10336:       } else {
 10337:         xb = xc;
 10338:         xc = xd;
 10339:         xd = 0L;
 10340:       }
 10341:       if ((xc | xb) != 0L) {  //端数が0ではない
 10342:         epbFpsr |= EPB_FPSR_X2;  //不正確な結果
 10343:         if (roundingMode == EPB_MODE_RN && xc < 0L && (xd << -1 | xc << 1 | xb) != 0L ||  //RNでguard bitが1かつLSBまたはguard bit以外の端数が0ではないまたは
 10344:             roundingMode == EPB_MODE_RM && xf < 0 ||  //端数が0ではなくてRMで-または
 10345:             roundingMode == EPB_MODE_RP && 0 <= xf) {  //端数が0ではなくてRPで+のとき
 10346:           xd++;  //繰り上げる
 10347:           if (xd >>> 24 != 0L) {  //繰り上がって溢れたとき
 10348:             xd = 1L << 23;
 10349:             xe++;  //指数部をインクリメントする。ここでxe=128になる場合がある
 10350:             if (127 < xe) {  //指数部が大きすぎる
 10351:               epbFpsr |= EPB_FPSR_OF | EPB_FPSR_X2;  //オーバーフロー、不正確な結果
 10352:               epbExceptionOperandExponent = xf | 0x3fff - 0x6000 + xe << 16;
 10353:               epbExceptionOperandMantissa = xd;
 10354:               return (0 <= xf ?
 10355:                       roundingMode == EPB_MODE_RZ || roundingMode == EPB_MODE_RM ? 0x7f7fffff : 0x7f800000 :  //RZ,RMのとき+max,RN,RPのとき+Inf
 10356:                       roundingMode == EPB_MODE_RZ || roundingMode == EPB_MODE_RP ? 0xff7fffff : 0xff800000);  //RZ,RPのとき-max,RN,RMのとき-Inf
 10357:             }
 10358:           } else if (40 < o) {  //非正規化数のとき
 10359:             if (xd << o - 1 < 0L) {  //1bit増えたとき
 10360:               xe++;  //指数部をインクリメントする
 10361: /* getf0 */
 10362:               if (xe == -126) {  //非正規化数が繰り上がって正規化数になったとき
 10363:                 //xd = 1L << 23;
 10364:                 epbFpsr |= EPB_FPSR_UF | EPB_FPSR_X2;  //アンダーフロー、不正確な結果
 10365:                 epbExceptionOperandExponent = xf | 0x3fff + 0x6000 + xe << 16;
 10366:                 epbExceptionOperandMantissa = xd;
 10367:               }
 10368: /**/
 10369:             }
 10370:           }
 10371:         }
 10372:         //RZ toward zeroのときは端数を切り捨てるだけなので何もしなくてよい
 10373:         if (xe <= -127) {  //非正規化数
 10374:           epbFpsr |= EPB_FPSR_UF | EPB_FPSR_X2;  //アンダーフロー、不正確な結果
 10375:           epbExceptionOperandExponent = xf | 0x3fff + 0x6000 + xe << 16;
 10376:           epbExceptionOperandMantissa = xd;
 10377:           if (xd == 0L) {  //非正規化数でxe==-150だったとき、先頭の1がxcにあって丸めで繰り上がらなかった
 10378:             return (0 <= xf ?
 10379:                     roundingMode == EPB_MODE_RP ? 0x00000001 : 0x00000000 :  //RPのとき+eps,RN,RZ,RMのとき+0
 10380:                     roundingMode == EPB_MODE_RM ? 0x80000001 : 0x80000000);  //RMのとき-eps,RN,RZ,RPのとき-0
 10381:           }
 10382:         }  //if 非正規化数
 10383:       } else {  //端数が0
 10384:         if (xe <= -127) {  //非正規化数
 10385:           epbFpsr |= EPB_FPSR_UF;  //アンダーフロー
 10386:           epbExceptionOperandExponent = xf | 0x3fff + 0x6000 + xe << 16;
 10387:           epbExceptionOperandMantissa = xd;
 10388:           if (xd == 0L) {  //非正規化数でxe==-150だったとき、先頭の1がxcにあって丸めで繰り上がらなかった
 10389:             return (0 <= xf ?
 10390:                     roundingMode == EPB_MODE_RP ? 0x00000001 : 0x00000000 :  //RPのとき+eps,RN,RZ,RMのとき+0
 10391:                     roundingMode == EPB_MODE_RM ? 0x80000001 : 0x80000000);  //RMのとき-eps,RN,RZ,RPのとき-0
 10392:           }
 10393:         }  //if 非正規化数
 10394:       }  //if 端数が0ではない/端数が0
 10395:       return (xf | Math.max (0, xe + 127) << 23 |  //符号と指数部
 10396:               (int) xd & ((1 << 23) - 1));  //仮数部。正規化数のときは先頭の1を取り除く
 10397:     }  //efp.getf0(int)
 10398:     public int getf0 (byte[] b, int a) {
 10399:       int i = this.getf0 (EPB_MODE_RN);
 10400:       b[a    ] = (byte) (i >>> 24);
 10401:       b[a + 1] = (byte) (i >>> 16);
 10402:       b[a + 2] = (byte) (i >>>  8);
 10403:       b[a + 3] = (byte)  i;
 10404:       return i;
 10405:     }  //efp.getf0(byte[],int)
 10406:     public int getf0 (byte[] b, int a, int roundingMode) {
 10407:       int i = this.getf0 (roundingMode);
 10408:       b[a    ] = (byte) (i >>> 24);
 10409:       b[a + 1] = (byte) (i >>> 16);
 10410:       b[a + 2] = (byte) (i >>>  8);
 10411:       b[a + 3] = (byte)  i;
 10412:       return i;
 10413:     }  //efp.getf0(byte[],int,int)
 10414: 
 10415:     //------------------------------------------------------------------------
 10416:     //i = x.geti ()
 10417:     //i = x.geti (roundingMode)
 10418:     //  int値
 10419:     //
 10420:     //  丸めモードを省略したときは小数点以下を切り捨てる(RZ)
 10421:     //  2^31-1よりも大きい数は2^31-1に、-2^31よりも小さい数は-2^31に変換する(飽和変換)
 10422:     //  NaNは-1に変換する
 10423:     //
 10424:     public int geti () {
 10425:       int xf = this.flg;
 10426:       if (xf << 1 != 0) {  //±0,±Inf,NaN
 10427:         if (xf << 1 < 0) {  //±0
 10428:           return 0;
 10429:         } else if (xf << 2 < 0) {  //±Inf
 10430:           epbFpsr |= EPB_FPSR_OE;
 10431:           epbExceptionOperandExponent = xf & M | 0x7fff << 16;
 10432:           epbExceptionOperandMantissa = 0x0000000000000000L;
 10433:           return xf >> 31 ^ 0x7fffffff;  //+Infは0x7fffffff,-Infは0x80000000
 10434:         } else {  //NaN
 10435:           epbFpsr |= EPB_FPSR_OE | EPB_FPSR_AV;
 10436:           epbExceptionOperandExponent = 0x7fff << 16;
 10437:           epbExceptionOperandMantissa = 0xffffffffffffffffL;
 10438:           return -1;  //NaNは-1
 10439:         }
 10440:       }
 10441:       //±0,±Inf,NaN以外
 10442:       int xe = this.epp;
 10443:       long xd = this.dvl;
 10444:       long xc = this.cvl;
 10445:       if (xe < 0) {  //0<|x|<1
 10446:         if (false) {
 10447:           epbFpsr |= EPB_FPSR_X2;  //不正確な結果
 10448:           epbExceptionOperandExponent = xf | 0x3fff + xe << 16;
 10449:           epbExceptionOperandMantissa = xd;
 10450:         }
 10451:         return 0;
 10452:       }
 10453:       //1<=|x|
 10454:       if (xe < 31) {  //1<=|x|<2^31
 10455:         if (false) {
 10456:           if ((xd << 1 + xe | xc) != 0L) {  //端数がある
 10457:             epbFpsr |= EPB_FPSR_X2;  //不正確な結果
 10458:             epbExceptionOperandExponent = xf | 0x3fff + xe << 16;
 10459:             epbExceptionOperandMantissa = xd;
 10460:           }
 10461:         }
 10462:         return xf >= 0 ? (int) (xd >>> ~xe) : -(int) (xd >>> ~xe);
 10463:       }
 10464:       //2^31<=|x|
 10465:       if (xf >= 0) {  //2^31<=x
 10466:         epbFpsr |= EPB_FPSR_OE;
 10467:         epbExceptionOperandExponent = 0x3fff + xe << 16;
 10468:         epbExceptionOperandMantissa = xd;
 10469:         return 0x7fffffff;
 10470:       }
 10471:       //x<=-2^31
 10472:       if (xe != 31 || xd != MSB || xc != 0L) {  //x!=-2^31
 10473:         epbFpsr |= EPB_FPSR_OE;
 10474:         epbExceptionOperandExponent = M | 0x3fff + xe << 16;
 10475:         epbExceptionOperandMantissa = this.dvl;
 10476:       }
 10477:       return 0x80000000;
 10478:     }  //efp.geti()
 10479:     public int geti (int roundingMode) {
 10480:       return (roundingMode == EPB_MODE_RN ? new EFP ().inner ().rint (this).outer ().geti () :
 10481:               roundingMode == EPB_MODE_RM ? new EFP ().inner ().floor (this).outer ().geti () :
 10482:               roundingMode == EPB_MODE_RP ? new EFP ().inner ().ceil (this).outer ().geti () :
 10483:               new EFP ().inner ().trunc (this).outer ().geti ());
 10484:     }  //efp.geti(int)
 10485: 
 10486:     //------------------------------------------------------------------------
 10487:     //i = x.geti32abs ()
 10488:     //  i=abs(x)&0xffffffff
 10489:     //  絶対値の整数部の下位32bit(飽和なし)
 10490:     //
 10491:     public int geti32abs () {
 10492:       return geti32abs (this);
 10493:     }  //efp.geti32abs()
 10494:     public int geti32abs (EFP x) {
 10495:       int xf = x.flg;
 10496:       if (xf << 1 != 0) {  //±0,±Inf,NaN
 10497:         return 0;
 10498:       }
 10499:       //±0,±Inf,NaN以外
 10500:       int xe = x.epp;
 10501:       long xd = x.dvl;
 10502:       long xc = x.cvl;
 10503:       return (xe < 0 ? 0 :  //すべて小数部
 10504:               xe <= 63 ? (int) (xd >>> ~xe) :  //0..63。xd>>>(63..0)。整数部の下位32bitがdに収まっている
 10505:               xe <= 94 ? (int) (xd << xe + 1 | xc >>> ~xe) : //64..94。xd<<(1..31)|xc>>>(63..33)。整数部の下位32bitがdとcに跨っている
 10506:               xe <= LEN + 30 ? (int) (xc >>> ~xe) :  //95..122。xc>>>(32..5)。整数部の下位32bitがcに収まっている
 10507:               0);  //すべて整数部で下位32bitは0
 10508:     }  //efp.geti32abs(EFP)
 10509: 
 10510:     //------------------------------------------------------------------------
 10511:     //l = x.getl ()
 10512:     //  long値
 10513:     //
 10514:     //  丸めモードを省略したときは小数点以下を切り捨てる(RZ)
 10515:     //  2^63-1よりも大きい数は2^63-1に、-2^63よりも小さい数は-2^63に変換する(飽和変換)
 10516:     //  NaNは0に変換する
 10517:     //
 10518:     public long getl () {
 10519:       int xf = this.flg;
 10520:       if (xf << 1 != 0) {  //±0,±Inf,NaN
 10521:         if (xf << 1 < 0) {  //±0
 10522:           return 0L;
 10523:         } else if (xf << 2 < 0) {  //±Inf
 10524:           epbFpsr |= EPB_FPSR_OE;
 10525:           epbExceptionOperandExponent = xf & M | 0x7fff << 16;
 10526:           epbExceptionOperandMantissa = 0x0000000000000000L;
 10527:           return xf < 0 ? MSB : ~MSB;  //+Infは0x7fffffffffffffffL,-Infは0x8000000000000000L
 10528:         } else {  //NaN
 10529:           epbFpsr |= EPB_FPSR_OE;
 10530:           epbExceptionOperandExponent = 0x7fff << 16;
 10531:           epbExceptionOperandMantissa = 0xffffffffffffffffL;
 10532:           return 0L;  //NaNは0L
 10533:         }
 10534:       }
 10535:       //±0,±Inf,NaN以外
 10536:       int xe = this.epp;
 10537:       if (xe < 0) {  //0<|x|<1
 10538:         return 0L;
 10539:       }
 10540:       //1<=|x|
 10541:       if (xe < 63) {  //1<=|x|<2^63
 10542:         return xf >= 0 ? this.dvl >>> ~xe : -(this.dvl >>> ~xe);
 10543:       }
 10544:       //2^63<=|x|
 10545:       if (xf >= 0) {  //2^63<=x
 10546:         epbFpsr |= EPB_FPSR_OE;
 10547:         epbExceptionOperandExponent = 0x3fff + xe << 16;
 10548:         epbExceptionOperandMantissa = this.dvl;
 10549:         return 0x7fffffffffffffffL;
 10550:       }
 10551:       //x<=-2^63
 10552:       if (xe != 63 || this.dvl != MSB || this.cvl != 0L) {  //x!=-2^63
 10553:         epbFpsr |= EPB_FPSR_OE;
 10554:         epbExceptionOperandExponent = M | 0x3fff + xe << 16;
 10555:         epbExceptionOperandMantissa = this.dvl;
 10556:       }
 10557:       return 0x8000000000000000L;
 10558:     }  //efp.getl()
 10559:     public long getl (int roundingMode) {
 10560:       return (roundingMode == EPB_MODE_RN ? new EFP ().inner ().rint (this).outer ().getl () :
 10561:               roundingMode == EPB_MODE_RM ? new EFP ().inner ().floor (this).outer ().getl () :
 10562:               roundingMode == EPB_MODE_RP ? new EFP ().inner ().ceil (this).outer ().getl () :
 10563:               this.getl ());
 10564:     }  //efp.getl(int)
 10565: 
 10566:     //------------------------------------------------------------------------
 10567:     //x = x.getman ()
 10568:     //y = y.getman (x)
 10569:     //  仮数部
 10570:     //
 10571:     //  getman(±0)=±0, getman(±Inf)=NaN, getman(NaN)=NaN
 10572:     //
 10573:     public final EFP getman () {
 10574:       return this.getman (this);
 10575:     }  //efp.getman()
 10576:     public final EFP getman (EFP x) {
 10577:       int xf = x.flg;
 10578:       if (xf << 1 != 0) {  //±0,±Inf,NaN
 10579:         if (xf << 2 < 0) {  //±Inf
 10580:           epbFpsr |= EPB_FPSR_OE;
 10581:           epbExceptionOperandExponent = xf & M | 0x7fff << 16;
 10582:           epbExceptionOperandMantissa = 0x0000000000000000L;
 10583:           this.flg = N;  //getman(±Inf)=NaN
 10584:         } else {  //±0,NaN
 10585:           this.flg = xf;  //getman(±0)=±0, getman(NaN)=NaN
 10586:         }
 10587:         return this;
 10588:       }
 10589:       this.flg = xf;  //仮数部
 10590:       this.epp = 0;
 10591:       this.dvl = x.dvl;
 10592:       this.cvl = x.cvl;
 10593:       return this;
 10594:     }  //efp.getman(EFP)
 10595: 
 10596:     //------------------------------------------------------------------------
 10597:     //x.getp012 (b, a)
 10598:     //x.getp012 (b, a, k)
 10599:     //  packed値
 10600:     //
 10601:     //  0
 10602:     //    bit31     仮数部の符号(0=+,1=-)
 10603:     //    bit30     指数部の符号(0=+,1=-)
 10604:     //    bit29-28  ±Inf,NaNのときはすべて1、それ以外はすべて0
 10605:     //    bit27-16  指数部(BCD)、±0のときはすべて0、±Inf,NaNのときはすべて1
 10606:     //    bit15-12  出力するときは指数部の1000の位、入力するときは不定。±Infのときはすべて0にしておかないとFLOAT4.Xが誤動作する
 10607:     //    bit11-4   不定。±Infのときはすべて0にしておかないとFLOAT4.Xが誤動作する
 10608:     //    bit3-0    整数部(BCD)、±0,±Infのときはすべて0、NaNのときはすべて1
 10609:     //  12
 10610:     //    bit63-0   小数部(BCD)、±0,±Infのときはすべて0、NaNのときはすべて1、ただしSNaNのときはbit63だけ0
 10611:     //
 10612:     //  k-factor
 10613:     //    -64..0   -小数点以下の桁数(%f)。0ではない先頭の数字から小数点以下-k桁目までの桁数(1桁以上17桁以下)を有効桁数とする
 10614:     //      1..17  有効桁数(%e)
 10615:     //     18..63  OPERR
 10616:     //
 10617:     public void getp012 (byte[] b, int a) {
 10618:       getp012 (b, a, 17);
 10619:     }  //efp.getp012(byte[],int)
 10620:     public void getp012 (byte[] b, int a, int k) {
 10621:       k = k << -7 >> -7;  //下位7bitを符号拡張する
 10622:       int u;
 10623:       long v;
 10624:       int xf = this.flg;
 10625:       if (xf << 1 != 0) {  //±0,±Inf,NaN
 10626:         if (xf << 1 < 0) {  //±0
 10627:           u = xf & M;
 10628:           v = 0L;
 10629:         } else if (xf << 2 < 0) {  //±Inf
 10630:           u = (xf & M) | 0x7fff0000;
 10631:           v = 0L;
 10632:         } else {  //NaN
 10633:           u = 0x7fff0000;
 10634:           v = 0xffffffffffffffffL;
 10635:         }
 10636:       } else {  //±0,±Inf,NaN以外
 10637:         if (k > 17) {
 10638:           epbFpsr |= EPB_FPSR_OE;
 10639:           epbExceptionOperandExponent = this.flg & M | 0x3fff + this.epp << 16;
 10640:           epbExceptionOperandMantissa = this.dvl;
 10641:           k = 17;
 10642:         }
 10643:         //  2進数で仮数部が64桁のextendedは2^n*5^27を正確に表現できる
 10644:         //  10進数で仮数部が17桁のpackedは2^56*10^nを正確に表現できる
 10645:         //  どちらも正確に表現できる2^56*10^27=2^83*5^27のextendedとpackedの相互変換は誤差なしで行われなければならない
 10646:         //    2^56*10^27=72057594037927936000000000000000000000000000(44桁)
 10647:         //      extended  40900000CECB8F27F4200F3A
 10648:         //      packed    004300072057594037927936
 10649:         //  同様に2^56*10^34=2^90*5^34のtripleとpackedの相互変換は誤差なしで行われなければならない
 10650:         //    2^56*10^34=720575940379279360000000000000000000000000000000000(51桁)
 10651:         //      triple    40A7C732F684DF56C3E01BC6
 10652:         //      packed    005000072057594037927936
 10653:         int xe = this.epp;
 10654:         long xd = this.dvl;
 10655:         long xc = this.cvl;
 10656:         EFP x = new EFP (P, xe, xd, xc);  //絶対値のコピー
 10657:         int savedFpsr = epbFpsr;
 10658:         this.inner ();
 10659:         //10の指数を決める
 10660:         //  1.0*2^xe <= x < 2.0*2^xe
 10661:         //  1.0*10^(log10(2)*xe) <= x < 2.0*10^(log10(2)*xe)
 10662:         //  e=floor(log10(2)*xe)
 10663:         //  1.0*10^e <= x < 2.0*10^(e+1)
 10664:         //  1.0*10^e <= x < 20.0*10^e
 10665:         int e = (int) Math.floor (0.30102999566398119521373889472449302677 * xe);
 10666:         //整数部を0桁から20桁にする
 10667:         //  常に1桁まで割ってしまうとpackedで表現できる整数の処理中に端数が生じてX2がセットされてしまう
 10668:         if (e < 0) {  //10^-eを掛ける。結果は10^0<=x<2*10^1で整数部が1桁または2桁になる。誤差で0桁になる場合がある
 10669:           int o = -e;
 10670:           EFP t = new EFP (ONE);
 10671:           for (int i = 0; o != 0; i++, o >>>= 1) {
 10672:             if ((o & 1) != 0) {
 10673:               t.imul (EFP_TEN_POWER_P[i]);
 10674:             }
 10675:           }
 10676:           x.imul (t);
 10677:         } else if (e <= 18) {  //そのまま。10^0<=x<20*10^18で整数部は1桁から20桁
 10678:           e = 0;
 10679:         } else {  //10^(e-18)で割る。結果は10^18<=x<20*10^18で整数部が19桁または20桁になる。誤差で18桁になる場合がある
 10680:           int o = e -= 18;
 10681:           EFP t = new EFP (ONE);
 10682:           for (int i = 0; o != 0; i++, o >>>= 1) {
 10683:             if ((o & 1) != 0) {
 10684:               t.imul (EFP_TEN_POWER_P[i]);
 10685:             }
 10686:           }
 10687:           x.div (t);
 10688:         }
 10689:         //整数部を展開する
 10690:         //  最大65bitの整数を10000で割って16桁の商と4桁の余りに分けてそれぞれBCDに変換する
 10691:         //  20^10^18-1=0x1158E460913CFFFFF(65bit)
 10692:         u = 0;
 10693:         v = 0L;
 10694:         if (0 <= x.epp) {  //整数部が1..65bit
 10695:           //整数部をs,tに取り出す
 10696:           long s, t;
 10697:           if (x.epp <= 63) {  //1..64bit
 10698:             s = 0L;
 10699:             t = x.dvl >>> ~x.epp;
 10700:           } else {  //65bit
 10701:             s = 1L;  //最上位は1
 10702:             t = x.dvl << 1 | x.cvl >>> -1;
 10703:           }
 10704:           //最大65bitの整数を10000で割る
 10705:           long r = s << 32 | t >>> 32;  //上位の被除数
 10706:           s = r / 10000L;  //上位の商
 10707:           r = r - s * 10000L << 32 | t & 0xffffffffL;  //下位の被除数
 10708:           t = r / 10000L;  //下位の商
 10709:           v = XEiJ.FMT_BCD4[(int) (r - t * 10000L)];  //下位の余り→下位4桁
 10710:           t = XEiJ.fmtBcd16 (s << 32 | t);  //全体の商→上位16桁
 10711:           u = (int) (t >>> 48);
 10712:           v |= t << 16;
 10713:         }
 10714:         //小数部を展開する
 10715:         //  整数部が18桁以上になるまで小数部を10000倍して整数部を4桁のBCDに変換することを繰り返す
 10716:         while ((u & 0xfffffff0) == 0) {
 10717:           u = u << 16 | (int) (v >>> -16);
 10718:           v = v << 16 | XEiJ.FMT_BCD4[x.frac ().muli (10000).geti32abs ()];
 10719:           e -= 4;
 10720:         }
 10721:         long rest = x.frac ().iszero () ? 0L : 1L;  //k+2桁目以降の端数の有無
 10722:         this.outer ();
 10723:         epbFpsr = savedFpsr;
 10724:         //四捨五入する位を確認する
 10725:         //   lz(u)  >>>2  24-
 10726:         //  12..15     3   21
 10727:         //  16..19     4   20
 10728:         //  20..23     5   19
 10729:         //  24..27     6   18
 10730:         int w = 24 - (Integer.numberOfLeadingZeros (u) >>> 2);  //展開された桁数。18桁以上21桁以下
 10731:         //  w桁のBCD値がu:vの96bitに右寄せで格納されている
 10732:         //  値はw桁のBCD値*10^e
 10733:         if (k <= 0) {  //固定小数点形式のとき
 10734:           //  先頭の数字の左側は右からw桁の位置
 10735:           //  小数点は右から-e桁の位置
 10736:           //  小数点以下-k桁の数字の右側は右から-e+k桁の位置
 10737:           //  先頭から小数点以下-k桁までの桁数はw-(-e+k)桁
 10738:           k = Math.max (1, Math.min (17, w + e - k));
 10739:         }
 10740:         //k+2桁目以降の端数の有無を確認する
 10741:         int i = w - k - 1 << 2;  //k+1桁目の右から数えたbit位置
 10742:         if (0 < i) {  //k+2桁目が展開されている
 10743:           if (i < 64) {  //k+1桁目がvにある。k+2桁目以降はvの右端からvの途中まで
 10744:             long mask = -1L << i;
 10745:             rest |= v & ~mask;  //k+2桁目以降の端数の有無
 10746:             v &= mask;
 10747:           } else {  //k+1桁目がuにある。k+2桁目以降はvの全体のみまたはvの全体とuの右端から途中まで
 10748:             int mask = -1 << i - 64;
 10749:             rest |= (long) (u & ~mask) | v;  //k+2桁目以降の端数の有無
 10750:             u &= mask;
 10751:             v = 0L;
 10752:           }
 10753:         }
 10754:         //k+1桁目を四捨五入する
 10755:         int d = (i < 64 ? (int) (v >>> i) : u >>> i - 64) & 15;  //k+1桁目の数字
 10756:         if (d != 0 || rest != 0L) {  //k+1桁目以降に端数がある
 10757:           epbFpsr |= EPB_FPSR_X2;  //不正確な結果
 10758:           epbExceptionOperandExponent = xf & M | 0x3fff + xe << 16;
 10759:           epbExceptionOperandMantissa = xd;
 10760:           if (i < 64) {
 10761:             v &= ~(15L << i);
 10762:           } else {
 10763:             u &= ~(15 << i);
 10764:           }
 10765:           i += 4;  //k桁目の右から数えたbit位置
 10766:           if ((epbRoundingMode == EPB_MODE_RN &&
 10767:                (5 < d ||  //k+1桁目以降に端数があってRNでk+1桁目が5より大きいか、
 10768:                 (d == 5 && (rest != 0L ||  //k+1桁目が5でk+2桁目以降に端数があるか、
 10769:                             ((i < 64 ? (int) (v >>> i) : u >>> i - 64) & 1) != 0)))) ||  //k+1桁目が5でk+2桁目以降に端数がなくてk桁目が奇数または
 10770:               (epbRoundingMode == EPB_MODE_RM && xf < 0) ||  //k+1桁目以降に端数があってRMで負または
 10771:               (epbRoundingMode == EPB_MODE_RP && 0 <= xf)) {  //k+1桁目以降に端数があってRPで正のとき切り上げる
 10772:             //k桁目が9のとき0に変えて切り上げる
 10773:             //  切り上げたときk-1桁目が9のとき0に変えて切り上げる
 10774:             //    先頭に0があるので必ず止まる
 10775:             while (((i < 64 ? (int) (v >>> i) : u >>> i - 64) & 15) == 9) {
 10776:               if (i < 64) {
 10777:                 v &= ~(15L << i);
 10778:               } else {
 10779:                 u &= ~(15 << i);
 10780:               }
 10781:               i += 4;
 10782:             }
 10783:             //9でなければ1を加える
 10784:             //  先頭の0が1に変わって1桁増える場合がある
 10785:             if (i < 64) {
 10786:               v += 1L << i;
 10787:             } else {
 10788:               u += 1 << i;
 10789:             }
 10790:           }  //切り上げる
 10791:         }  //if 端数がある
 10792:         //小数点の位置を合わせる
 10793:         w = 7 - (Integer.numberOfLeadingZeros (u) >>> 2);  //四捨五入した後の多すぎる小数点以下の桁数
 10794:         e += 16 + w;
 10795:         i = w << 2;  //多すぎるbit数
 10796:         v = (long) u << -i | v >>> i;
 10797:         u >>>= i - 64;
 10798:         //指数部を展開する
 10799:         if (e < 0) {
 10800:           u |= 0x40000000;  //指数部の符号
 10801:           e = -e;
 10802:         }
 10803:         e = XEiJ.fmtBcd8 (e);
 10804:         if ((e & ~0xfff) != 0) {  //指数部が3桁に収まっていない
 10805:           epbFpsr |= EPB_FPSR_OE;
 10806:           epbExceptionOperandExponent = xf & M | 0x3fff + xe << 16;
 10807:           epbExceptionOperandMantissa = xd;
 10808:         }
 10809:         u |= (e & 0xfff) << 16 | (e & 0xf000);
 10810:         //符号を付ける
 10811:         u |= xf & M;  //仮数部の符号
 10812:       }
 10813:       b[a     ] = (byte) (u >> 24);
 10814:       b[a +  1] = (byte) (u >> 16);
 10815:       b[a +  2] = (byte) (u >>  8);
 10816:       b[a +  3] = (byte)  u;
 10817:       u = (int) (v >>> 32);
 10818:       b[a +  4] = (byte) (u >> 24);
 10819:       b[a +  5] = (byte) (u >> 16);
 10820:       b[a +  6] = (byte) (u >>  8);
 10821:       b[a +  7] = (byte)  u;
 10822:       u = (int)  v;
 10823:       b[a +  8] = (byte) (u >> 24);
 10824:       b[a +  9] = (byte) (u >> 16);
 10825:       b[a + 10] = (byte) (u >>  8);
 10826:       b[a + 11] = (byte)  u;
 10827:       return;
 10828:     }  //efp.getp012(byte[],int,int)
 10829: 
 10830:     //------------------------------------------------------------------------
 10831:     //i = x.gets ()
 10832:     //i = x.gets (roundingMode)
 10833:     //  short値
 10834:     //
 10835:     //  丸めモードを省略したときは小数点以下を切り捨てる(RZ)
 10836:     //  2^15-1よりも大きい数は2^15-1に、-2^15よりも小さい数は-2^15に変換する(飽和変換)
 10837:     //  NaNは-1に変換する
 10838:     //
 10839:     //  Javaのdoubleからshortへのキャストは飽和変換ではない(intに飽和変換してから下位16bitを取り出す)ことに注意
 10840:     //
 10841:     public int gets () {
 10842:       int xf = this.flg;
 10843:       if (xf << 1 != 0) {  //±0,±Inf,NaN
 10844:         if (xf << 1 < 0) {  //±0
 10845:           return 0;
 10846:         } else if (xf << 2 < 0) {  //±Inf
 10847:           epbFpsr |= EPB_FPSR_OE;
 10848:           epbExceptionOperandExponent = xf & M | 0x7fff << 16;
 10849:           epbExceptionOperandMantissa = 0x0000000000000000L;
 10850:           return xf >> 31 ^ 0x00007fff;  //+Infは0x00007fff,-Infは0xffff8000
 10851:         } else {  //NaN
 10852:           epbFpsr |= EPB_FPSR_OE | EPB_FPSR_AV;
 10853:           epbExceptionOperandExponent = 0x7fff << 16;
 10854:           epbExceptionOperandMantissa = 0xffffffffffffffffL;
 10855:           return -1;  //NaNは-1
 10856:         }
 10857:       }
 10858:       //±0,±Inf,NaN以外
 10859:       int xe = this.epp;
 10860:       long xd = this.dvl;
 10861:       long xc = this.cvl;
 10862:       if (xe < 0) {  //0<|x|<1
 10863:         if (false) {
 10864:           epbFpsr |= EPB_FPSR_X2;  //不正確な結果
 10865:           epbExceptionOperandExponent = xf | 0x3fff + xe << 16;
 10866:           epbExceptionOperandMantissa = xd;
 10867:         }
 10868:         return 0;
 10869:       }
 10870:       //1<=|x|
 10871:       if (xe < 15) {  //1<=|x|<2^15
 10872:         if (false) {
 10873:           if ((xd << 1 + xe | xc) != 0L) {  //端数がある
 10874:             epbFpsr |= EPB_FPSR_X2;  //不正確な結果
 10875:             epbExceptionOperandExponent = xf | 0x3fff + xe << 16;
 10876:             epbExceptionOperandMantissa = xd;
 10877:           }
 10878:         }
 10879:         return xf >= 0 ? (int) (xd >>> ~xe) : -(int) (xd >>> ~xe);
 10880:       }
 10881:       //2^15<=|x|
 10882:       if (xf >= 0) {  //2^15<=x
 10883:         epbFpsr |= EPB_FPSR_OE;
 10884:         epbExceptionOperandExponent = 0x3fff + xe << 16;
 10885:         epbExceptionOperandMantissa = xd;
 10886:         return 0x00007fff;
 10887:       }
 10888:       //x<=-2^15
 10889:       if (xe != 15 || xd != MSB || xc != 0L) {  //x!=-2^15
 10890:         epbFpsr |= EPB_FPSR_OE;
 10891:         epbExceptionOperandExponent = M | 0x3fff + xe << 16;
 10892:         epbExceptionOperandMantissa = this.dvl;
 10893:       }
 10894:       return 0xffff8000;
 10895:     }  //efp.gets()
 10896:     public int gets (int roundingMode) {
 10897:       return (roundingMode == EPB_MODE_RN ? new EFP ().inner ().rint (this).outer ().gets () :
 10898:               roundingMode == EPB_MODE_RM ? new EFP ().inner ().floor (this).outer ().gets () :
 10899:               roundingMode == EPB_MODE_RP ? new EFP ().inner ().ceil (this).outer ().gets () :
 10900:               new EFP ().inner ().trunc (this).outer ().gets ());
 10901:     }  //efp.gets(int)
 10902: 
 10903:     //------------------------------------------------------------------------
 10904:     //x.getx012 (b, a)
 10905:     //x.getx012 (b, a, roundingMode)
 10906:     //i = x.getx0 ()
 10907:     //i = x.getx0 (roundingMode)
 10908:     //l = x.getx12 ()
 10909:     //l = x.getx12 (roundingMode)
 10910:     //  extended値
 10911:     //
 10912:     //         0          1       2
 10913:     //    0x7fff0000,0xffffffffffffffffL  Non-Signaling NaN
 10914:     //    0x7fff0000,0xbfffffffffffffffL  Signaling NaN
 10915:     //    0x7fff0000,0x0000000000000000L  +Inf
 10916:     //    0x7ffe0000,0xffffffffffffffffL  2^16384-2^16320   = 1.1897314953572317650212638530309702052 E4932   正規化数の最大値
 10917:     //    0x3fff0000,0x8000000000000000L  2^0               = 1
 10918:     //    0x00000000,0x8000000000000000L  2^-16383          = 1.6810515715560467531313389086608763013 E-4932  正規化数の最小値
 10919:     //    0x00000000,0x7fffffffffffffffL  2^-16383-2^-16446 = 1.6810515715560467529490789320667525712 E-4932  非正規化数の最大値
 10920:     //    0x00000000,0x0000000000000001L  2^-16446          = 1.8225997659412373012642029668097099082 E-4951  非正規化数の最小値
 10921:     //    0x00000000,0x0000000000000000L  +0
 10922:     //    NaNの符号はDon't Care、出力は0
 10923:     //    NaNの整数部はDon't Care、出力は1
 10924:     //    Non-Signaling NaNの小数部の先頭は1
 10925:     //    Signaling NaNの小数部の先頭は0
 10926:     //      Signaling NaNが返ることはない
 10927:     //    NaNの小数部の先頭以外はNon-Zero、出力はすべて1
 10928:     //    ±Infの整数部はDon't Care、出力は0
 10929:     //    ±Infの小数部はすべて0
 10930:     //    正規化数の整数部は1
 10931:     //    非正規化数の整数部は0
 10932:     //
 10933:     //  メモ
 10934:     //    M68000PRMとMC68881UMにはextendedの正規化数の最大値と正規化数の最小値と非正規化数の最小値の記述が間違っているものがある
 10935:     //
 10936:     public void getx012 (byte[] b, int a) {
 10937:       this.getx012 (b, a, EPB_MODE_RN);
 10938:     }  //efp.getx012(byte[],int)
 10939:     public void getx012 (byte[] b, int a, int roundingMode) {
 10940:       int xf = this.flg;
 10941:       int xe = this.epp;  //正規化数は-16383<=xe<=16383、非正規化数は-16446<=xe<=-16384
 10942:       long xd = this.dvl;
 10943:       long xc = this.cvl;
 10944:     xfxd:
 10945:       {
 10946:         if (xf << 1 != 0) {  //±0,±Inf,NaN
 10947:           if (xf << 1 < 0) {  //±0
 10948:             xf &= M;  //符号部1bit、指数部15bit、空き16bit
 10949:             xd = 0x0000000000000000L;  //整数部1bit、小数部63bit
 10950:           } else if (xf << 2 < 0) {  //±Inf
 10951:             xf = (xf & M) | 0x7fff0000;  //符号部1bit、指数部15bit、空き16bit
 10952:             xd = 0x0000000000000000L;  //整数部1bit、小数部63bit
 10953:           } else {  //NaN
 10954:             xf = 0x7fff0000;  //符号部1bit、指数部15bit、空き16bit
 10955:             xd = 0xffffffffffffffffL;  //整数部1bit、小数部63bit
 10956:           }
 10957:           break xfxd;
 10958:         }
 10959:         //±0,±Inf,NaN以外
 10960:         if (xe < -16447) {  //指数部が小さすぎる。非正規化数の最小値は2^-16446だが丸めで繰り上がる場合があるので一旦2^-16447まで受け入れる
 10961:           epbFpsr |= EPB_FPSR_UF | EPB_FPSR_X2;  //アンダーフロー、不正確な結果
 10962:           epbExceptionOperandExponent = xf | 0x3fff + 0x6000 + xe << 16;
 10963:           epbExceptionOperandMantissa = xd;
 10964:           if (0 <= xf) {  //+x
 10965:             if (roundingMode == EPB_MODE_RP) {  //RPのとき+eps
 10966:               xf = 0x00000000;  //符号部1bit、指数部15bit、空き16bit
 10967:               xd = 0x0000000000000001L;  //整数部1bit、小数部63bit
 10968:             } else {  //RN,RZ,RMのとき+0
 10969:               xf = 0x00000000;  //符号部1bit、指数部15bit、空き16bit
 10970:               xd = 0x0000000000000000L;  //整数部1bit、小数部63bit
 10971:             }
 10972:           } else {  //-x
 10973:             if (roundingMode == EPB_MODE_RM) {  //RMのとき-eps
 10974:               xf = 0x80000000;  //符号部1bit、指数部15bit、空き16bit
 10975:               xd = 0x0000000000000001L;  //整数部1bit、小数部63bit
 10976:             } else {  //RN,RZ,RPのとき-0
 10977:               xf = 0x80000000;  //符号部1bit、指数部15bit、空き16bit
 10978:               xd = 0x0000000000000000L;  //整数部1bit、小数部63bit
 10979:             }
 10980:           }
 10981:           break xfxd;
 10982:         }
 10983:         if (16383 < xe) {  //指数部が大きすぎる
 10984:           if (true) {
 10985:             epbFpsr |= EPB_FPSR_OF;  //オーバーフロー
 10986:             if (xc != 0L) {  //端数が0ではない
 10987:               epbFpsr |= EPB_FPSR_X2;  //不正確な結果
 10988:             }
 10989:           } else {
 10990:             epbFpsr |= EPB_FPSR_OF | EPB_FPSR_X2;  //オーバーフロー、不正確な結果
 10991:           }
 10992:           epbExceptionOperandExponent = xf | 0x3fff - 0x6000 + xe << 16;
 10993:           epbExceptionOperandMantissa = xd;
 10994:           if (0 <= xf) {  //+x
 10995:             if (roundingMode == EPB_MODE_RM) {  //RMのとき+max
 10996:               xf = 0x7ffe0000;  //符号部1bit、指数部15bit、空き16bit
 10997:               xd = 0xffffffffffffffffL;  //整数部1bit、小数部63bit
 10998:             } else {  //RN,RZ,RPのとき+Inf
 10999:               xf = 0x7fff0000;  //符号部1bit、指数部15bit、空き16bit
 11000:               xd = 0x0000000000000000L;  //整数部1bit、小数部63bit
 11001:             }
 11002:           } else {  //-x
 11003:             if (roundingMode == EPB_MODE_RP) {  //RPのとき-max
 11004:               xf = 0xfffe0000;  //符号部1bit、指数部15bit、空き16bit
 11005:               xd = 0xffffffffffffffffL;  //整数部1bit、小数部63bit
 11006:             } else {  //RN,RZ,RMのとき-Inf
 11007:               xf = 0xffff0000;  //符号部1bit、指数部15bit、空き16bit
 11008:               xd = 0x0000000000000000L;  //整数部1bit、小数部63bit
 11009:             }
 11010:           }
 11011:           break xfxd;
 11012:         }
 11013:         long xb = 0L;
 11014:         int o = xe <= -16384 ? 0 + -16383 - xe : 0;  //右にずらすbit数。正規化数は0、非正規化数は0+1<=o<=0+64
 11015:         if (o == 0) {
 11016:         } else if (o < 64) {
 11017:           xb = xc << -o;
 11018:           xc = xd << -o | xc >>> o;
 11019:           xd >>>= o;
 11020:         } else {
 11021:           xb = xc;
 11022:           xc = xd;
 11023:           xd = 0L;
 11024:         }
 11025:         if ((xc | xb) != 0L) {  //端数が0ではない
 11026:           epbFpsr |= EPB_FPSR_X2;  //不正確な結果
 11027:           if (roundingMode == EPB_MODE_RN && xc < 0L && (xd << 63 | xc << 1 | xb) != 0L ||  //RNでguard bitが1かつLSBまたはguard bit以外の端数が0ではないまたは
 11028:               roundingMode == EPB_MODE_RM && xf < 0 ||  //端数が0ではなくてRMで-または
 11029:               roundingMode == EPB_MODE_RP && 0 <= xf) {  //端数が0ではなくてRPで+のとき
 11030:             xd++;  //繰り上げる
 11031:             if (xd == 0L) {  //繰り上がって溢れたとき
 11032:               xd = MSB;
 11033:               xe++;  //指数部をインクリメントする。ここでxe=16384になる場合がある
 11034:               if (16383 < xe) {  //指数部が大きすぎる
 11035:                 epbFpsr |= EPB_FPSR_OF | EPB_FPSR_X2;  //オーバーフロー、不正確な結果
 11036:                 epbExceptionOperandExponent = xf | 0x3fff - 0x6000 + xe << 16;
 11037:                 epbExceptionOperandMantissa = xd;
 11038:                 if (0 <= xf) {  //+x
 11039:                   if (roundingMode == EPB_MODE_RM) {  //RMのとき+max
 11040:                     xf = 0x7ffe0000;  //符号部1bit、指数部15bit、空き16bit
 11041:                     xd = 0xffffffffffffffffL;  //整数部1bit、小数部63bit
 11042:                   } else {  //RN,RZ,RPのとき+Inf
 11043:                     xf = 0x7fff0000;  //符号部1bit、指数部15bit、空き16bit
 11044:                     xd = 0x0000000000000000L;  //整数部1bit、小数部63bit
 11045:                   }
 11046:                 } else {  //-x
 11047:                   if (roundingMode == EPB_MODE_RP) {  //RPのとき-max
 11048:                     xf = 0xfffe0000;  //符号部1bit、指数部15bit、空き16bit
 11049:                     xd = 0xffffffffffffffffL;  //整数部1bit、小数部63bit
 11050:                   } else {  //RN,RZ,RMのとき-Inf
 11051:                     xf = 0xffff0000;  //符号部1bit、指数部15bit、空き16bit
 11052:                     xd = 0x0000000000000000L;  //整数部1bit、小数部63bit
 11053:                   }
 11054:                 }
 11055:                 break xfxd;
 11056:               }  //if 指数部が大きすぎる
 11057:             } else if (0 < o) {  //非正規化数のとき
 11058:               if (xd << o - 1 < 0L) {  //1bit増えたとき
 11059:                 xe++;  //指数部をインクリメントする
 11060: /* getx012
 11061:                 if (xe == -16383) {  //非正規化数が繰り上がって正規化数になったとき
 11062:                   //xd = 1L << 15;
 11063:                   epbFpsr |= EPB_FPSR_UF | EPB_FPSR_X2;  //アンダーフロー、不正確な結果
 11064:                   epbExceptionOperandExponent = xf | 0x3fff + 0x6000 + xe << 16;
 11065:                   epbExceptionOperandMantissa = xd;
 11066:                 }
 11067: */
 11068:               }
 11069:             }
 11070:           }
 11071:           //RZ toward zeroのときは端数を切り捨てるだけなので何もしなくてよい
 11072:           if (xe <= -16384) {  //非正規化数
 11073:             epbFpsr |= EPB_FPSR_UF | EPB_FPSR_X2;  //アンダーフロー、不正確な結果
 11074:             epbExceptionOperandExponent = xf | 0x3fff + 0x6000 + xe << 16;
 11075:             epbExceptionOperandMantissa = xd;
 11076:             if (xd == 0L) {  //非正規化数でxe==-16447だったとき、先頭の1がxcにあって丸めで繰り上がらなかった
 11077:               if (0 <= xf) {  //+x
 11078:                 if (roundingMode == EPB_MODE_RP) {  //RPのとき+eps
 11079:                   xf = 0x00000000;  //符号部1bit、指数部15bit、空き16bit
 11080:                   xd = 0x0000000000000001L;  //整数部1bit、小数部63bit
 11081:                 } else {  //RN,RZ,RMのとき+0
 11082:                   xf = 0x00000000;  //符号部1bit、指数部15bit、空き16bit
 11083:                   xd = 0x0000000000000000L;  //整数部1bit、小数部63bit
 11084:                 }
 11085:               } else {  //-x
 11086:                 if (roundingMode == EPB_MODE_RM) {  //RMのとき-eps
 11087:                   xf = 0x80000000;  //符号部1bit、指数部15bit、空き16bit
 11088:                   xd = 0x0000000000000001L;  //整数部1bit、小数部63bit
 11089:                 } else {  //RN,RZ,RPのとき-0
 11090:                   xf = 0x80000000;  //符号部1bit、指数部15bit、空き16bit
 11091:                   xd = 0x0000000000000000L;  //整数部1bit、小数部63bit
 11092:                 }
 11093:               }
 11094:               break xfxd;
 11095:             }
 11096:           }  //if 非正規化数
 11097:         } else {  //端数が0
 11098:           if (xe <= -16384) {  //非正規化数
 11099:             epbFpsr |= EPB_FPSR_UF;  //アンダーフロー
 11100:             epbExceptionOperandExponent = xf | 0x3fff + 0x6000 + xe << 16;
 11101:             epbExceptionOperandMantissa = xd;
 11102:             if (xd == 0L) {  //非正規化数でxe==-16447だったとき、先頭の1がxcにあって丸めで繰り上がらなかった
 11103:               if (0 <= xf) {  //+x
 11104:                 if (roundingMode == EPB_MODE_RP) {  //RPのとき+eps
 11105:                   xf = 0x00000000;  //符号部1bit、指数部15bit、空き16bit
 11106:                   xd = 0x0000000000000001L;  //整数部1bit、小数部63bit
 11107:                 } else {  //RN,RZ,RMのとき+0
 11108:                   xf = 0x00000000;  //符号部1bit、指数部15bit、空き16bit
 11109:                   xd = 0x0000000000000000L;  //整数部1bit、小数部63bit
 11110:                 }
 11111:               } else {  //-x
 11112:                 if (roundingMode == EPB_MODE_RM) {  //RMのとき-eps
 11113:                   xf = 0x80000000;  //符号部1bit、指数部15bit、空き16bit
 11114:                   xd = 0x0000000000000001L;  //整数部1bit、小数部63bit
 11115:                 } else {  //RN,RZ,RPのとき-0
 11116:                   xf = 0x80000000;  //符号部1bit、指数部15bit、空き16bit
 11117:                   xd = 0x0000000000000000L;  //整数部1bit、小数部63bit
 11118:                 }
 11119:               }
 11120:               break xfxd;
 11121:             }
 11122:           }  //if 非正規化数
 11123:         }  //if 端数が0ではない/端数が0
 11124:         xf |= Math.max (0, 16383 + xe) << 16;  //符号とバイアスを加えた指数部
 11125:       }  //xfxd
 11126:       //結果
 11127:       b[a     ] = (byte) (xf >> 24);
 11128:       b[a +  1] = (byte) (xf >> 16);
 11129:       b[a +  2] = 0;
 11130:       b[a +  3] = 0;
 11131:       xf = (int) (xd >>> 32);
 11132:       b[a +  4] = (byte) (xf >> 24);
 11133:       b[a +  5] = (byte) (xf >> 16);
 11134:       b[a +  6] = (byte) (xf >>  8);
 11135:       b[a +  7] = (byte)  xf;
 11136:       xf = (int)  xd;
 11137:       b[a +  8] = (byte) (xf >> 24);
 11138:       b[a +  9] = (byte) (xf >> 16);
 11139:       b[a + 10] = (byte) (xf >>  8);
 11140:       b[a + 11] = (byte)  xf;
 11141:       return;
 11142:     }  //efp.getx012(byte[],int,int)
 11143:     public int getx0 () {
 11144:       byte[] b = new byte[12];
 11145:       this.getx012 (b, 0, EPB_MODE_RN);
 11146:       return b[0] << 24 | (b[1] & 255) << 16 | (char) (b[2] << 8 | b[3] & 255);
 11147:     }  //efp.getx0()
 11148:     public int getx0 (int roundingMode) {
 11149:       byte[] b = new byte[12];
 11150:       this.getx012 (b, 0, roundingMode);
 11151:       return b[0] << 24 | (b[1] & 255) << 16 | (char) (b[2] << 8 | b[3] & 255);
 11152:     }  //efp.getx0(int)
 11153:     public long getx12 () {
 11154:       byte[] b = new byte[12];
 11155:       this.getx012 (b, 0, EPB_MODE_RN);
 11156:       return ((long) (b[4] << 24 | (b[5] & 255) << 16 | (char) (b[ 6] << 8 | b[ 7] & 255)) << 32 |
 11157:               (long) (b[8] << 24 | (b[9] & 255) << 16 | (char) (b[10] << 8 | b[11] & 255)) & 0xffffffffL);
 11158:     }  //efp.getx12()
 11159:     public long getx12 (int roundingMode) {
 11160:       byte[] b = new byte[12];
 11161:       this.getx012 (b, 0, roundingMode);
 11162:       return ((long) (b[4] << 24 | (b[5] & 255) << 16 | (char) (b[ 6] << 8 | b[ 7] & 255)) << 32 |
 11163:               (long) (b[8] << 24 | (b[9] & 255) << 16 | (char) (b[10] << 8 | b[11] & 255)) & 0xffffffffL);
 11164:     }  //efp.getx12(int)
 11165: 
 11166:     //------------------------------------------------------------------------
 11167:     //x.gety012 (b, a)
 11168:     //x.gety012 (b, a, roundingMode)
 11169:     //i = x.gety0 ()
 11170:     //i = x.gety0 (roundingMode)
 11171:     //l = x.gety12 ()
 11172:     //l = x.gety12 (roundingMode)
 11173:     //  triple値
 11174:     //
 11175:     //         0          1       2
 11176:     //    0x7fffffff,0xffffffffffffffffL  Non-Signaling NaN
 11177:     //    0x7fffffff,0xbfffffffffffffffL  Signaling NaN
 11178:     //    0x7fff0000,0x0000000000000000L  +Inf
 11179:     //    0x7ffeffff,0xffffffffffffffffL  2^16384-2^16304   = 1.1897314953572317650857583425051800275 E4932   正規化数の最大値
 11180:     //    0x3fff0000,0x8000000000000000L  2^0               = 1
 11181:     //    0x00000000,0x8000000000000000L  2^-16383          = 1.6810515715560467531313389086608763013 E-4932  正規化数の最小値
 11182:     //    0x0000ffff,0x7fffffffffffffffL  2^-16383-2^-16462 = 1.6810515715560467531313361275943389154 E-4932  非正規化数の最大値
 11183:     //    0x00000001,0x0000000000000000L  2^-16462          = 2.7810665373859211750247237652736052066 E-4956  非正規化数の最小値
 11184:     //    0x00000000,0x0000000000000000L  +0
 11185:     //    NaNの符号はDon't Care、出力は0
 11186:     //    NaNの整数部はDon't Care、出力は1
 11187:     //    Non-Signaling NaNの小数部の先頭は1
 11188:     //    Signaling NaNの小数部の先頭は0
 11189:     //      Signaling NaNが返ることはない
 11190:     //    NaNの小数部の先頭以外はNon-Zero、出力はすべて1
 11191:     //    ±Infの整数部はDon't Care、出力は0
 11192:     //    ±Infの小数部はすべて0
 11193:     //    正規化数の整数部は1
 11194:     //    非正規化数の整数部は0
 11195:     //
 11196:     public void gety012 (byte[] b, int a) {
 11197:       this.gety012 (b, a, EPB_MODE_RN);
 11198:     }  //efp.gety012(byte[],int)
 11199:     public void gety012 (byte[] b, int a, int roundingMode) {
 11200:       int xf = this.flg;
 11201:       int xe = this.epp;  //正規化数は-16383<=xe<=16383、非正規化数は-16462<=xe<=-16384
 11202:       long xd = this.dvl;
 11203:       long xc = this.cvl;
 11204:     xfxd:
 11205:       {
 11206:         if (xf << 1 != 0) {  //±0,±Inf,NaN
 11207:           if (xf << 1 < 0) {  //±0
 11208:             xf &= M;  //符号部1bit、指数部15bit、小数部の下位16bit
 11209:             xd = 0x0000000000000000L;  //整数部1bit、小数部の上位63bit
 11210:           } else if (xf << 2 < 0) {  //±Inf
 11211:             xf = (xf & M) | 0x7fff0000;  //符号部1bit、指数部15bit、小数部の下位16bit
 11212:             xd = 0x0000000000000000L;  //整数部1bit、小数部の上位63bit
 11213:           } else {  //NaN
 11214:             xf = 0x7fffffff;  //符号部1bit、指数部15bit、小数部の下位16bit
 11215:             xd = 0xffffffffffffffffL;  //整数部1bit、小数部の上位63bit
 11216:           }
 11217:           break xfxd;
 11218:         }
 11219:         //±0,±Inf,NaN以外
 11220:         if (xe < -16463) {  //指数部が小さすぎる。非正規化数の最小値は2^-16462だが丸めで繰り上がる場合があるので一旦2^-16463まで受け入れる
 11221:           epbFpsr |= EPB_FPSR_UF | EPB_FPSR_X2;  //アンダーフロー、不正確な結果
 11222:           epbExceptionOperandExponent = xf | 0x3fff + 0x6000 + xe << 16;
 11223:           epbExceptionOperandMantissa = xd;
 11224:           if (0 <= xf) {  //+x
 11225:             if (roundingMode == EPB_MODE_RP) {  //RPのとき+eps
 11226:               xf = 0x00000001;  //符号部1bit、指数部15bit、小数部の下位16bit
 11227:               xd = 0x0000000000000000L;  //整数部1bit、小数部の上位63bit
 11228:             } else {  //RN,RZ,RMのとき+0
 11229:               xf = 0x00000000;  //符号部1bit、指数部15bit、小数部の下位16bit
 11230:               xd = 0x0000000000000000L;  //整数部1bit、小数部の上位63bit
 11231:             }
 11232:           } else {  //-x
 11233:             if (roundingMode == EPB_MODE_RM) {  //RMのとき-eps
 11234:               xf = 0x80000001;  //符号部1bit、指数部15bit、小数部の下位16bit
 11235:               xd = 0x0000000000000000L;  //整数部1bit、小数部の上位63bit
 11236:             } else {  //RN,RZ,RPのとき-0
 11237:               xf = 0x80000000;  //符号部1bit、指数部15bit、小数部の下位16bit
 11238:               xd = 0x0000000000000000L;  //整数部1bit、小数部の上位63bit
 11239:             }
 11240:           }
 11241:           break xfxd;
 11242:         }
 11243:         if (16383 < xe) {  //指数部が大きすぎる
 11244:           if (true) {
 11245:             epbFpsr |= EPB_FPSR_OF;  //オーバーフロー
 11246:             if (xc << 16 != 0L) {  //端数が0ではない
 11247:               epbFpsr |= EPB_FPSR_X2;  //不正確な結果
 11248:             }
 11249:           } else {
 11250:             epbFpsr |= EPB_FPSR_OF | EPB_FPSR_X2;  //オーバーフロー、不正確な結果
 11251:           }
 11252:           epbExceptionOperandExponent = xf | 0x3fff - 0x6000 + xe << 16;
 11253:           epbExceptionOperandMantissa = xd;
 11254:           if (0 <= xf) {  //+x
 11255:             if (roundingMode == EPB_MODE_RM) {  //RMのとき+max
 11256:               xf = 0x7ffeffff;  //符号部1bit、指数部15bit、小数部の下位16bit
 11257:               xd = 0xffffffffffffffffL;  //整数部1bit、小数部の上位63bit
 11258:             } else {  //RN,RZ,RPのとき+Inf
 11259:               xf = 0x7fff0000;  //符号部1bit、指数部15bit、小数部の下位16bit
 11260:               xd = 0x0000000000000000L;  //整数部1bit、小数部の上位63bit
 11261:             }
 11262:           } else {  //-x
 11263:             if (roundingMode == EPB_MODE_RP) {  //RPのとき-max
 11264:               xf = 0xfffeffff;  //符号部1bit、指数部15bit、小数部の下位16bit
 11265:               xd = 0xffffffffffffffffL;  //整数部1bit、小数部の上位63bit
 11266:             } else {  //RN,RZ,RMのとき-Inf
 11267:               xf = 0xffff0000;  //符号部1bit、指数部15bit、小数部の下位16bit
 11268:               xd = 0x0000000000000000L;  //整数部1bit、小数部の上位63bit
 11269:             }
 11270:           }
 11271:           break xfxd;
 11272:         }
 11273:         long xb = 0L;
 11274:         long xa = 0L;
 11275:         int o = xe <= -16384 ? 48 + -16383 - xe : 48;  //右にずらすbit数。正規化数は48、非正規化数は48+1<=o<=48+80
 11276:         if (o < 64) {
 11277:           xb = xc << -o;
 11278:           xc = xd << -o | xc >>> o;
 11279:           xd >>>= o;
 11280:         } else if (o == 64) {
 11281:           xb = xc;
 11282:           xc = xd;
 11283:           xd = 0L;
 11284:         } else if (o < 128) {
 11285:           xa = xc << -o;
 11286:           xb = xd << -o | xc >>> o;
 11287:           xc = xd >>> o;
 11288:           xd = 0L;
 11289:         } else {
 11290:           xa = xc;
 11291:           xb = xd;
 11292:           xc = 0L;
 11293:           xd = 0L;
 11294:         }
 11295:         if ((xb | xa) != 0L) {  //端数が0ではない
 11296:           epbFpsr |= EPB_FPSR_X2;  //不正確な結果
 11297:           if (roundingMode == EPB_MODE_RN && xb < 0L && (xc << 63 | xb << 1 | xa) != 0L ||  //RNでguard bitが1かつLSBまたはguard bit以外の端数が0ではないまたは
 11298:               roundingMode == EPB_MODE_RM && xf < 0 ||  //端数が0ではなくてRMで-または
 11299:               roundingMode == EPB_MODE_RP && 0 <= xf) {  //端数が0ではなくてRPで+のとき
 11300:             xc++;  //繰り上げる
 11301:             if (xc == 0L) {  //繰り上がって溢れたとき
 11302:               xd++;  //繰り上げる
 11303:               if (xd >>> 16 != 0L) {  //繰り上がって溢れたとき
 11304:                 //xd = 1L << 15;
 11305:                 xe++;  //指数部をインクリメントする。ここでxe=16384になる場合がある
 11306:                 if (16383 < xe) {  //指数部が大きすぎる
 11307:                   epbFpsr |= EPB_FPSR_OF | EPB_FPSR_X2;  //オーバーフロー、不正確な結果
 11308:                   epbExceptionOperandExponent = xf | 0x3fff - 0x6000 + xe << 16;
 11309:                   epbExceptionOperandMantissa = xd;
 11310:                   if (0 <= xf) {  //+x
 11311:                     if (roundingMode == EPB_MODE_RM) {  //RMのとき+max
 11312:                       xf = 0x7ffeffff;  //符号部1bit、指数部15bit、小数部の下位16bit
 11313:                       xd = 0xffffffffffffffffL;  //整数部1bit、小数部の上位63bit
 11314:                     } else {  //RN,RZ,RPのとき+Inf
 11315:                       xf = 0x7fff0000;  //符号部1bit、指数部15bit、小数部の下位16bit
 11316:                       xd = 0x0000000000000000L;  //整数部1bit、小数部の上位63bit
 11317:                     }
 11318:                   } else {  //-x
 11319:                     if (roundingMode == EPB_MODE_RP) {  //RPのとき-max
 11320:                       xf = 0xfffeffff;  //符号部1bit、指数部15bit、小数部の下位16bit
 11321:                       xd = 0xffffffffffffffffL;  //整数部1bit、小数部の上位63bit
 11322:                     } else {  //RN,RZ,RMのとき-Inf
 11323:                       xf = 0xffff0000;  //符号部1bit、指数部15bit、小数部の下位16bit
 11324:                       xd = 0x0000000000000000L;  //整数部1bit、小数部の上位63bit
 11325:                     }
 11326:                   }
 11327:                   break xfxd;
 11328:                 }  //if 指数部が大きすぎる
 11329:               } else if (48 < o) {  //非正規化数のとき
 11330:                 if (xd << o - 1 < 0L) {  //1bit増えたとき
 11331:                   xe++;  //指数部をインクリメントする
 11332: /* gety012
 11333:                   if (xe == -16383) {  //非正規化数が繰り上がって正規化数になったとき
 11334:                     //xd = 1L << 15;
 11335:                     epbFpsr |= EPB_FPSR_UF | EPB_FPSR_X2;  //アンダーフロー、不正確な結果
 11336:                     epbExceptionOperandExponent = xf | 0x3fff + 0x6000 + xe << 16;
 11337:                     epbExceptionOperandMantissa = xd;
 11338:                   }
 11339: */
 11340:                 }
 11341:               }
 11342:             }
 11343:           }
 11344:           //RZ toward zeroのときは端数を切り捨てるだけなので何もしなくてよい
 11345:           if (xe <= -16384) {  //非正規化数
 11346:             epbFpsr |= EPB_FPSR_UF | EPB_FPSR_X2;  //アンダーフロー、不正確な結果
 11347:             epbExceptionOperandExponent = xf | 0x3fff + 0x6000 + xe << 16;
 11348:             epbExceptionOperandMantissa = xd;
 11349:             if ((xd | xc) == 0L) {  //非正規化数でxe==-16463だったとき、先頭の1がxbにあって丸めで繰り上がらなかった
 11350:               if (0 <= xf) {  //+x
 11351:                 if (roundingMode == EPB_MODE_RP) {  //RPのとき+eps
 11352:                   xf = 0x00000001;  //符号部1bit、指数部15bit、小数部の下位16bit
 11353:                   xd = 0x0000000000000000L;  //整数部1bit、小数部の上位63bit
 11354:                 } else {  //RN,RZ,RMのとき+0
 11355:                   xf = 0x00000000;  //符号部1bit、指数部15bit、小数部の下位16bit
 11356:                   xd = 0x0000000000000000L;  //整数部1bit、小数部の上位63bit
 11357:                 }
 11358:               } else {  //-x
 11359:                 if (roundingMode == EPB_MODE_RM) {  //RMのとき-eps
 11360:                   xf = 0x80000001;  //符号部1bit、指数部15bit、小数部の下位16bit
 11361:                   xd = 0x0000000000000000L;  //整数部1bit、小数部の上位63bit
 11362:                 } else {  //RN,RZ,RPのとき-0
 11363:                   xf = 0x80000000;  //符号部1bit、指数部15bit、小数部の下位16bit
 11364:                   xd = 0x0000000000000000L;  //整数部1bit、小数部の上位63bit
 11365:                 }
 11366:               }
 11367:               break xfxd;
 11368:             }
 11369:           }  //if 非正規化数
 11370:         } else {  //端数が0
 11371:           if (xe <= -16384) {  //非正規化数
 11372:             epbFpsr |= EPB_FPSR_UF;  //アンダーフロー
 11373:             epbExceptionOperandExponent = xf | 0x3fff + 0x6000 + xe << 16;
 11374:             epbExceptionOperandMantissa = xd;
 11375:             if ((xd | xc) == 0L) {  //非正規化数でxe==-16463だったとき、先頭の1がxbにあって丸めで繰り上がらなかった
 11376:               if (0 <= xf) {  //+x
 11377:                 if (roundingMode == EPB_MODE_RP) {  //RPのとき+eps
 11378:                   xf = 0x00000001;  //符号部1bit、指数部15bit、小数部の下位16bit
 11379:                   xd = 0x0000000000000000L;  //整数部1bit、小数部の上位63bit
 11380:                 } else {  //RN,RZ,RMのとき+0
 11381:                   xf = 0x00000000;  //符号部1bit、指数部15bit、小数部の下位16bit
 11382:                   xd = 0x0000000000000000L;  //整数部1bit、小数部の上位63bit
 11383:                 }
 11384:               } else {  //-x
 11385:                 if (roundingMode == EPB_MODE_RM) {  //RMのとき-eps
 11386:                   xf = 0x80000001;  //符号部1bit、指数部15bit、小数部の下位16bit
 11387:                   xd = 0x0000000000000000L;  //整数部1bit、小数部の上位63bit
 11388:                 } else {  //RN,RZ,RPのとき-0
 11389:                   xf = 0x80000000;  //符号部1bit、指数部15bit、小数部の下位16bit
 11390:                   xd = 0x0000000000000000L;  //整数部1bit、小数部の上位63bit
 11391:                 }
 11392:               }
 11393:               break xfxd;
 11394:             }
 11395:           }  //if 非正規化数
 11396:         }  //if 端数が0ではない/端数が0
 11397:         xd = xd << 48 | xc >>> -48;
 11398:         xc <<= 48;
 11399:         xf |= Math.max (0, 16383 + xe) << 16;  //符号とバイアスを加えた指数部
 11400:       }  //xfxd
 11401:       //結果
 11402:       b[a     ] = (byte) (xf >> 24);
 11403:       b[a +  1] = (byte) (xf >> 16);
 11404:       xf = (int) (xc >>> 48);
 11405:       b[a +  2] = (byte) (xf >>  8);
 11406:       b[a +  3] = (byte)  xf;
 11407:       xf = (int) (xd >>> 32);
 11408:       b[a +  4] = (byte) (xf >> 24);
 11409:       b[a +  5] = (byte) (xf >> 16);
 11410:       b[a +  6] = (byte) (xf >>  8);
 11411:       b[a +  7] = (byte)  xf;
 11412:       xf = (int)  xd;
 11413:       b[a +  8] = (byte) (xf >> 24);
 11414:       b[a +  9] = (byte) (xf >> 16);
 11415:       b[a + 10] = (byte) (xf >>  8);
 11416:       b[a + 11] = (byte)  xf;
 11417:       return;
 11418:     }  //efp.gety012(byte[],int,int)
 11419:     public int gety0 () {
 11420:       byte[] b = new byte[12];
 11421:       this.gety012 (b, 0, EPB_MODE_RN);
 11422:       return b[0] << 24 | (b[1] & 255) << 16 | (char) (b[2] << 8 | b[3] & 255);
 11423:     }  //efp.gety0()
 11424:     public int gety0 (int roundingMode) {
 11425:       byte[] b = new byte[12];
 11426:       this.gety012 (b, 0, roundingMode);
 11427:       return b[0] << 24 | (b[1] & 255) << 16 | (char) (b[2] << 8 | b[3] & 255);
 11428:     }  //efp.gety0(int)
 11429:     public long gety12 () {
 11430:       byte[] b = new byte[12];
 11431:       this.gety012 (b, 0, EPB_MODE_RN);
 11432:       return ((long) (b[4] << 24 | (b[5] & 255) << 16 | (char) (b[ 6] << 8 | b[ 7] & 255)) << 32 |
 11433:               (long) (b[8] << 24 | (b[9] & 255) << 16 | (char) (b[10] << 8 | b[11] & 255)) & 0xffffffffL);
 11434:     }  //efp.gety12()
 11435:     public long gety12 (int roundingMode) {
 11436:       byte[] b = new byte[12];
 11437:       this.gety012 (b, 0, roundingMode);
 11438:       return ((long) (b[4] << 24 | (b[5] & 255) << 16 | (char) (b[ 6] << 8 | b[ 7] & 255)) << 32 |
 11439:               (long) (b[8] << 24 | (b[9] & 255) << 16 | (char) (b[10] << 8 | b[11] & 255)) & 0xffffffffL);
 11440:     }  //efp.gety12(int)
 11441: 
 11442:     //------------------------------------------------------------------------
 11443:     //b = x.gt (y)
 11444:     //  b=x>y
 11445:     //  より大きいか
 11446:     //
 11447:     //  -Inf==-Inf<-x<-0==+0<+x<+Inf==+Inf
 11448:     //
 11449:     //  NaNの扱い
 11450:     //    どちらかがNaNのときはfalseを返す
 11451:     //
 11452:     public boolean gt (EFP y) {
 11453:       int xf = this.flg;
 11454:       int yf = y.flg;
 11455:       if ((xf | yf) << 1 != 0) {  //どちらかが±0,±Inf,NaN
 11456:         return EFP_GT_TABLE[xf >>> 28] << (yf >>> 28 - 1) < 0;
 11457:       }
 11458:       //両方±0,±Inf,NaN以外
 11459:       if (xf != yf) {  //両方±0,±Inf,NaN以外で符号が違う
 11460:         return xf > yf;
 11461:       }
 11462:       //両方±0,±Inf,NaN以外で符号が同じ
 11463:       int s;
 11464:       long t;
 11465:       return (xf >= 0 ? 1 : -1) * ((s = this.epp - y.epp) != 0 ? s >= 0 ? 1 : -1 :
 11466:                                    (t = this.dvl - y.dvl) != 0L ? t >= 0L ? 1 : -1 :
 11467:                                    (t = (this.cvl >>> 1) - (y.cvl >>> 1)) != 0L ? t >= 0L ? 1 : -1 :
 11468:                                    0) > 0;
 11469:     }  //efp.gt(EFP)
 11470: 
 11471:     //------------------------------------------------------------------------
 11472:     //i = x.hashCode ()
 11473:     //  ハッシュコード
 11474:     //
 11475:     //  equalsであるオブジェクトはhashCodeが同じでなければならない
 11476:     //  equalsでないオブジェクトはhashCodeがなるべく違う方がよい
 11477:     //
 11478:     public int hashCode () {
 11479:       return (this.flg ^
 11480:               this.epp ^
 11481:               (int) (this.dvl >> 32) ^
 11482:               (int) this.dvl ^
 11483:               (int) (this.cvl >> 32));
 11484:     }  //efp.hashCode()
 11485: 
 11486:     //------------------------------------------------------------------------
 11487:     //x = x.ieeerem (y)
 11488:     //  x=IEEEremainder(x,y)
 11489:     //z = z.ieeerem (x, y)
 11490:     //  z=IEEEremainder(x,y)
 11491:     //  剰余(round-to-nearest)
 11492:     //
 11493:     //  JavaのMath.IEEEremainder(x,y)と同じ
 11494:     //  IEEEremainder(x,y)=isNaN(x)||isNaN(y)||isInfinite(x)?NaN:isInfinite(y)?x:x-rint(x/y)*y
 11495:     //  被除数から最も近い除数の倍数を引いた結果を返す
 11496:     //  倍数の符号は任意なので除数の符号は結果に影響しない
 11497:     //    IEEEremainder ( 5.0,  3.0) ==  5.0 - rint ( 5.0 /  3.0) *  3.0 == -1.0
 11498:     //    IEEEremainder ( 5.0, -3.0) ==  5.0 - rint ( 5.0 / -3.0) * -3.0 == -1.0
 11499:     //    IEEEremainder (-5.0,  3.0) == -5.0 - rint (-5.0 /  3.0) *  3.0 ==  1.0
 11500:     //    IEEEremainder (-5.0, -3.0) == -5.0 - rint (-5.0 / -3.0) * -3.0 ==  1.0
 11501:     //
 11502:     public final EFP ieeerem (EFP y) {
 11503:       return this.ieeerem (this, y);
 11504:     }  //efp.ieeerem(EFP)
 11505:     public final EFP ieeerem (EFP x, EFP y) {
 11506:       int xf = x.flg;
 11507:       int yf = y.flg;
 11508:       epbFpsr &= 0xff00ffff;  //quotient byteをクリアする
 11509:       if ((xf | yf) << 1 != 0) {  //どちらかが±0,±Inf,NaN
 11510:         if ((xf | yf) << 3 < 0) {  //ieeerem(NaN,y)=NaN, ieeerem(x,NaN)=NaN
 11511:           this.flg = N;
 11512:         } else if (xf << 2 < 0 ||  //ieeerem(±Inf,y)=NaN
 11513:                    yf << 1 < 0) {  //ieeerem(x,±0)=NaN
 11514:           //除数が±0でもゼロ除算にはならない
 11515:           epbFpsr |= EPB_FPSR_OE;
 11516:           if (yf << 1 < 0) {  //±0
 11517:             epbExceptionOperandExponent = yf & M;
 11518:             epbExceptionOperandMantissa = 0x0000000000000000L;
 11519:           } else if (yf << 2 < 0) {  //±Inf
 11520:             epbExceptionOperandExponent = yf & M | 0x7fff << 16;
 11521:             epbExceptionOperandMantissa = 0x0000000000000000L;
 11522:           } else {  //±y
 11523:             epbExceptionOperandExponent = yf & M | 0x3fff + y.epp << 16;
 11524:             epbExceptionOperandMantissa = y.dvl;
 11525:           }
 11526:           this.flg = N;
 11527:         } else if (xf << 1 < 0) {  //ieeerem(±0,y)=±0
 11528:           epbFpsr |= ((xf ^ yf) & M) >>> 8;  //quotient byteに商の符号を入れる
 11529:           this.flg = xf;
 11530:         } else {  //ieeerem(x,±Inf)=x
 11531:           epbFpsr |= ((xf ^ yf) & M) >>> 8;  //quotient byteに商の符号を入れる
 11532:           this.finish (xf, x.epp, x.dvl, x.cvl, 0L);  //xが非正規化数のときUFをセットする
 11533:         }
 11534:         return this;
 11535:       }
 11536:       //両方±0,±Inf,NaN以外
 11537:       epbFpsr |= ((xf ^ yf) & M) >>> 8;  //quotient byteに商の符号を入れる
 11538:       if (false) {
 11539:         this.inner ();
 11540:         //this.sub (x, new EFP ().div (x, y).rint ().imul (y));  //x-rint(x/y)*y。this==x||this==yの場合に注意
 11541:         EFP q = new EFP ().quo (x, y);  //商
 11542:         int qi = q.geti32abs ();  //商の絶対値の下位32bit
 11543:         EFP w = new EFP ();
 11544:         this.imulw (w, q, y).negsub (x).sub (w);  //余り。桁落ちを避けるため倍精度で計算する
 11545:         int k = w.imul2 (this).cmpabs (y);  //|余り*2|<=>|除数|
 11546:         if (k > 0 || k == 0 && (qi & 1) != 0) {  //余りの絶対値が除数の絶対値の1/2よりも大きいか、ちょうど1/2で商が奇数のとき
 11547:           qi++;  //商の絶対値を1増やす
 11548:           if ((xf ^ yf) >= 0) {
 11549:             this.sub (y);
 11550:           } else {
 11551:             this.iadd (y);
 11552:           }
 11553:         }
 11554:         epbQuotient = qi;
 11555:         epbFpsr |= (qi & 127) << 16;  //商の絶対値の下位7bit
 11556:         if (this.flg << 1 < 0) {  //余りが0
 11557:           this.flg = xf | Z;  //0にxの符号を付ける
 11558:         }
 11559:         return this.outer ().finish ();
 11560:       } else {
 11561:         this.inner ();
 11562:         int ye = y.epp;  //this==yの場合があるので順序に注意する
 11563:         long yd = y.dvl;
 11564:         long yc = y.cvl;
 11565:         long yc1 = yc >>> 1;
 11566:         this.epp = x.epp;
 11567:         this.dvl = x.dvl;
 11568:         this.cvl = x.cvl;
 11569:         int i;
 11570:         long l;
 11571:         int q = 0;
 11572:         if ((i = this.epp - ye) > 0 ||
 11573:             i == 0 && ((l = this.dvl - yd) > 0L ||
 11574:                        l == 0L && this.cvl >>> 1 >= yc1)) {  //|x|>=|y|。商は0ではない
 11575:           this.flg = P;  //|x|。余りの初期値
 11576:           EFP t = new EFP (P, 0, yd, yc);
 11577:           do {
 11578:             t.epp = i = (l = this.dvl - yd) > 0L || l == 0L && this.cvl >>> 1 >= yc1 ? this.epp : this.epp - 1;  //指数部を揃えて
 11579:             if ((i -= ye) <= 31) {
 11580:               q |= 1 << i;
 11581:             }
 11582:             this.sub (t);  //引く。アンダーフローのチェックは後で行う
 11583:           } while (this.flg == 0 &&  //0ではない
 11584:                    ((i = this.epp - ye) > 0 ||
 11585:                     i == 0 && ((l = this.dvl - yd) > 0L ||
 11586:                                l == 0L && this.cvl >>> 1 >= yc1)));  //this>=|y|。まだ引ける。指数部が極端に違うと繰り返す回数が大きくなる
 11587:           this.flg |= xf;  //余りが0の場合も含めてyの符号に関係なくxの符号を付ける
 11588:         } else {  //|x|<|y|。商は0
 11589:           this.flg = xf;  //被除数がそのまま余りになる
 11590:         }
 11591:         if (this.flg << 1 >= 0) {  //余りが0ではないとき
 11592:           if ((i = this.epp - ye + 1) > 0 ||
 11593:               i == 0 && ((l = this.dvl - yd) > 0L ||
 11594:                          l == 0L && ((l = (this.cvl >>> 1) - yc1) > 0L ||  //|r|>|y|/2または
 11595:                                      l == 0L && (q & 1) != 0))) {  //|r|==|y|/2かつ商が奇数
 11596:             this.sub (new EFP (this.flg, ye, yd, yc));  //符号を合わせて引く。アンダーフローのチェックは後で行う
 11597:             q++;
 11598:           }
 11599:           if ((short) this.epp != this.epp) {  //アンダーフロー
 11600:             this.outer ();
 11601:             epbFpsr |= EPB_FPSR_UF;  //アンダーフロー
 11602:             epbExceptionOperandExponent = this.flg & M;
 11603:             epbExceptionOperandMantissa = this.dvl;
 11604:             return this.sete (UNFL_RESULTS[epbRoundingPrec << 3 | epbRoundingMode << 1 | xf >>> 31]).finish ();  //±0
 11605:           }
 11606:         }
 11607:         epbQuotient = q;
 11608:         epbFpsr |= (q & 127) << 16;  //商の絶対値の下位7bit
 11609:         return this.outer ().finish ();
 11610:       }
 11611:     }  //efp.ieeerem(EFP,EFP)
 11612: 
 11613:     //------------------------------------------------------------------------
 11614:     //k = x.ieeerempi2 ()
 11615:     //  k=rint(x/(pi/2))&3
 11616:     //  x=x-rint(x/(pi/2))*(pi/2)
 11617:     //k = y.ieeerempi2 (x)
 11618:     //  k=rint(x/(pi/2))&3
 11619:     //  y=x-rint(x/(pi/2))*(pi/2)
 11620:     //  ラジアンの象限分類
 11621:     //
 11622:     //  引数をpi/2で割った余りを[-pi/4..pi/4]の範囲で求めて商の下位2bitを返す
 11623:     //                     k=1
 11624:     //               │    ←
 11625:     //    k=2↓\    │    /
 11626:     //           \  │  /
 11627:     //             \│/
 11628:     //       ────・────
 11629:     //             /│\
 11630:     //           /  │  \
 11631:     //         /    │    \↑k=0
 11632:     //         →    │
 11633:     //        k=3
 11634:     //
 11635:     //  三角関数に与えられた引数が大きすぎる場合は何かの間違いでその引数と結果は意味を持たないと考えられる
 11636:     //  しかし実装としてはどのような引数が与えられても可能な限り真の値に近い結果を返したい
 11637:     //  sin(2^n)の象限分類を行うにはおよそ(n)bitの円周率を静的または動的に調達する必要がある
 11638:     //    xをyで割った余りx%y=x-trunc(x/y)*yを正確に求めるには商trunc(x/y)を1の位まで正確に求めなければならない
 11639:     //    xの指数部に対してyの有効桁数が少ないと商を1の位まで正確に求めることができない
 11640:     //    yがpi/2のときxが2^nならばyのpi/2もおよそ(n)bitなければならない
 11641:     //  除数が定数のときは除算を逆数乗算で置き換えることができる
 11642:     //    除数yがpi/2なのでxの指数部の最大値と同じ桁数の2/piの値があればよい
 11643:     //    象限分類で必要なのは商の下位2bitと余りの先頭LENbitだけである
 11644:     //    2/piの値の配列が大きくても1回の呼び出しで使用するのはその一部分に限られる
 11645:     //
 11646:     //  echo lm=32767;lw=9;default(realprecision,floor(lm*0.30103)+200);pi2=Pi/2;twopi=2/Pi;ln2=log(2);eval("hex(s)={my(v,h,i,c);v=Vecsmall(s);h=0;for(i=1,#v,c=v[i];if(c!=95,h=(h<<4)+if(48<=c&&c<=57,c-48,65<=c&&c<=70,c-55,97<=c&&c<=102,c-87,error)));h}");p=eval("twopi/2^(31*3)");a=vector((3+(lm+600)\31)\10*10,i,p=p*eval("2^31");w=floor(p);p=frac(p);printf("%s0x%08x,%s",if(i%10==1,"      ",""),w,if(i%10==0,"\n"," "));w);for(ee=0,lm,xx=hex("80000000000000000000000");tx=eval("xx/2^(91-ee)");tk=bitand(tx\pi2,3);ty=tx%pi2;yy=sum(i=1,lw,shift(a[ee\31+i],31*(lw-i)));ay=frac(xx*yy\eval("2^31")/eval("2^(31*(lw-1)-ee%31)"))*4;ak=floor(ay);ay=frac(ay)*pi2;dist=if(tk!=ak,-999,-log(abs((ay-ty)/ty))/ln2);printf("      //  %6d  %023x  %d  %32.30f  %d  %32.30f  %6.2f  %s%c",ee,xx,tk,ty,ak,ay,dist,if(eval("dist<96"),"ERROR","OK"),10)) | gp -q | grep "ERROR"
 11647:     //  エラーなし
 11648:     //  echo lm=32767;lw=9;default(realprecision,floor(lm*0.30103)+200);pi2=Pi/2;twopi=2/Pi;ln2=log(2);eval("hex(s)={my(v,h,i,c);v=Vecsmall(s);h=0;for(i=1,#v,c=v[i];if(c!=95,h=(h<<4)+if(48<=c&&c<=57,c-48,65<=c&&c<=70,c-55,97<=c&&c<=102,c-87,error)));h}");p=eval("twopi/2^(31*3)");a=vector((3+(lm+600)\31)\10*10,i,p=p*eval("2^31");w=floor(p);p=frac(p);printf("%s0x%08x,%s",if(i%10==1,"      ",""),w,if(i%10==0,"\n"," "));w);for(ee=0,lm,xx=hex("fffffffffffffffffffffff");tx=eval("xx/2^(91-ee)");tk=bitand(tx\pi2,3);ty=tx%pi2;yy=sum(i=1,lw,shift(a[ee\31+i],31*(lw-i)));ay=frac(xx*yy\eval("2^31")/eval("2^(31*(lw-1)-ee%31)"))*4;ak=floor(ay);ay=frac(ay)*pi2;dist=if(tk!=ak,-999,-log(abs((ay-ty)/ty))/ln2);printf("      //  %6d  %023x  %d  %32.30f  %d  %32.30f  %6.2f  %s%c",ee,xx,tk,ty,ak,ay,dist,if(eval("dist<96"),"ERROR","OK"),10)) | gp -q | grep "ERROR"
 11649:     //  エラーなし
 11650:     //
 11651:     //2/piの値
 11652:     //  echo lm=32767;lw=9;default(realprecision,floor(lm*0.30103)+200);pi2=Pi/2;twopi=2/Pi;ln2=log(2);eval("hex(s)={my(v,h,i,c);v=Vecsmall(s);h=0;for(i=1,#v,c=v[i];if(c!=95,h=(h<<4)+if(48<=c&&c<=57,c-48,65<=c&&c<=70,c-55,97<=c&&c<=102,c-87,error)));h}");p=eval("twopi/2^(31*3)");a=vector((3+(lm+600)\31)\10*10,i,p=p*eval("2^31");w=floor(p);p=frac(p);printf("%s0x%08x,%s",if(i%10==1,"      ",""),w,if(i%10==0,"\n"," "));w);for(ee=0,lm,xx=hex("c90fdaa22168c234c4c6629");tx=eval("xx/2^(91-ee)");tk=bitand(tx\pi2,3);ty=tx%pi2;yy=sum(i=1,lw,shift(a[ee\31+i],31*(lw-i)));ay=frac(xx*yy\eval("2^31")/eval("2^(31*(lw-1)-ee%31)"))*4;ak=floor(ay);ay=frac(ay)*pi2;dist=if(tk!=ak,-999,-log(abs((ay-ty)/ty))/ln2);printf("      //  %6d  %023x  %d  %32.30f  %d  %32.30f  %6.2f  %s%c",ee,xx,tk,ty,ak,ay,dist,if(eval("dist<96"),"ERROR","OK"),10)) | gp -q > two_pi_array.out
 11653:     //  エラーなし
 11654:     //
 11655:     public int ieeerempi2 () {
 11656:       return this.ieeerempi2 (this);
 11657:     }  //efp.ieeerempi2()
 11658:     public int ieeerempi2 (EFP x) {
 11659:       int xf = x.flg;
 11660:       if (xf << 1 != 0) {  //±0,±Inf,NaN
 11661:         this.flg = xf;  //そのまま
 11662:         return 0;
 11663:       }
 11664:       //±0,±Inf,NaN以外
 11665:       int xe = x.epp;
 11666:       long xd = x.dvl;
 11667:       long xc = x.cvl;
 11668:       int o;
 11669:       long t;
 11670:       if ((o = xe + 1) < 0 || o == 0 && ((t = xd - 0xc90fdaa22168c234L) < 0L ||
 11671:                                          t == 0L && xc >>> 1 <= 0xc4c6629L >>> 1)) {  //|x|<=pi/4
 11672:         this.flg = xf;  //そのまま
 11673:         this.epp = xe;
 11674:         this.dvl = xd;
 11675:         this.cvl = xc;
 11676:         return 0;
 11677:       }
 11678:       if ((o = xe - 1) < 0 || o == 0 && ((t = xd - 0x96cbe3f9990e91a7L) < 0L ||
 11679:                                          t == 0L && xc >>> 1 <= 0x9394c9fL >>> 1)) {  //|x|<=3*pi/4
 11680:         if (xf >= 0) {
 11681:           this.inner ().sub (x, PI_2).outer ().sub (PI_2A);  //x-pi/2
 11682:           return 1;
 11683:         } else {
 11684:           this.inner ().iadd (x, PI_2).outer ().add (PI_2A);  //x+pi/2
 11685:           return 3;
 11686:         }
 11687:       }
 11688:       //以下はxe>=1
 11689:       //92bitの仮数部を30bit,31bit,31bitに3分割する
 11690:       long x0 = xd >>> -30;  //上位30bit
 11691:       long x1 = xd >>> 3 & 0x7fffffffL;  //中位31bit
 11692:       long x2 = (xd << 28 | xc >>> -28) & 0x7fffffffL;  //下位31bit
 11693:       //  perl optdiv.pl 32767 31
 11694:       //  x/31==x*16913>>>19 (0<=x<=34966) [32767*16913==554188271]
 11695:       o = xe * 16913 >>> 19;  //xe/31。xe<0は不可
 11696:       long y0 = TWO_PI_ARRAY[o    ];
 11697:       long y1 = TWO_PI_ARRAY[o + 1];
 11698:       long y2 = TWO_PI_ARRAY[o + 2];
 11699:       long y3 = TWO_PI_ARRAY[o + 3];
 11700:       long y4 = TWO_PI_ARRAY[o + 4];
 11701:       long y5 = TWO_PI_ARRAY[o + 5];
 11702:       long y6 = TWO_PI_ARRAY[o + 6];
 11703:       long y7 = TWO_PI_ARRAY[o + 7];
 11704:       long y8 = TWO_PI_ARRAY[o + 8];
 11705:       //xとyを掛けて62bit左詰め4要素にする
 11706:       //                             x0 x1 x2
 11707:       //  *        y0 y1 y2 y3 y4 y5 y6 y7 y8
 11708:       //  -----------------------------------
 11709:       //          |     |     |     |   x2*y8
 11710:       //          |     |     |     |x1*y8|
 11711:       //          |     |     |     |x2*y7|
 11712:       //          |     |     |   x0*y8   |
 11713:       //          |     |     |   x1*y7   |
 11714:       //          |     |     |   x2*y6   |
 11715:       //          |     |     |x0*y7|     |
 11716:       //          |     |     |x1*y6|     |
 11717:       //          |     |     |x2*y5|     |
 11718:       //          |     |   x0*y6   |     |
 11719:       //          |     |   x1*y5   |     |
 11720:       //          |     |   x2*y4   |     |
 11721:       //          |     |x0*y5|     |     |
 11722:       //          |     |x1*y4|     |     |
 11723:       //          |     |x2*y3|     |     |
 11724:       //          |   x0*y4   |     |     |
 11725:       //          |   x1*y3   |     |     |
 11726:       //          |   x2*y2   |     |     |
 11727:       //          |x0*y3|     |     |     |
 11728:       //          |x1*y2|     |     |     |
 11729:       //          |x2*y1|     |     |     |
 11730:       //        x0*y2   |     |     |     |
 11731:       //        x1*y1   |     |     |     |
 11732:       //        x2*y0   |     |     |     |
 11733:       //     x0*y1|     |     |     |     |
 11734:       //     x1*y0|     |     |     |     |
 11735:       //  x0*y0   |     |     |     |     |
 11736:       //  -----------------------------------
 11737:       //           z0    z1    z2    z3
 11738:       long z3 = (x2 * y8 >>> 31) + x1 * y8 + x2 * y7;  //x2*y8の下位は捨てる
 11739:       long z2 = (z3 >>> 31) + x0 * y8 + x1 * y7 + x2 * y6;
 11740:       z3 = (z3 & 0x7fffffffL) + (z2 << 33 >>> 2) << 2;
 11741:       z2 = (z2 >>> 31) + x0 * y7 + x1 * y6 + x2 * y5;
 11742:       long z1 = (z2 >>> 31) + x0 * y6 + x1 * y5 + x2 * y4;
 11743:       z2 = (z2 & 0x7fffffffL) + (z1 << 33 >>> 2) << 2;
 11744:       z1 = (z1 >>> 31) + x0 * y5 + x1 * y4 + x2 * y3;
 11745:       long z0 = (z1 >>> 31) + x0 * y4 + x1 * y3 + x2 * y2;
 11746:       z1 = (z1 & 0x7fffffffL) + (z0 << 33 >>> 2) << 2;
 11747:       z0 = (z0 >>> 31) + x0 * y3 + x1 * y2 + x2 * y1 + (x0 * y2 + x1 * y1 + x2 * y0 << 31) << 2;  //溢れは無視する。x0*y1+x1*y0とx0*y0は不要
 11748:       //248bit左詰めにする
 11749:       z0 |= z1 >>> -2;
 11750:       z1 = z1 << 2 | z2 >>> -4;
 11751:       z2 = z2 << 4 | z3 >>> -6;
 11752:       z3 <<= 6;
 11753:       //左にxe%31bitずらす
 11754:       o = xe - o * 31;  //xe%31
 11755:       if (o != 0) {
 11756:         z0 = z0 << o | z1 >>> -o;
 11757:         z1 = z1 << o | z2 >>> -o;
 11758:         z2 = z2 << o | z3 >>> -o;
 11759:         z3 <<= o;
 11760:       }
 11761:       //商の下位2bitを取り出す
 11762:       o = (int) (z0 >>> -2);
 11763:       if (xf < 0) {
 11764:         o = -o;
 11765:       }
 11766:       //商の下位2bitを押し出して小数点以下だけにする
 11767:       z0 = z0 << 2 | z1 >>> -2;
 11768:       z1 = z1 << 2 | z2 >>> -2;
 11769:       z2 = z2 << 2 | z3 >>> -2;
 11770:       z3 <<= 2;
 11771:       //余りの絶対値が0.5以上のときは商の絶対値を1増やして余りの絶対値を1減らす
 11772:       //  左端が0.5の位なので左端が1ならば符号を反転する
 11773:       if (z0 < 0L) {
 11774:         o = xf >= 0 ? o + 1 : o - 1;
 11775:         t = z3 = -z3;
 11776:         t |= z2 = t == 0L ? -z2 : ~z2;
 11777:         t |= z1 = t == 0L ? -z1 : ~z1;
 11778:         z0 = t == 0L ? -z0 : ~z0;  //左端が0になるとは限らない。100...のときは符号反転しても100...のまま
 11779:         xf ^= M;
 11780:       }
 11781:       o &= 3;
 11782:       //正規化する
 11783:       if (z0 < 0L) {
 11784:         xe = -1;  //-1
 11785:       } else if (z0 != 0L) {
 11786:         xe = Long.numberOfLeadingZeros (z0);  //1..63。左にシフトするbit数
 11787:         z0 = z0 << xe | z1 >>> -xe;
 11788:         z1 = z1 << xe | z2 >>> -xe;
 11789:         z2 = z2 << xe | z3 >>> -xe;
 11790:         z3 <<= xe;
 11791:         xe = ~xe;  //-1-xe。-2..-64。指数
 11792:       } else if (z1 < 0L) {
 11793:         xe = -65;  //-65。指数
 11794:         z0 = z1;
 11795:         z1 = z2;
 11796:         z2 = z3;
 11797:         z3 = 0L;
 11798:       } else if (z1 != 0L) {
 11799:         xe = Long.numberOfLeadingZeros (z1) + 64;  //65..127。左にシフトするbit数
 11800:         z0 = z1 << xe | z2 >>> -xe;
 11801:         z1 = z2 << xe | z3 >>> -xe;
 11802:         z2 = z3 << xe;
 11803:         z3 = 0L;
 11804:         xe = ~xe;  //-1-xe。-66..-128。指数
 11805:       } else if (z2 < 0L) {
 11806:         xe = -129;  //-129。指数
 11807:         z0 = z2;
 11808:         z1 = z3;
 11809:         z2 = 0L;
 11810:         z3 = 0L;
 11811:       } else if (z2 != 0L) {
 11812:         xe = Long.numberOfLeadingZeros (z2) + 128;  //129..191。左にシフトするbit数
 11813:         z0 = z2 << xe | z3 >>> -xe;
 11814:         z1 = z3 << xe;
 11815:         z2 = 0L;
 11816:         z3 = 0L;
 11817:         xe = ~xe;  //-1-xe。-130..-192。指数
 11818:       } else if (z3 != 0L) {
 11819:         xe = Long.numberOfLeadingZeros (z3) + 192;  //192..255。左にシフトするbit数
 11820:         z0 = z3 << xe;
 11821:         z1 = 0L;
 11822:         z2 = 0L;
 11823:         z3 = 0L;
 11824:         xe = ~xe;  //-1-xe。-193..-256。指数
 11825:       } else {
 11826:         this.flg = xf | Z;
 11827:         return o;
 11828:       }
 11829:       //丸めの処理
 11830:       this.ifinish (xf, xe, z0, z1, z2 | z3);
 11831:       //pi/2を掛ける
 11832:       this.mul (PI_2);
 11833:       //商の下位2bitを返す
 11834:       return o;
 11835:     }  //efp.ieeerempi2(EFP)
 11836: 
 11837:     //------------------------------------------------------------------------
 11838:     //x = x.inc ()
 11839:     //  x+=1
 11840:     //y = y.inc (x)
 11841:     //  y=x+1
 11842:     //  1を加える(インクリメント)
 11843:     //
 11844:     //  グラフ
 11845:     //    perl -e "use Graph;$g=new Graph();$g->grid();$g->func(sub{$_[0]+1});print$g"
 11846:     //    echo read("../misc/efp.gp");eval("inc(x)=x+1");graph(inc) | gp -q
 11847:     //    +---------+---------+---------+---------+---------+---------+--------***--------+
 11848:     //    |                                       |                          ***          |
 11849:     //    |                                       |                        ***            |
 11850:     //    |                                       |                      ***              |
 11851:     //    |                                       |                    ***                |
 11852:     //    +                                       +                  ***                  +
 11853:     //    |                                       |                ***                    |
 11854:     //    |                                       |              ***                      |
 11855:     //    |                                       |            ***                        |
 11856:     //    |                                       |          ***                          |
 11857:     //    +                                       +        ***                            +
 11858:     //    |                                       |      ***                              |
 11859:     //    |                                       |    ***                                |
 11860:     //    |                                       |  ***                                  |
 11861:     //    |                                       |***                                    |
 11862:     //    +                                      ***                                      +
 11863:     //    |                                    ***|                                       |
 11864:     //    |                                  ***  |                                       |
 11865:     //    |                                ***    |                                       |
 11866:     //    |                              ***      |                                       |
 11867:     //    +---------+---------+--------***--------+---------+---------+---------+---------+
 11868:     //    |                          ***          |                                       |
 11869:     //    |                        ***            |                                       |
 11870:     //    |                      ***              |                                       |
 11871:     //    |                    ***                |                                       |
 11872:     //    +                  ***                  +                                       +
 11873:     //    |                ***                    |                                       |
 11874:     //    |              ***                      |                                       |
 11875:     //    |            ***                        |                                       |
 11876:     //    |          ***                          |                                       |
 11877:     //    +        ***                            +                                       +
 11878:     //    |      ***                              |                                       |
 11879:     //    |    ***                                |                                       |
 11880:     //    |  ***                                  |                                       |
 11881:     //    |***                                    |                                       |
 11882:     //    **                                      +                                       +
 11883:     //    |                                       |                                       |
 11884:     //    |                                       |                                       |
 11885:     //    |                                       |                                       |
 11886:     //    |                                       |                                       |
 11887:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
 11888:     //
 11889:     public final EFP inc () {
 11890:       return this.inc (this);
 11891:     }  //efp.inc()
 11892:     public final EFP inc (EFP x) {
 11893:       //return this.add (x, ONE);  //7.6ns
 11894:       //6.2ns
 11895:       int xf = x.flg;
 11896:       if (xf << 1 != 0) {  //±0,±Inf,NaN
 11897:         if (xf << 1 < 0) {  //±0
 11898:           this.flg = P;  //+1
 11899:           this.epp = 0;
 11900:           this.dvl = MSB;
 11901:           this.cvl = 0L;
 11902:         } else {  //±Inf,NaN
 11903:           this.flg = xf;
 11904:         }
 11905:         return this;
 11906:       }
 11907:       //±0,±Inf,NaN以外
 11908:       int xe = x.epp;
 11909:       if (xe < -LEN) {  //..-LEN-1。xの先頭がguard bitよりも右
 11910:         //絶対値は1の方が大きいのでxを右にシフトするがxの絶対値が小さすぎるので1になる
 11911:         epbFpsr |= EPB_FPSR_X2;  //不正確な結果
 11912:         this.flg = P;  //+1
 11913:         this.epp = 0;
 11914:         this.dvl = MSB;
 11915:         this.cvl = 0L;
 11916:         return this;
 11917:       }
 11918:       long xd = x.dvl;
 11919:       long xc = x.cvl;
 11920:       if (LEN < xe) {  //LEN+1..。1がguard bitよりも右
 11921:         //絶対値はxの方が大きいので1を右にシフトするが1の絶対値が小さすぎるのでxになる
 11922:         epbFpsr |= EPB_FPSR_X2;  //不正確な結果
 11923:         return this.finish (xf, xe, xd, xc, 0L);  //x
 11924:       }
 11925:       long xb = 0L;
 11926:       if (xe == 0) {  //0。xの最上位bitと1が重なる
 11927:         //絶対値はxの方が大きいか等しいが小数点の位置は同じ
 11928:         if (xf < 0) {  //-x
 11929:           //絶対値から1を引く
 11930:           xd -= MSB;
 11931:         } else {  //+x
 11932:           //絶対値に1を加える
 11933:           xb = xc << -1;
 11934:           xc = xd << -1 | xc >>> 1;
 11935:           xd = (xd >>> 1) + (MSB >>> 1);
 11936:           xe++;
 11937:         }
 11938:       } else if (0 < xe) {  //1..LEN
 11939:         //絶対値はxの方が大きいので1を右にシフトする
 11940:         if (xf < 0) {  //-x
 11941:           //絶対値から1を引く
 11942:           if (xe <= 63) {  //1..63。xの上位の2bit目以降と1が重なる
 11943:             xd -= MSB >>> xe;  //最上位bitが1なのでボローはなく0にもならない
 11944:           } else {  //64..LEN。xの下位またはguard bitと1が重なる
 11945:             if (xc >>> ~xe != 0L) {  //下位の引く位置から上が0ではない。下位だけで引ける
 11946:               xc -= MSB >>> xe;
 11947:             } else {  //下位の引く位置から上が0なのでボローが発生する
 11948:               xc |= MSB >> xe;  //下位の引く位置から上は-1になる
 11949:               xd--;  //ボローを上位から引く
 11950:             }
 11951:           }
 11952:         } else {  //+x
 11953:           //絶対値に1を加える
 11954:           if (xe <= 63) {  //1..63。xの上位と1が重なる
 11955:             if ((xd += MSB >>> xe) >>> ~xe == 0L) {  //絶対値に1を加えたら加えたbitから上がすべて0になって溢れた
 11956:               xb = xc << -1;
 11957:               xc = xd << -1 | xc >>> 1;
 11958:               xd = MSB | xd >>> 1;
 11959:               xe++;
 11960:             }
 11961:           } else {  //64..LEN。xの下位またはguard bitと1が重なる
 11962:             if ((xc += MSB >>> xe) >>> ~xe == 0L && ++xd == 0L) {  //絶対値に1を加えたら加えたbitから上がすべて0になって溢れた
 11963:               xb = xc << -1;
 11964:               xc = xc >>> 1;
 11965:               xd = MSB;
 11966:               xe++;
 11967:             }
 11968:           }
 11969:         }
 11970:       } else {  //-LEN..-1
 11971:         //絶対値は1の方が大きいのでxを右にシフトする
 11972:         if (-63 <= xe) {  //-63..-1。xの先頭が1の右隣から上位の最下位bitまで
 11973:           xb = xc << xe;
 11974:           xc = xd << xe | xc >>> -xe;
 11975:           xd >>>= -xe;
 11976:         } else if (-64 == xe) {  //-64。xの先頭が下位の最上位bit
 11977:           xb = xc;
 11978:           xc = xd;
 11979:           xd = 0L;
 11980:         } else {  //-LEN..-65。xの先頭が下位の上から2bit目からguard bitまで
 11981:           xb = xd << xe | xc >>> -xe;
 11982:           xc = xd >>> -xe;
 11983:           xd = 0L;
 11984:         }
 11985:         xe = 0;
 11986:         if (xf < 0) {  //-x
 11987:           //絶対値を1から引く
 11988:           if (xb != 0L) {
 11989:             xb = -xb;
 11990:             xc = -1L - xc;
 11991:             xd = MSB - 1L - xd;
 11992:           } else if (xc != 0L) {
 11993:             xc = -xc;
 11994:             xd = MSB - 1L - xd;
 11995:           } else {
 11996:             xd = MSB - xd;
 11997:           }
 11998:           xf ^= M;  //符号反転
 11999:         } else {  //+x
 12000:           //絶対値に1を加える
 12001:           xd |= MSB;
 12002:         }
 12003:       }
 12004:       //正規化する
 12005:       if (xd >= 0L) {
 12006:         if (xd != 0L) {
 12007:           int o = Long.numberOfLeadingZeros (xd);  //1..63。左にシフトするbit数
 12008:           xe -= o;
 12009:           xd = xd << o | xc >>> -o;
 12010:           xc = xc << o | xb >>> -o;
 12011:           xb <<= o;
 12012:         } else if (xc < 0L) {
 12013:           xe -= 64;
 12014:           xd = xc;
 12015:           xc = xb;
 12016:           xb = 0L;
 12017:         } else if (xc != 0L) {
 12018:           int o = 64 + Long.numberOfLeadingZeros (xc);  //65..127。左にシフトするbit数
 12019:           xe -= o;
 12020:           xd = xc << o | xb >>> -o;
 12021:           xc = xb << o;
 12022:           xb = 0L;
 12023:         } else if (xb < 0L) {
 12024:           xe -= 128;
 12025:           xd = xb;
 12026:           xc = 0L;
 12027:           xb = 0L;
 12028:         } else if (xb != 0L) {
 12029:           int o = 128 + Long.numberOfLeadingZeros (xb);  //129..191。左にシフトするbit数
 12030:           xe -= o;
 12031:           xd = xb << o;
 12032:           xc = 0L;
 12033:           xb = 0L;
 12034:         } else {
 12035:           this.flg = P | Z;  //-1+1=+0
 12036:           return this;
 12037:         }
 12038:       }
 12039:       return this.finish (xf, xe, xd, xc, xb);
 12040:     }  //efp.inc(EFP)
 12041: 
 12042:     //------------------------------------------------------------------------
 12043:     //b = x.iseven ()
 12044:     //  偶数の整数か
 12045:     //
 12046:     //  NaNは偶数ではない
 12047:     //  ±0,±Infは偶数
 12048:     //  ±0,±Inf,NaN以外は1の位のbitがないか1の位のbitが0ならば偶数
 12049:     //
 12050:     public boolean iseven () {
 12051:       int xf = this.flg;
 12052:       int xe = this.epp;
 12053:       return (xf << 1 != 0 ? xf << 3 >= 0 :  //±0,±Infは偶数。NaNは整数ではない
 12054:               xe < 0 ? false :  //整数部の1が小数点よりも右側にあるということは小数点以下が0ではないので整数ではない
 12055:               xe > LEN - 1 ? true : //1の位が小数部よりも右側にあるということは1の位が0なので偶数
 12056:               xe <= 63 ? this.dvl << xe == 0L && this.cvl == 0L : this.cvl << xe == 0L);  //1の位と小数点以下がすべて0ならば偶数
 12057:     }  //efp.iseven()
 12058: 
 12059:     //------------------------------------------------------------------------
 12060:     //b = x.isinf ()
 12061:     //  ±Infか
 12062:     //
 12063:     public boolean isinf () {
 12064:       return this.flg << 2 < 0;  //±Inf
 12065:     }  //efp.isinf()
 12066: 
 12067:     //------------------------------------------------------------------------
 12068:     //b = x.isint ()
 12069:     //  整数か
 12070:     //
 12071:     //  NaNは整数ではない
 12072:     //  ±0,±Infは整数
 12073:     //  ±0,±Inf,NaN以外は小数点よりも右側にセットされているbitがなければ整数
 12074:     //
 12075:     public boolean isint () {
 12076:       int xf = this.flg;
 12077:       int xe = this.epp;
 12078:       return (xf << 1 != 0 ? xf << 3 >= 0 :  //±0,±Infは整数。NaNは整数ではない
 12079:               xe < 0 ? false :  //整数部の1が小数点よりも右側にあるということは小数点以下が0ではないので整数ではない
 12080:               xe >= LEN - 1 ? true : //小数点が小数部よりも右側にあるので整数
 12081:               xe <= 63 ? this.dvl << 1 << xe == 0L && this.cvl == 0L : this.cvl << xe == 0L);  //小数点以下がすべて0ならば偶数
 12082:     }  //efp.isint()
 12083: 
 12084:     //------------------------------------------------------------------------
 12085:     //b = x.isnan ()
 12086:     //  NaNか
 12087:     //
 12088:     public boolean isnan () {
 12089:       return this.flg << 3 < 0;  //NaN
 12090:     }  //efp.isnan()
 12091: 
 12092:     //------------------------------------------------------------------------
 12093:     //b = x.isodd ()
 12094:     //  奇数の整数か
 12095:     //
 12096:     //  NaNは奇数ではない
 12097:     //  ±0,±Infは奇数ではない
 12098:     //  ±0,±Inf,NaN以外は1の位のbitが1ならば奇数
 12099:     //
 12100:     public boolean isodd () {
 12101:       int xf = this.flg;
 12102:       int xe = this.epp;
 12103:       return (xf << 1 != 0 ? false :  //±0,±Infは奇数ではない。NaNは整数ではない
 12104:               xe < 0 ? false :  //整数部の1が小数点よりも右側にあるということは小数点以下が0ではないので整数ではない
 12105:               xe > LEN - 1 ? false : //1の位が小数部よりも右側にあるということは1の位が0なので奇数ではない
 12106:               xe <= 63 ? this.dvl << xe == MSB && this.cvl == 0L : this.cvl << xe == MSB);  //1の位が1で小数点以下がすべて0ならば奇数
 12107:     }  //efp.isodd()
 12108: 
 12109:     //------------------------------------------------------------------------
 12110:     //b = x.isone ()
 12111:     //  +1か
 12112:     //
 12113:     public boolean isone () {
 12114:       return (this.flg == P &&
 12115:               this.epp == 0 &&
 12116:               this.dvl == MSB &&
 12117:               this.cvl == 0L);  //1
 12118:     }  //efp.isone()
 12119: 
 12120:     //------------------------------------------------------------------------
 12121:     //b = x.iszero ()
 12122:     //  ±0か
 12123:     //
 12124:     public boolean iszero () {
 12125:       return this.flg << 1 < 0;  //±0
 12126:     }  //efp.iszero()
 12127: 
 12128:     //------------------------------------------------------------------------
 12129:     //b = x.le (y)
 12130:     //  b=x<=y
 12131:     //  より小さいか等しいか
 12132:     //
 12133:     //  -Inf==-Inf<-x<-0==+0<+x<+Inf==+Inf
 12134:     //
 12135:     //  NaNの扱い
 12136:     //    どちらかがNaNのときはfalseを返す
 12137:     //
 12138:     public boolean le (EFP y) {
 12139:       int xf = this.flg;
 12140:       int yf = y.flg;
 12141:       if ((xf | yf) << 1 != 0) {  //どちらかが±0,±Inf,NaN
 12142:         return EFP_LE_TABLE[xf >>> 28] << (yf >>> 28 - 1) < 0;
 12143:       }
 12144:       //両方±0,±Inf,NaN以外
 12145:       if (xf != yf) {  //両方±0,±Inf,NaN以外で符号が違う
 12146:         return xf < yf;
 12147:       }
 12148:       //両方±0,±Inf,NaN以外で符号が同じ
 12149:       int s;
 12150:       long t;
 12151:       return (xf >= 0 ? 1 : -1) * ((s = this.epp - y.epp) != 0 ? s >= 0 ? 1 : -1 :
 12152:                                    (t = this.dvl - y.dvl) != 0L ? t >= 0L ? 1 : -1 :
 12153:                                    (t = (this.cvl >>> 1) - (y.cvl >>> 1)) != 0L ? t >= 0L ? 1 : -1 :
 12154:                                    0) <= 0;
 12155:     }  //efp.le(EFP)
 12156: 
 12157:     //------------------------------------------------------------------------
 12158:     //x = x.log ()
 12159:     //  x=log(x)
 12160:     //y = y.log (x)
 12161:     //  y=log(x)
 12162:     //  自然対数 natural logarithm
 12163:     //
 12164:     //  グラフ
 12165:     //    perl -e "use Graph;$g=new Graph();$g->grid();$g->func(sub{log($_[0])});print$g"
 12166:     //    echo read("../misc/efp.gp");graph(log) | gp -q
 12167:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
 12168:     //    |                                       |                                       |
 12169:     //    |                                       |                                       |
 12170:     //    |                                       |                                       |
 12171:     //    |                                       |                                       |
 12172:     //    +                                       +                                       +
 12173:     //    |                                       |                                       |
 12174:     //    |                                       |                                       |
 12175:     //    |                                       |                                       |
 12176:     //    |                                       |                                       |
 12177:     //    +                                       +                                       +
 12178:     //    |                                       |                                       |
 12179:     //    |                                       |                                       |
 12180:     //    |                                       |                                    ****
 12181:     //    |                                       |                             ********  |
 12182:     //    +                                       +                        ******         +
 12183:     //    |                                       |                   ******              |
 12184:     //    |                                       |               *****                   |
 12185:     //    |                                       |            ****                       |
 12186:     //    |                                       |          ***                          |
 12187:     //    +---------+---------+---------+---------+--------***--------+---------+---------+
 12188:     //    |                                       |      ***                              |
 12189:     //    |                                       |     **                                |
 12190:     //    |                                       |    **                                 |
 12191:     //    |                                       |   **                                  |
 12192:     //    +                                       +  **                                   +
 12193:     //    |                                       |  *                                    |
 12194:     //    |                                       | **                                    |
 12195:     //    |                                       | *                                     |
 12196:     //    |                                       |**                                     |
 12197:     //    +                                       +*                                      +
 12198:     //    |                                       |*                                      |
 12199:     //    |                                       |*                                      |
 12200:     //    |                                       |*                                      |
 12201:     //    |                                       |*                                      |
 12202:     //    +                                       **                                      +
 12203:     //    |                                       *                                       |
 12204:     //    |                                       *                                       |
 12205:     //    |                                       *                                       |
 12206:     //    |                                       *                                       |
 12207:     //    +---------+---------+---------+---------*---------+---------+---------+---------+
 12208:     //
 12209:     //  定義域
 12210:     //    0<x<=inf
 12211:     //
 12212:     //  値域
 12213:     //    -inf<=y<=inf
 12214:     //
 12215:     //  テイラー展開
 12216:     //    > coeff(sub(a=0,for n:=0:8 sum sub(x=a,df(log(1+x),x,n))/factorial(n)*(x-a)^n),x);
 12217:     //           - 1   1    - 1   1    - 1   1    - 1
 12218:     //    {0,1,------,---,------,---,------,---,------}
 12219:     //           2     3    4     5    6     7    8
 12220:     //    log(1+x)=sum[n=1..inf]{(-1)^(n+1)*x^n/n}
 12221:     //    1<xのときはlog(x)=-log(1/x)で計算する
 12222:     //
 12223:     //  テイラー展開2
 12224:     //    log(1+x)=sum[n=1..inf]{(-1)^(n+1)*x^n/n}
 12225:     //    xに-xを代入すると偶数次の項は係数が負のままで奇数次の項は係数が正から負に変わるので
 12226:     //    log(1-x)=sum[n=1..inf]{-x^n/n}
 12227:     //    > coeff(sub(a=0,for n:=0:8 sum sub(x=a,df(log(1-x),x,n))/factorial(n)*(x-a)^n),x);
 12228:     //            - 1    - 1    - 1    - 1    - 1    - 1    - 1
 12229:     //    {0,-1,------,------,------,------,------,------,------}
 12230:     //            2      3      4      5      6      7      8
 12231:     //    これらを引くと偶数次の項が消えて
 12232:     //    log(1+x)-log(1-x)=2*sum[k=0..inf]{x^(2*k+1)/(2*k+1)}
 12233:     //    すなわち
 12234:     //    log((1+x)/(1-x))=2*sum[k=0..inf]{x^(2*k+1)/(2*k+1)}
 12235:     //    > coeff(sub(a=0,for n:=0:14 sum sub(x=a,df(log((1+x)/(1-x)),x,n))/factorial(n)*(x-a)^n),x);
 12236:     //            2     2     2     2     2      2
 12237:     //    {0,2,0,---,0,---,0,---,0,---,0,----,0,----}
 12238:     //            3     5     7     9     11     13
 12239:     //    ここで
 12240:     //    u=(x-1)/(x+1)
 12241:     //    とおくと
 12242:     //    x=(1+u)/(1-u)
 12243:     //    であるから
 12244:     //    log(x)=2*sum[k=0..inf]{u^(2*k+1)/(2*k+1)}
 12245:     //    0<x<infのとき-1<u<1なので定義域のほぼ全域で収束する
 12246:     //    それでもxが1から離れると収束が遅い
 12247:     //    式からわかるように、log(x)のグラフと2*(x-1)/(x+1)のグラフは1付近の形がよく似ている
 12248:     //    perl -e "use Graph;$g=new Graph();$g->grid();$g->func(sub{my($x)=@_;2*($x-1)/($x+1)});print$g"
 12249:     //    +--------***--------+---------+---------+---------+---------+---------+---------+
 12250:     //    |     ****                              |                                       |
 12251:     //    |  ****                                 |                                       |
 12252:     //    ****                                    |                                       |
 12253:     //    |                                       |                                       |
 12254:     //    +                                       +                                       +
 12255:     //    |                                       |                                       |
 12256:     //    |                                       |                                       |
 12257:     //    |                                       |                                       |
 12258:     //    |                                       |                                       |
 12259:     //    +                                       +                                       +
 12260:     //    |                                       |                                       |
 12261:     //    |                                       |                                       |
 12262:     //    |                                       |                                       |
 12263:     //    |                                       |                                 *******
 12264:     //    +                                       +                         *********     +
 12265:     //    |                                       |                    ******             |
 12266:     //    |                                       |                *****                  |
 12267:     //    |                                       |             ****                      |
 12268:     //    |                                       |          ****                         |
 12269:     //    +---------+---------+---------+---------+--------***--------+---------+---------+
 12270:     //    |                                       |      ***                              |
 12271:     //    |                                       |     **                                |
 12272:     //    |                                       |    **                                 |
 12273:     //    |                                       |   **                                  |
 12274:     //    +                                       +  **                                   +
 12275:     //    |                                       | **                                    |
 12276:     //    |                                       |**                                     |
 12277:     //    |                                       |*                                      |
 12278:     //    |                                       **                                      |
 12279:     //    +                                       *                                       +
 12280:     //    |                                      **                                       |
 12281:     //    |                                      *|                                       |
 12282:     //    |                                      *|                                       |
 12283:     //    |                                     **|                                       |
 12284:     //    +                                     * +                                       +
 12285:     //    |                                     * |                                       |
 12286:     //    |                                    ** |                                       |
 12287:     //    |                                    *  |                                       |
 12288:     //    |                                    *  |                                       |
 12289:     //    +---------+---------+---------+------*--+---------+---------+---------+---------+
 12290:     //    差を10倍してみる
 12291:     //    perl -e "use Graph;$g=new Graph();$g->grid();$g->func(sub{my($x)=@_;10*(2*($x-1)/($x+1)-log($x))});print$g"
 12292:     //    +---------+---------+---------+---------+-*-------+---------+---------+---------+
 12293:     //    |                                       | *                                     |
 12294:     //    |                                       | *                                     |
 12295:     //    |                                       | *                                     |
 12296:     //    |                                       | *                                     |
 12297:     //    +                                       + *                                     +
 12298:     //    |                                       | *                                     |
 12299:     //    |                                       | *                                     |
 12300:     //    |                                       | *                                     |
 12301:     //    |                                       | *                                     |
 12302:     //    +                                       + *                                     +
 12303:     //    |                                       | **                                    |
 12304:     //    |                                       |  *                                    |
 12305:     //    |                                       |  *                                    |
 12306:     //    |                                       |  *                                    |
 12307:     //    +                                       +  *                                    +
 12308:     //    |                                       |  **                                   |
 12309:     //    |                                       |   *                                   |
 12310:     //    |                                       |   **                                  |
 12311:     //    |                                       |    **                                 |
 12312:     //    +---------+---------+---------+---------+-----***********---+---------+---------+
 12313:     //    |                                       |               ******                  |
 12314:     //    |                                       |                    ****               |
 12315:     //    |                                       |                       ***             |
 12316:     //    |                                       |                         ****          |
 12317:     //    +                                       +                            ***        +
 12318:     //    |                                       |                              ****     |
 12319:     //    |                                       |                                 ***   |
 12320:     //    |                                       |                                   *** |
 12321:     //    |                                       |                                     ***
 12322:     //    +                                       +                                       +
 12323:     //    |                                       |                                       |
 12324:     //    |                                       |                                       |
 12325:     //    |                                       |                                       |
 12326:     //    |                                       |                                       |
 12327:     //    +                                       +                                       +
 12328:     //    |                                       |                                       |
 12329:     //    |                                       |                                       |
 12330:     //    |                                       |                                       |
 12331:     //    |                                       |                                       |
 12332:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
 12333:     //
 12334:     //  テイラー展開3
 12335:     //    浮動小数点数の特性を利用して指数部を分離する
 12336:     //    x=2^k*vのとき
 12337:     //    log(x)=log(2^k*v)
 12338:     //          =k*log(2)+log(v)
 12339:     //    sqrt(2)/2<=v<=sqrt(2)
 12340:     //    となるようにkを選ぶと
 12341:     //    2*sqrt(2)-3<=(v-1)/(v+1)<=3-2*sqrt(2)
 12342:     //    -0.17157...<=(v-1)/(v+1)<=0.17157...
 12343:     //    となる
 12344:     //    1/(3-2*sqrt(2))^2=33.97...であるから1項増やす毎に5bit以上増える
 12345:     //    多倍長の場合はxと同じ精度のlog(2)を他の方法で求めなければならない
 12346:     //    echo read("../misc/efp.gp");eval("f(n,x)={my(u=(x-1)/(x+1));2*sum(k=0,n,u^(2*k+1)/(2*k+1))}");for(n=0,30,printf("%4d",floor(closeness2(log,f(n,x),sqrt(2)/2,sqrt(2))))) | gp -q
 12347:     //       0   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30
 12348:     //       6  12  18  23  28  34  39  44  49  55  60  65  70  76  81  86  91  96 101 107 112 117 122 127 132 137 143 148 153 158 163
 12349:     //
 12350:     //  連分数展開
 12351:     //    log(1+x)=x/(1+x/(2+x/(3+4*x/(4+4*x/(5+9*x/(6+9*x/(7+...
 12352:     //      echo eval("h(k)=if(k==1,1/2,bitand(k,1)==0,k/(k+1)/4,(k+1)/k/4)");eval("g(n,x,k)=h(k)*x/(1+if(k<n,g(n,x,k+1),0))");eval("f(n,x)=x/(1+if(n<1,0,g(n,x,1)))");for(n=0,10,print("    //      f(",n,",x)=",f(n,x))) | gp -q
 12353:     //      f(0,x)=x
 12354:     //      f(1,x)=2*x/(x + 2)
 12355:     //      f(2,x)=(x^2 + 6*x)/(4*x + 6)
 12356:     //      f(3,x)=(3*x^2 + 6*x)/(x^2 + 6*x + 6)
 12357:     //      f(4,x)=(x^3 + 21*x^2 + 30*x)/(9*x^2 + 36*x + 30)
 12358:     //      f(5,x)=(11*x^3 + 60*x^2 + 60*x)/(3*x^3 + 36*x^2 + 90*x + 60)
 12359:     //      f(6,x)=(3*x^4 + 140*x^3 + 510*x^2 + 420*x)/(48*x^3 + 360*x^2 + 720*x + 420)
 12360:     //      f(7,x)=(25*x^4 + 260*x^3 + 630*x^2 + 420*x)/(6*x^4 + 120*x^3 + 540*x^2 + 840*x + 420)
 12361:     //      f(8,x)=(6*x^5 + 505*x^4 + 3360*x^3 + 6510*x^2 + 3780*x)/(150*x^4 + 1800*x^3 + 6300*x^2 + 8400*x + 3780)
 12362:     //      f(9,x)=(137*x^5 + 2310*x^4 + 9870*x^3 + 15120*x^2 + 7560*x)/(30*x^5 + 900*x^4 + 6300*x^3 + 16800*x^2 + 18900*x + 7560)
 12363:     //      f(10,x)=(5*x^6 + 672*x^5 + 7035*x^4 + 23520*x^3 + 30870*x^2 + 13860*x)/(180*x^5 + 3150*x^4 + 16800*x^3 + 37800*x^2 + 37800*x + 13860)
 12364:     //      echo read("../misc/efp.gp");eval("log1p(x)=log(1+x)");eval("h(k)=if(k==1,1/2,k%2==0,k/(k+1)/4,(k+1)/k/4)");eval("g(n,x,k)=h(k)*x/(1+if(k<n,g(n,x,k+1),0))");eval("f(n,x)=x/(1+if(n<1,0,g(n,x,1)))");for(n=0,30,printf("%4d",floor(closeness2(log1p,f(n,x),sqrt(2)/2-1,sqrt(2)-1)))) | gp -q
 12365:     //       0   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30
 12366:     //       2   6   9  13  16  20  23  27  31  34  38  41  45  48  52  55  59  62  66  70  73  77  80  84  87  91  94  98 101 105 108
 12367:     //
 12368:     //  チェビシェフ展開
 12369:     //    x=(1+u)/(1-u)
 12370:     //    u=(x-1)/(x+1)
 12371:     //    log((1+u)/(1-u))=2*sum[k=0..inf]{u^(2*k+1)/(2*k+1)}
 12372:     //    の係数を調整する
 12373:     //    sqrt(2)/2<=x<=sqrt(2)
 12374:     //    のとき
 12375:     //    2*sqrt(2)-3<=u<=3-2*sqrt(2)
 12376:     //    であるから
 12377:     //    echo read("../misc/efp.gp");eval("f(u)=log((1+u)/(1-u))");a=2*sqrt(2)-3;b=3-2*sqrt(2);for(k=0,30,printf("%4d",floor(closeness2(f,chebyshev(f,a,b,2*k+1),a,b)))) | gp -q
 12378:     //       0   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30
 12379:     //       7  14  21  28  35  42  49  56  63  70  77  84  91  98 105 113 120 127 134 141 148 155 162 169 176 183 190 197 204 211 219
 12380:     //
 12381:     //  expm1を高速に計算できる場合
 12382:     //    組み込み関数を使ってlog(x)=log1p(x-1)の近似値y'を求める
 12383:     //    expm1を使ってx'-1=expm1(y')を正確に求める。これは正確なのでlog(x')=y'である
 12384:     //    log(x)=log(x'*(x/x'))
 12385:     //          =log(x')+log(x/x')
 12386:     //          =y'+log((x'+x-x')/x')
 12387:     //          =y'+log(1+(x-x')/x')
 12388:     //          =y'+log1p((x'-x)/x)
 12389:     //    (x-x')/xは小さいのでlog1p((x-x')/x')は速く収束する
 12390:     //
 12391:     //  AGM
 12392:     //    I(a,b)=int[0..pi/2]{dt/sqrt(a^2*cos(t)^2+b^2*sin(t)^2)}
 12393:     //    T(a,b)=2/pi*I(a,b)=1/M(a,b)
 12394:     //    M(a[0],b[0])=lim[n=inf]{a[n]}=lim[n=inf]{b[n]}
 12395:     //    a[n+1]=(a[n]+b[n])/2
 12396:     //    b[n+1]=sqrt(a[n]*b[n])
 12397:     //    abs(log(x)-[I(1,10^-n)-I(1,10^-n*x)])<n*10^(2-2*n)  (0<x<1)
 12398:     //    echo read("../misc/efp.gp");eval("fi(a,b)=intnum(t=0,Pi/2,1/sqrt(a^2*cos(t)^2+b^2*sin(t)^2))");eval("f(n,x)=fi(1,2^-n)-fi(1,2^-n*x)");printf("%.30f",f(100,2)/f(100,10)) | gp -q
 12399:     //    0.301029995663981195213738894724
 12400:     //    echo read("../misc/efp.gp");eval("g(a,b)=Pi/2/agm(a,b)");eval("f(n,x)=g(1,2^-n)-g(1,2^-n*x)");printf("%.30f",f(100,2)/f(100,10)) | gp -q
 12401:     //    0.301029995663981195213738894724
 12402:     //    perl -e "sub mm{my($a,$b)=@_;while(1){my$t=($a+$b)/2;$t<$a or last;$b=sqrt($a*$b);$a=$t}$a};sub ii{my($a,$b)=@_;atan2(1,1)*2/mm($a,$b)}sub ll{my($x,$n)=@_;ii(1,2**-$n)-ii(1,2**-$n*$x)}printf'    //    %14s  %22s  %22s  %22s%c','x','log(x)','ll(x,31)','abs(ll(x,31)-log(x))',10;for my$k(-10..10){my$x=10**$k;printf'    //    %14.14g  %22.16g  %22.16g  %22.16g%c',$x,log($x),ll($x,31),abs(log($x)-ll($x,31)),10}"
 12403:     //                 x                  log(x)                ll(x,31)    abs(ll(x,31)-log(x))
 12404:     //             1e-10      -23.02585092994046      -23.02585092994045   3.552713678800501e-15
 12405:     //             1e-09      -20.72326583694641       -20.7232658369464   7.105427357601002e-15
 12406:     //             1e-08      -18.42068074395237      -18.42068074395237                       0
 12407:     //             1e-07      -16.11809565095832      -16.11809565095832   3.552713678800501e-15
 12408:     //             1e-06      -13.81551055796427      -13.81551055796427                       0
 12409:     //             1e-05      -11.51292546497023      -11.51292546497024   8.881784197001252e-15
 12410:     //            0.0001      -9.210340371976182       -9.21034037197618    1.77635683940025e-15
 12411:     //             0.001      -6.907755278982137      -6.907755278982144   7.105427357601002e-15
 12412:     //              0.01      -4.605170185988091      -4.605170185988086   4.440892098500626e-15
 12413:     //               0.1      -2.302585092994045       -2.30258509299405   4.884981308350689e-15
 12414:     //                 1                       0                       0                       0
 12415:     //                10       2.302585092994046       2.302585092994047   8.881784197001252e-16
 12416:     //               100       4.605170185988092       4.605170185988079   1.243449787580175e-14
 12417:     //              1000       6.907755278982137       6.907755278981323   8.135714324453147e-13
 12418:     //             10000       9.210340371976184       9.210340371907533   6.865086277230148e-11
 12419:     //            100000       11.51292546497023       11.51292545935356   5.616673348640688e-09
 12420:     //           1000000       13.81551055796427       13.81551012112039   4.368438872859315e-07
 12421:     //          10000000       16.11809565095832       16.11806444854419   3.120241413512304e-05
 12422:     //         100000000       18.42068074395237       18.41880659707298    0.001874146879391247
 12423:     //        1000000000       20.72326583694641        20.6532968557838     0.06996898116260653
 12424:     //       10000000000       23.02585092994046       21.30306063168329       1.722790298257163
 12425:     //    1<xのときはlog(x)=-log(1/x)で計算する
 12426:     //    収束は速いがsqrtが必要なので桁数が少ないときは効率が悪い
 12427:     //
 12428:     public final EFP log () {
 12429:       return this.log (this);
 12430:     }  //efp.log()
 12431:     public final EFP log (EFP x) {
 12432:       int xf = x.flg;
 12433:       if (xf != 0) {  //-x,±0,±Inf,NaN
 12434:         if (xf << 3 < 0) {  //NaN
 12435:           this.flg = N;  //log(NaN)=NaN
 12436:         } else if (xf << 1 < 0) {  //±0
 12437:           epbFpsr |= EPB_FPSR_DZ;
 12438:           epbExceptionOperandExponent = xf & M;
 12439:           epbExceptionOperandMantissa = 0x0000000000000000L;
 12440:           this.flg = M | I;  //log(±0)=-Inf
 12441:         } else if (xf >= 0) {  //+Inf
 12442:           this.flg = P | I;  //log(+Inf)=+Inf
 12443:         } else {  //-x,-Inf
 12444:           epbFpsr |= EPB_FPSR_OE;
 12445:           if (xf << 2 < 0) {  //log(-Inf)=NaN
 12446:             epbExceptionOperandExponent = M | 0x7fff << 16;
 12447:             epbExceptionOperandMantissa = 0x0000000000000000L;
 12448:           } else {  //log(-x)=NaN
 12449:             epbExceptionOperandExponent = M | 0x3fff + x.epp << 16;
 12450:             epbExceptionOperandMantissa = x.dvl;
 12451:           }
 12452:           this.flg = N;  //log(-x)=NaN, log(-Inf)=NaN
 12453:         }
 12454:         return this;
 12455:       }
 12456:       //-x,±0,±Inf,NaN以外
 12457:       if (x.epp == 0 && x.dvl == MSB && x.cvl == 0L) {  //+1
 12458:         this.flg = epbRoundingMode == EPB_MODE_RM ? M | Z : P | Z;  //log(1)=±0。RMのときだけ-0
 12459:         return this;
 12460:       }
 12461:       //-x,±0,+1,±Inf,NaN以外
 12462:       this.inner ();
 12463:       if (true) {
 12464:         //1の近くだけlog1p()を使う
 12465:         if ((x.epp == -1 && x.dvl >>> 32 == 0xffffffff00000000L >>> 32) ||  //1-2^32<=x<1
 12466:             (x.epp == 0 && x.dvl >>> 31 == 0x8000000000000000L >>> 31)) {  //1<=x<1+2^-32
 12467:           //return this.inner ().dec (x).outer ().log1p ();
 12468:           //log(1+x)=x-x^2/2+x^3/3
 12469:           EFP t = new EFP ().dec (x);
 12470:           return this.cub (t).div3 ().sub (new EFP ().squ (t).div2 ()).outer ().add (t);
 12471:         }
 12472:       }
 12473:       epbFpsr |= EPB_FPSR_X2;  //不正確な結果
 12474:       EFP v = new EFP (x);
 12475:       v.epp = v.dvl >= 0xb504f333f9de6484L ? -1 : 0;  //SQRT2
 12476:       int k = x.epp - v.epp;  //x=2^k*v, sqrt(2)/2<=v<=sqrt(2)
 12477:       if (true) {  //チェビシェフ展開。[90] 420ns
 12478:         EFP u = new EFP ().dec (v).div (v.inc ());  //u=(v-1)/(v+1)
 12479:         v.isqu (u);  //u^2
 12480:         /*
 12481:         this.imul (LOG_C25, v)
 12482:           .iadd (LOG_C23).imul (v)
 12483:             .iadd (LOG_C21).imul (v)
 12484:               .iadd (LOG_C19).imul (v)
 12485:                 .iadd (LOG_C17).imul (v)
 12486:                   .iadd (LOG_C15).imul (v)
 12487:                     .iadd (LOG_C13).imul (v)
 12488:                       .iadd (LOG_C11).imul (v)
 12489:                         .iadd (LOG_C9).imul (v)
 12490:                           .iadd (LOG_C7).imul (v)
 12491:                             .iadd (LOG_C5).imul (v)
 12492:                               .iadd (LOG_C3).imul (v)
 12493:                                 .iadd (LOG_C1).imul (u)
 12494:                                   .iadd (v.muli (LOG_2, k)).iadd (v.muli (LOG_2A, k));  //log(x)=log(2^k*v)=k*log(2)+log(v)
 12495:          */
 12496:         this.imul (LOG_C27, v)
 12497:           .iadd (LOG_C25).imul (v)
 12498:             .iadd (LOG_C23).imul (v)
 12499:               .iadd (LOG_C21).imul (v)
 12500:                 .iadd (LOG_C19).imul (v)
 12501:                   .iadd (LOG_C17).imul (v)
 12502:                     .iadd (LOG_C15).imul (v)
 12503:                       .iadd (LOG_C13).imul (v)
 12504:                         .iadd (LOG_C11).imul (v)
 12505:                           .iadd (LOG_C9).imul (v)
 12506:                             .iadd (LOG_C7).imul (v)
 12507:                               .iadd (LOG_C5).imul (v)
 12508:                                 .iadd (LOG_C3).imul (v)
 12509:                                   .iadd (LOG_C1).imul (u)
 12510:                                     .iadd (v.muli (LOG_2, k)).iadd (v.muli (LOG_2A, k));  //log(x)=log(2^k*v)=k*log(2)+log(v)
 12511:       } else {  //expm1を使う。[89] 520ns
 12512:         EFP vv1 = new EFP ().dec (v);
 12513:         if (vv1.flg << 1 < 0) {  //log(2^k*1)
 12514:           this.muli (LOG_2, k);  //log(2^k)=k*log(2)
 12515:         } else {
 12516:           EFP yy = ZERO;
 12517:           if (-1023 < vv1.epp) {
 12518:             //  Math.log1p(double)を使ってlog(v)の近似値y'を求める
 12519:             long s = Double.doubleToLongBits (Math.log1p (Double.longBitsToDouble ((long) (vv1.flg | 1023 + vv1.epp << 20) << 32 | vv1.dvl << 1 >>> 12)));
 12520:             if (s != 0L) {
 12521:               int sh = (int) (s >>> 32);
 12522:               yy = new EFP (sh & M, (sh >>> 20 & 2047) - 1023, MSB | s << 12 >>> 1, 0L);  //log(v)の近似値y'
 12523:             }
 12524:           }
 12525:           //  expm1を使ってlog(v')=y'を満たすv'を求める
 12526:           vv1.expm1 (yy);  //v'-1=expm1(y')
 12527:           //  log(v)=log(v')+log1p((v-v')/v')を使ってlog(v)を計算する
 12528:           //  (v-v')/v'は小さいので1次の項だけ加える
 12529:           v.dec ().sub (vv1);  //(v-1)-(v'-1)=v-v'
 12530:           this.rcp (vv1.inc ()).imul (v).iadd (yy)  //y'+(v-v')/v'≒log(v')+log1p((v-v')/v')=log(v)
 12531:             .iadd (v.muli (LOG_2, k)).iadd (v.muli (LOG_2A, k));  //log(x)=log(2^k*v)=k*log(2)+log(v)
 12532:         }
 12533:       }
 12534:       return outer ().finish ();
 12535:     }  //efp.log(EFP)
 12536: 
 12537:     //------------------------------------------------------------------------
 12538:     //x = x.log10 ()
 12539:     //  x=log10(x)
 12540:     //y = y.log10 (x)
 12541:     //  y=log10(x)
 12542:     //  常用対数 common logarithm
 12543:     //
 12544:     //  グラフ
 12545:     //    perl -e "use Graph;$g=new Graph();$g->grid();$g->func(sub{log($_[0])/log(10)});print$g"
 12546:     //    echo read("../misc/efp.gp");eval("log10(x)=log(x)/log(10)");graph(log10) | gp -q
 12547:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
 12548:     //    |                                       |                                       |
 12549:     //    |                                       |                                       |
 12550:     //    |                                       |                                       |
 12551:     //    |                                       |                                       |
 12552:     //    +                                       +                                       +
 12553:     //    |                                       |                                       |
 12554:     //    |                                       |                                       |
 12555:     //    |                                       |                                       |
 12556:     //    |                                       |                                       |
 12557:     //    +                                       +                                       +
 12558:     //    |                                       |                                       |
 12559:     //    |                                       |                                       |
 12560:     //    |                                       |                                       |
 12561:     //    |                                       |                                       |
 12562:     //    +                                       +                                       +
 12563:     //    |                                       |                                       |
 12564:     //    |                                       |                               *********
 12565:     //    |                                       |                   *************       |
 12566:     //    |                                       |            ********                   |
 12567:     //    +---------+---------+---------+---------+-------******------+---------+---------+
 12568:     //    |                                       |    ****                               |
 12569:     //    |                                       |  ***                                  |
 12570:     //    |                                       | **                                    |
 12571:     //    |                                       |**                                     |
 12572:     //    +                                       +*                                      +
 12573:     //    |                                       |*                                      |
 12574:     //    |                                       **                                      |
 12575:     //    |                                       *                                       |
 12576:     //    |                                       *                                       |
 12577:     //    +                                       *                                       +
 12578:     //    |                                       *                                       |
 12579:     //    |                                       *                                       |
 12580:     //    |                                       *                                       |
 12581:     //    |                                       *                                       |
 12582:     //    +                                       *                                       +
 12583:     //    |                                       *                                       |
 12584:     //    |                                       *                                       |
 12585:     //    |                                       *                                       |
 12586:     //    |                                       |                                       |
 12587:     //    +---------+---------+---------+---------*---------+---------+---------+---------+
 12588:     //
 12589:     //  対数関数との関係
 12590:     //    log10(x)=log(x)/log(10)
 12591:     //
 12592:     public final EFP log10 () {
 12593:       return this.log10 (this);
 12594:     }  //efp.log10()
 12595:     public final EFP log10 (EFP x) {
 12596:       //return this.log (x).div (LOG_10);  //log(x)/log(10) [90]
 12597:       int xf = x.flg;
 12598:       if (xf != 0) {  //-x,±0,±Inf,NaN
 12599:         if (xf << 3 < 0) {  //NaN
 12600:           this.flg = N;  //log10(NaN)=NaN
 12601:         } else if (xf << 1 < 0) {  //±0
 12602:           epbFpsr |= EPB_FPSR_DZ;
 12603:           epbExceptionOperandExponent = xf & M;
 12604:           epbExceptionOperandMantissa = 0x0000000000000000L;
 12605:           this.flg = M | I;  //log10(±0)=-Inf
 12606:         } else if (xf >= 0) {  //+Inf
 12607:           epbExceptionOperandExponent = 0x7fff << 16;
 12608:           epbExceptionOperandMantissa = 0x0000000000000000L;
 12609:           this.flg = P | I;  //log10(+Inf)=+Inf
 12610:         } else {  //-x,-Inf
 12611:           epbFpsr |= EPB_FPSR_OE;
 12612:           if (xf << 2 < 0) {  //-Inf
 12613:             epbExceptionOperandExponent = M | 0x7fff << 16;
 12614:             epbExceptionOperandMantissa = 0x0000000000000000L;
 12615:           } else {  //-x
 12616:             epbExceptionOperandExponent = M | 0x3fff + x.epp << 16;
 12617:             epbExceptionOperandMantissa = x.dvl;
 12618:           }
 12619:           this.flg = N;  //log10(-x)=NaN, log10(-Inf)=NaN
 12620:         }
 12621:         return this;
 12622:       }
 12623:       //-x,±0,±Inf,NaN以外
 12624:       int xe = x.epp;
 12625:       //log10(1)を特別扱いにする
 12626:       if (xe == 0 && x.dvl == MSB && x.cvl == 0L) {  //log10(1)
 12627:         this.flg = epbRoundingMode == EPB_MODE_RM ? M | Z : P | Z;  //log10(1)=±0。RMのときは-0,RN,RZ,RPのときは+0
 12628:         return this;
 12629:       }
 12630:       //log10(10^n)(n>0)を特別扱いにする
 12631:       if (3 <= xe && xe <= 129) {
 12632:         EFP t = ACCURATE_LOG10_BASE[xe];
 12633:         if (t != null && x.dvl == t.dvl && x.cvl == t.cvl) {
 12634:           //結果は正確だがMC68882に合わせて不正確な結果をセットしておく
 12635:           epbFpsr |= EPB_FPSR_X2;  //不正確な結果
 12636:           //  perl -e "for$e(0..129){$n=($e+1)*617>>11;if($e==int(log(10**$n)/log(2))){print$e,' ';}}"
 12637:           //  0 3 6 9 13 16 19 23 26 29 33 36 39 43 46 49 53 56 59 63 66 69 73 76 79 83 86 89 93 96 99 102 106 109 112 116 119 122 126 129 
 12638:           return this.seti ((xe + 1) * 617 >> 11);
 12639:         }
 12640:       }
 12641:       //-x,±0,10^n,±Inf,NaN以外
 12642:       this.inner ();
 12643:       epbFpsr |= EPB_FPSR_X2;  //不正確な結果
 12644:       EFP v = new EFP (x);
 12645:       v.epp = v.dvl >= 0xb504f333f9de6484L ? -1 : 0;  //SQRT2
 12646:       int k = x.epp - v.epp;  //x=2^k*v, sqrt(2)/2<=v<=sqrt(2)
 12647:       EFP u = new EFP ().dec (v).div (v.inc ());  //u=(v-1)/(v+1)
 12648:       v.isqu (u);  //u^2
 12649:       this.imul (LOG10_C27, v)
 12650:         .iadd (LOG10_C25).imul (v)
 12651:           .iadd (LOG10_C23).imul (v)
 12652:             .iadd (LOG10_C21).imul (v)
 12653:               .iadd (LOG10_C19).imul (v)
 12654:                 .iadd (LOG10_C17).imul (v)
 12655:                   .iadd (LOG10_C15).imul (v)
 12656:                     .iadd (LOG10_C13).imul (v)
 12657:                       .iadd (LOG10_C11).imul (v)
 12658:                         .iadd (LOG10_C9).imul (v)
 12659:                           .iadd (LOG10_C7).imul (v)
 12660:                             .iadd (LOG10_C5).imul (v)
 12661:                               .iadd (LOG10_C3).imul (v)
 12662:                                 .iadd (LOG10_C1).imul (u)
 12663:                                   .iadd (u.muli (LOG10_2, k));
 12664:       u.muli (LOG10_2A, k);
 12665:       return this.outer ().add (u);  //log10(x)=log10(2^k*v)=k*log10(2)+log(v) [91]
 12666:     }  //efp.log10()
 12667: 
 12668:     //------------------------------------------------------------------------
 12669:     //x = x.log1p ()
 12670:     //  x=log(1+x)
 12671:     //y = y.log1p (x)
 12672:     //  y=log(1+x)
 12673:     //  1に近い数の自然対数 natural logarithm of number being close to 1
 12674:     //
 12675:     //  グラフ
 12676:     //    perl -e "use Graph;$g=new Graph();$g->grid();$g->func(sub{log(1+$_[0])});print$g"
 12677:     //    echo read("../misc/efp.gp");eval("log1p(x)=log(1+x)");graph(log1p) | gp -q
 12678:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
 12679:     //    |                                       |                                       |
 12680:     //    |                                       |                                       |
 12681:     //    |                                       |                                       |
 12682:     //    |                                       |                                       |
 12683:     //    +                                       +                                       +
 12684:     //    |                                       |                                       |
 12685:     //    |                                       |                                       |
 12686:     //    |                                       |                                       |
 12687:     //    |                                       |                                       |
 12688:     //    +                                       +                                       +
 12689:     //    |                                       |                                       |
 12690:     //    |                                       |                                  ******
 12691:     //    |                                       |                          *********    |
 12692:     //    |                                       |                   ********            |
 12693:     //    +                                       +              ******                   +
 12694:     //    |                                       |         ******                        |
 12695:     //    |                                       |     *****                             |
 12696:     //    |                                       |  ****                                 |
 12697:     //    |                                       |***                                    |
 12698:     //    +---------+---------+---------+--------***--------+---------+---------+---------+
 12699:     //    |                                    ***|                                       |
 12700:     //    |                                   **  |                                       |
 12701:     //    |                                  **   |                                       |
 12702:     //    |                                 **    |                                       |
 12703:     //    +                                **     +                                       +
 12704:     //    |                                *      |                                       |
 12705:     //    |                               **      |                                       |
 12706:     //    |                               *       |                                       |
 12707:     //    |                              **       |                                       |
 12708:     //    +                              *        +                                       +
 12709:     //    |                              *        |                                       |
 12710:     //    |                              *        |                                       |
 12711:     //    |                              *        |                                       |
 12712:     //    |                              *        |                                       |
 12713:     //    +                             **        +                                       +
 12714:     //    |                             *         |                                       |
 12715:     //    |                             *         |                                       |
 12716:     //    |                             *         |                                       |
 12717:     //    |                             *         |                                       |
 12718:     //    +---------+---------+---------*---------+---------+---------+---------+---------+
 12719:     //
 12720:     //  メモ
 12721:     //    log1p(x)の存在意義は1に極端に近い値の対数をlog(x)よりも正確に求められることだが、
 12722:     //    これは変数xに1に極端に近い値が入っているときlog(x)よりもlog1p(x-1)の方が正確な結果を返すという意味ではない
 12723:     //    例えば有効桁数が10桁のときxに1.000000001111111111を代入しようとするとxの値は1.000000001になってしまう
 12724:     //    x-1で桁落ちした引数をlog1pに与えたところで結果の精度が高くなるわけがない
 12725:     //    1に極端に近い値を経由せずにlog1p(1.111111111e-9)を計算すれば正確な結果が得られる
 12726:     //
 12727:     //  テイラー展開
 12728:     //    log(1+x)=sum[n=1..inf]{(-1)^(n+1)*x^n/n}
 12729:     //
 12730:     //  チェビシェフ展開
 12731:     //    sqrt(2)/2-1<=x<=sqrt(2)-1
 12732:     //    のとき
 12733:     //    u=x/(x+2)
 12734:     //    x=2*u/(1-u)
 12735:     //    とおくと
 12736:     //    2*sqrt(2)-3<=u<=3-2*sqrt(2)
 12737:     //    log(x)のときと同じ多項式を使う
 12738:     //
 12739:     //  メモ
 12740:     //    log1p(-0)=-0,log1p(+0)=+0に注意する
 12741:     //
 12742:     public final EFP log1p () {
 12743:       return this.log1p (this);
 12744:     }  //efp.log1p()
 12745:     public final EFP log1p (EFP x) {
 12746:       int xf = x.flg;
 12747:       if (xf << 1 != 0) {  //±0,±Inf,NaN
 12748:         if (xf << 3 < 0) {  //NaN
 12749:           this.flg = N;  //log1p(NaN)=NaN
 12750:         } else if (xf << 1 < 0) {  //±0
 12751:           this.flg = xf;  //log1p(±0)=±0
 12752:         } else if (xf >= 0) {  //+Inf
 12753:           this.flg = P | I;  //log1p(+Inf)=+Inf
 12754:         } else {  //-Inf
 12755:           epbFpsr |= EPB_FPSR_OE;
 12756:           epbExceptionOperandExponent = M | 0x7fff << 16;
 12757:           epbExceptionOperandMantissa = 0x0000000000000000L;
 12758:           this.flg = N;  //log1p(-Inf)=NaN
 12759:         }
 12760:         return this;
 12761:       }
 12762:       //±0,±Inf,NaN以外
 12763:       if (xf < 0) {  //x<0
 12764:         if (x.epp == 0 && x.dvl == MSB && x.cvl == 0L) {  //x==-1
 12765:           epbFpsr |= EPB_FPSR_DZ;  //MC68882はlog1p(-1)でDZをセットする
 12766:           epbExceptionOperandExponent = M | 0x3fff << 16;
 12767:           epbExceptionOperandMantissa = 0x8000000000000000L;
 12768:           this.flg = M | I;  //log1p(-1)=-Inf
 12769:           return this;
 12770:         } else if (x.epp >= 0) {  //x<-1
 12771:           epbFpsr |= EPB_FPSR_OE;
 12772:           epbExceptionOperandExponent = M | 0x3fff + x.epp << 16;
 12773:           epbExceptionOperandMantissa = x.dvl;
 12774:           this.flg = N;  //log1p(x<-1)=NaN
 12775:           return this;
 12776:         }
 12777:       }
 12778:       epbFpsr |= EPB_FPSR_X2;  //不正確な結果
 12779:       //if (x.epp < -2 || (x.epp == -2 && x.dvl <= (xf < 0 ? 0x95f619980c4336f7L : 0xd413cccfe7799211L))) {  //sqrt(2)/2-1<=x<=sqrt(2)-1
 12780:       if (LOG1P_A.le (x) && x.le (LOG1P_B)) {  //sqrt(2)/2-1<=x<=sqrt(2)-1
 12781:         int savedFpsr = epbFpsr;
 12782:         this.inner ();
 12783:         if (this == x) {
 12784:           x = new EFP (x);
 12785:         }
 12786:         EFP u = new EFP ().iadd (x, TWO).rcpdiv (x);  //u=x/(x+2)
 12787:         EFP v = new EFP ().isqu (u);  //u^2
 12788:         /*
 12789:         return this.imul (LOG_C25, v)
 12790:           .iadd (LOG_C23).imul (v)
 12791:             .iadd (LOG_C21).imul (v)
 12792:               .iadd (LOG_C19).imul (v)
 12793:                 .iadd (LOG_C17).imul (v)
 12794:                   .iadd (LOG_C15).imul (v)
 12795:                     .iadd (LOG_C13).imul (v)
 12796:                       .iadd (LOG_C11).imul (v)
 12797:                         .iadd (LOG_C9).imul (v)
 12798:                           .iadd (LOG_C7).imul (v)
 12799:                             .iadd (LOG_C5).imul (v)
 12800:                               .iadd (LOG_C3).imul (v)
 12801:                                 .iadd (LOG_C1).outer ().mul (u);
 12802:          */
 12803:         this.imul (LOG_C27, v)
 12804:           .iadd (LOG_C25).imul (v)
 12805:             .iadd (LOG_C23).imul (v)
 12806:               .iadd (LOG_C21).imul (v)
 12807:                 .iadd (LOG_C19).imul (v)
 12808:                   .iadd (LOG_C17).imul (v)
 12809:                     .iadd (LOG_C15).imul (v)
 12810:                       .iadd (LOG_C13).imul (v)
 12811:                         .iadd (LOG_C11).imul (v)
 12812:                           .iadd (LOG_C9).imul (v)
 12813:                             .iadd (LOG_C7).imul (v)
 12814:                               .iadd (LOG_C5).imul (v)
 12815:                                 .iadd (LOG_C3).imul (v)
 12816:                                   .iadd (LOG_C1).outer ().mul (u);
 12817:         return this.originLowerLower (x).correctUnderflow (savedFpsr);
 12818:       }
 12819:       return this.inner ().inc (x).outer ().log ();  //log(1+x)
 12820:     }  //efp.log1p()
 12821: 
 12822:     //------------------------------------------------------------------------
 12823:     //x = x.log2 ()
 12824:     //  x=log2(x)
 12825:     //y = y.log2 (x)
 12826:     //  y=log2(x)
 12827:     //  二進対数 binary logarithm
 12828:     //
 12829:     //  グラフ
 12830:     //    perl -e "use Graph;$g=new Graph();$g->grid();$g->func(sub{log($_[0])/log(2)});print$g"
 12831:     //    echo read("../misc/efp.gp");eval("log2(x)=log(x)/log(2)");graph(log2) | gp -q
 12832:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
 12833:     //    |                                       |                                       |
 12834:     //    |                                       |                                       |
 12835:     //    |                                       |                                       |
 12836:     //    |                                       |                                       |
 12837:     //    +                                       +                                       +
 12838:     //    |                                       |                                       |
 12839:     //    |                                       |                                       |
 12840:     //    |                                       |                                       |
 12841:     //    |                                       |                                       |
 12842:     //    +                                       +                                    ****
 12843:     //    |                                       |                               ******  |
 12844:     //    |                                       |                           *****       |
 12845:     //    |                                       |                        ****           |
 12846:     //    |                                       |                    *****              |
 12847:     //    +                                       +                  ***                  +
 12848:     //    |                                       |               ****                    |
 12849:     //    |                                       |             ***                       |
 12850:     //    |                                       |           ***                         |
 12851:     //    |                                       |          **                           |
 12852:     //    +---------+---------+---------+---------+--------***--------+---------+---------+
 12853:     //    |                                       |       **                              |
 12854:     //    |                                       |      **                               |
 12855:     //    |                                       |     **                                |
 12856:     //    |                                       |    **                                 |
 12857:     //    +                                       +    *                                  +
 12858:     //    |                                       |   **                                  |
 12859:     //    |                                       |   *                                   |
 12860:     //    |                                       |  **                                   |
 12861:     //    |                                       |  *                                    |
 12862:     //    +                                       + **                                    +
 12863:     //    |                                       | *                                     |
 12864:     //    |                                       | *                                     |
 12865:     //    |                                       | *                                     |
 12866:     //    |                                       |**                                     |
 12867:     //    +                                       +*                                      +
 12868:     //    |                                       |*                                      |
 12869:     //    |                                       |*                                      |
 12870:     //    |                                       |*                                      |
 12871:     //    |                                       |*                                      |
 12872:     //    +---------+---------+---------+---------+*--------+---------+---------+---------+
 12873:     //
 12874:     //  対数関数との関係
 12875:     //    log2(x)=log(x)/log(2)
 12876:     //
 12877:     //  チェビシェフ展開
 12878:     //    指数部を分離する
 12879:     //      log2(x)=log2(2^k*v)=k+log2(v)
 12880:     //      1<=v<2
 12881:     //    定義域を0に近付ける
 12882:     //      -(1-t)/(1+t)=(2-t)/(2+t)をtについて解くとt=sqrt(2)
 12883:     //      u=(v-sqrt(2))/(v+sqrt(2))
 12884:     //      2*sqrt(2)-3<=u<3-2*sqrt(2)
 12885:     //      v=sqrt(2)*(1+u)/(1-u)
 12886:     //      log2(v)=log2(sqrt(2)*(1+u)/(1-u))
 12887:     //    perl -e "use Graph;$g=new Graph();$g->grid();$g->func(sub{my($u)=@_;log(sqrt(2)*(1+$u)/(1-$u))/log(2)});print$g"
 12888:     //    +---------+---------+---------+---------+-------*-+---------+---------+---------+
 12889:     //    |                                       |       *                               |
 12890:     //    |                                       |       *                               |
 12891:     //    |                                       |      **                               |
 12892:     //    |                                       |      *                                |
 12893:     //    +                                       +      *                                +
 12894:     //    |                                       |     **                                |
 12895:     //    |                                       |     *                                 |
 12896:     //    |                                       |     *                                 |
 12897:     //    |                                       |    **                                 |
 12898:     //    +                                       +    *                                  +
 12899:     //    |                                       |   **                                  |
 12900:     //    |                                       |  **                                   |
 12901:     //    |                                       |  *                                    |
 12902:     //    |                                       | **                                    |
 12903:     //    +                                       +**                                     +
 12904:     //    |                                       |*                                      |
 12905:     //    |                                       **                                      |
 12906:     //    |                                      **                                       |
 12907:     //    |                                      *|                                       |
 12908:     //    +---------+---------+---------+-------**+---------+---------+---------+---------+
 12909:     //    |                                    ** |                                       |
 12910:     //    |                                    *  |                                       |
 12911:     //    |                                   **  |                                       |
 12912:     //    |                                  **   |                                       |
 12913:     //    +                                  *    +                                       +
 12914:     //    |                                 **    |                                       |
 12915:     //    |                                 *     |                                       |
 12916:     //    |                                 *     |                                       |
 12917:     //    |                                **     |                                       |
 12918:     //    +                                *      +                                       +
 12919:     //    |                                *      |                                       |
 12920:     //    |                               **      |                                       |
 12921:     //    |                               *       |                                       |
 12922:     //    |                               *       |                                       |
 12923:     //    +                               *       +                                       +
 12924:     //    |                              **       |                                       |
 12925:     //    |                              *        |                                       |
 12926:     //    |                              *        |                                       |
 12927:     //    |                              *        |                                       |
 12928:     //    +---------+---------+---------+*--------+---------+---------+---------+---------+
 12929:     //    奇関数にするためlog2(v)-1/2をチェビシェフ展開する
 12930:     //    echo read("../misc/efp.gp");eval("f(u)=log(sqrt(2)*(1+u)/(1-u))/log(2)-1/2");a=2*sqrt(2)-3;b=3-2*sqrt(2);forstep(n=1,31,2,printf("%4d",floor(closeness(f,chebyshev(f,a,b,n),a,b,10000)))); | gp -q
 12931:     //       1   3   5   7   9  11  13  15  17  19  21  23  25  27  29  31
 12932:     //       7  14  21  28  35  42  49  56  63  70  77  84  91  98 105 113
 12933:     //
 12934:     public final EFP log2 () {
 12935:       return this.log2 (this);
 12936:     }  //efp.log2()
 12937:     public final EFP log2 (EFP x) {
 12938:       //return this.log (x).div (LOG_2);  //log(x)/log(2)
 12939:       int xf = x.flg;
 12940:       if (xf != 0) {  //-x,±0,±Inf,NaN
 12941:         if (xf << 3 < 0) {  //NaN
 12942:           this.flg = N;  //log2(NaN)=NaN
 12943:         } else if (xf << 1 < 0) {  //±0
 12944:           epbFpsr |= EPB_FPSR_DZ;
 12945:           epbExceptionOperandExponent = xf & M;
 12946:           epbExceptionOperandMantissa = 0x0000000000000000L;
 12947:           this.flg = M | I;  //log2(±0)=-Inf
 12948:         } else if (xf >= 0) {  //+Inf
 12949:           this.flg = P | I;  //log2(+Inf)=+Inf
 12950:         } else {  //-x,-Inf
 12951:           epbFpsr |= EPB_FPSR_OE;
 12952:           if (xf << 2 < 0) {  //-Inf
 12953:             epbExceptionOperandExponent = M | 0x7fff << 16;
 12954:             epbExceptionOperandMantissa = 0x0000000000000000L;
 12955:           } else {  //-x
 12956:             epbExceptionOperandExponent = M | 0x3fff + x.epp << 16;
 12957:             epbExceptionOperandMantissa = x.dvl;
 12958:           }
 12959:           this.flg = N;  //log2(-x)=NaN, log2(-Inf)=NaN
 12960:         }
 12961:         return this;
 12962:       }
 12963:       //-x,±0,±Inf,NaN以外
 12964:       //log2(2^n)を特別扱いにする
 12965:       if (x.dvl == MSB && x.cvl == 0L) {  //log2(2^n)
 12966:         if (x.epp == 0) {  //log2(1)
 12967:           this.flg = epbRoundingMode == EPB_MODE_RM ? M | Z : P | Z;  //log2(1)=±0。RMのときは-0,RN,RZ,RPのときは+0
 12968:         } else {  //log2(2^n)(n>0)
 12969:           //結果は正確だがMC68882に合わせて不正確な結果をセットしておく
 12970:           epbFpsr |= EPB_FPSR_X2;  //不正確な結果
 12971:           this.seti (x.epp);  //log2(2^n)=n
 12972:         }
 12973:         return this;
 12974:       }
 12975:       //-x,±0,2^n,±Inf,NaN以外
 12976:       this.inner ();
 12977:       epbFpsr |= EPB_FPSR_X2;  //不正確な結果
 12978:       EFP v = new EFP (x);
 12979:       v.epp = v.dvl >= 0xb504f333f9de6484L ? -1 : 0;  //SQRT2
 12980:       int k = x.epp - v.epp;  //x=2^k*v, sqrt(2)/2<=v<=sqrt(2)
 12981:       EFP u = new EFP ().dec (v).div (v.inc ());  //u=(v-1)/(v+1)
 12982:       v.isqu (u);  //u^2
 12983:       this.imul (LOG2_C27, v)
 12984:         .iadd (LOG2_C25).imul (v)
 12985:           .iadd (LOG2_C23).imul (v)
 12986:             .iadd (LOG2_C21).imul (v)
 12987:               .iadd (LOG2_C19).imul (v)
 12988:                 .iadd (LOG2_C17).imul (v)
 12989:                   .iadd (LOG2_C15).imul (v)
 12990:                     .iadd (LOG2_C13).imul (v)
 12991:                       .iadd (LOG2_C11).imul (v)
 12992:                         .iadd (LOG2_C9).imul (v)
 12993:                           .iadd (LOG2_C7).imul (v)
 12994:                             .iadd (LOG2_C5).imul (v)
 12995:                               .iadd (LOG2_C3).imul (v)
 12996:                                 .iadd (LOG2_C1).imul (u);
 12997:       u.seti (k);
 12998:       return this.outer ().add (u);  //log2(x)=log2(2^k*v)=k+log2(v)
 12999:     }  //efp.log2()
 13000: 
 13001:     //------------------------------------------------------------------------
 13002:     //x = x.lgamma ()
 13003:     //  x=log(Γ(x))
 13004:     //y = y.lgamma (x)
 13005:     //  y=log(Γ(x))
 13006:     //  ログガンマ関数
 13007:     //
 13008:     //  グラフ
 13009:     //    echo read("../misc/efp.gp");graph(lngamma) | gp -q
 13010:     //    +---------+---------+---------+---------*---------+---------+---------+---------+
 13011:     //    |                                       *                                       |
 13012:     //    |                                       *                                       |
 13013:     //    |                                       *                                       |
 13014:     //    |                                       *                                       |
 13015:     //    +                                       **                                      +
 13016:     //    |                                       |*                                      |
 13017:     //    |                                       |*                                      |
 13018:     //    |                                       |*                                      |
 13019:     //    |                                       |*                                      |
 13020:     //    +                                       +*                                      +
 13021:     //    |                                       |**                                    **
 13022:     //    |                                       | *                                   **|
 13023:     //    |                                       | *                                 *** |
 13024:     //    |                                       | **                              ***   |
 13025:     //    +                                       +  **                           ***     +
 13026:     //    |                                       |   *                         ***       |
 13027:     //    |                                       |   **                      ***         |
 13028:     //    |                                       |    ***                 ****           |
 13029:     //    |                                       |      ***            ****              |
 13030:     //    +---------+---------+---------+---------+--------*****---******-------+---------+
 13031:     //    |                                       |            *****                      |
 13032:     //    |                                       |                                       |
 13033:     //    |                                       |                                       |
 13034:     //    |                                       |                                       |
 13035:     //    +                                       +                                       +
 13036:     //    |                                       |                                       |
 13037:     //    |                                       |                                       |
 13038:     //    |                                       |                                       |
 13039:     //    |                                       |                                       |
 13040:     //    +                                       +                                       +
 13041:     //    |                                       |                                       |
 13042:     //    |                                       |                                       |
 13043:     //    |                                       |                                       |
 13044:     //    |                                       |                                       |
 13045:     //    +                                       +                                       +
 13046:     //    |                                       |                                       |
 13047:     //    |                                       |                                       |
 13048:     //    |                                       |                                       |
 13049:     //    |                                       |                                       |
 13050:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
 13051:     //
 13052:     //  0<x<13のとき
 13053:     //    Γ(x)=Γ(x+1)/x
 13054:     //    log(Γ(x))=log(Γ(x+1))-log(x)
 13055:     //    で13<=xまで持っていく
 13056:     //    log(Γ(12+α))=log(Γ(13+α))-log(12+α)
 13057:     //    log(Γ(11+α))=log(Γ(12+α))-log(11+α)
 13058:     //                =log(Γ(13+α))-log(12+α)-log(11+α)
 13059:     //                =log(Γ(13+α))-log((12+α)*(11+α))
 13060:     //    log(Γ(10+α))=log(Γ(11+α))-log(10+α)
 13061:     //                =log(Γ(13+α))-log((12+α)*(11+α))-log(10+α)
 13062:     //                =log(Γ(13+α))-log((12+α)*(11+α)*(10+α))
 13063:     //                :
 13064:     //    すなわち
 13065:     //    d=1
 13066:     //    while x<13
 13067:     //      d*=x
 13068:     //      x+=1
 13069:     //    としてからlog(Γ(x))を計算してlog(Γ(x))-log(d)を返す
 13070:     //
 13071:     //  13<=xのとき
 13072:     //    log(Γ(x))=(x-1/2)*log(x)-x+log(2*π)/2+Σ[n=1..∞]{B(2*n)/(2*n*(2*n-1)*x^(2*n-1))]
 13073:     //
 13074:     public final EFP lgamma () {
 13075:       return this.lgamma (this);
 13076:     }  //efp.lgamma()
 13077:     public final EFP lgamma (EFP x) {
 13078:       int xf = x.flg;
 13079:       if (xf != 0) {  //-x,±0,±Inf,NaN
 13080:         this.flg = (xf == (P | Z) || xf == (P | I) ? P | I :  //lgamma(+0)=lgamma(+Inf)=+Inf
 13081:                     N);  //lgamma(NaN)=lgamma(-Inf)=lgamma(-x)=lgamma(-0)=NaN
 13082:         return this;
 13083:       }
 13084:       //+x
 13085:       this.inner ();
 13086:       x = new EFP (x);
 13087:       EFP d = null;
 13088:       if (x.lt (THIRTEEN)) {
 13089:         d = new EFP (ONE);
 13090:         do {
 13091:           d.mul (x);
 13092:           x.inc ();
 13093:         } while (x.lt (THIRTEEN));
 13094:       }
 13095:       EFP t = new EFP ().rcp (x);  //1/x
 13096:       EFP t2 = new EFP ().squ (t);  //1/x^2
 13097:       this.mul (LGAMMA_C14, t2)
 13098:         .add (LGAMMA_C13).mul (t2)
 13099:           .add (LGAMMA_C12).mul (t2)
 13100:             .add (LGAMMA_C11).mul (t2)
 13101:               .add (LGAMMA_C10).mul (t2)
 13102:                 .add (LGAMMA_C9).mul (t2)
 13103:                   .add (LGAMMA_C8).mul (t2)
 13104:                     .add (LGAMMA_C7).mul (t2)
 13105:                       .add (LGAMMA_C6).mul (t2)
 13106:                         .add (LGAMMA_C5).mul (t2)
 13107:                           .add (LGAMMA_C4).mul (t2)
 13108:                             .add (LGAMMA_C3).mul (t2)
 13109:                               .add (LGAMMA_C2).mul (t2)
 13110:                                 .add (LGAMMA_C1).mul (t)
 13111:                                   .add (LOGTWOPI_2).sub (x);  //-x+log(2*π)/2+Σ[n=1..14]{B(2*n)/(2*n*(2*n-1)*x^(2*n-1))]
 13112:       t.sub (x, ONE_2);  //x-1/2
 13113:       this.add (x.log ().mul (t));  //(x-1/2)*log(x)-x+log(2*π)/2+Σ[n=1..14]{B(2*n)/(2*n*(2*n-1)*x^(2*n-1))]
 13114:       if (d != null) {
 13115:         this.sub (d.log ());  //log(Γ(x))-log(d)
 13116:       }
 13117:       return this.outer ().finish ();
 13118:     }  //efp.lgamma(EFP)
 13119: 
 13120:     //------------------------------------------------------------------------
 13121:     //b = x.lt (y)
 13122:     //  b=x<y
 13123:     //  より小さいか
 13124:     //
 13125:     //  -Inf==-Inf<-x<-0==+0<+x<+Inf==+Inf
 13126:     //
 13127:     //  NaNの扱い
 13128:     //    どちらかがNaNのときはfalseを返す
 13129:     //
 13130:     public boolean lt (EFP y) {
 13131:       int xf = this.flg;
 13132:       int yf = y.flg;
 13133:       if ((xf | yf) << 1 != 0) {  //どちらかが±0,±Inf,NaN
 13134:         return EFP_LT_TABLE[xf >>> 28] << (yf >>> 28 - 1) < 0;
 13135:       }
 13136:       //両方±0,±Inf,NaN以外
 13137:       if (xf != yf) {  //両方±0,±Inf,NaN以外で符号が違う
 13138:         return xf < yf;
 13139:       }
 13140:       //両方±0,±Inf,NaN以外で符号が同じ
 13141:       int s;
 13142:       long t;
 13143:       return (xf >= 0 ? 1 : -1) * ((s = this.epp - y.epp) != 0 ? s >= 0 ? 1 : -1 :
 13144:                                    (t = this.dvl - y.dvl) != 0L ? t >= 0L ? 1 : -1 :
 13145:                                    (t = (this.cvl >>> 1) - (y.cvl >>> 1)) != 0L ? t >= 0L ? 1 : -1 :
 13146:                                    0) < 0;
 13147:     }  //efp.lt(EFP)
 13148: 
 13149:     //------------------------------------------------------------------------
 13150:     //x = x.max (y)
 13151:     //  x=max(x,y)
 13152:     //z = z.max (x, y)
 13153:     //  z=max(x,y)
 13154:     //  最大値
 13155:     //
 13156:     //  どちらかがNaNのときはNaN
 13157:     //  -0<+0とみなされる
 13158:     //
 13159:     public final EFP max (EFP y) {
 13160:       return this.max (this, y);
 13161:     }  //efp.max(EFP)
 13162:     public final EFP max (EFP x, EFP y) {
 13163:       if ((x.flg | y.flg) << 3 < 0) {  //どちらかがNaN
 13164:         this.flg = N;  //NaN
 13165:       } else if (x.compareTo (y) >= 0) {  //両方NaN以外でx>=y。cmpは-0>=+0なので不可
 13166:         this.flg = x.flg;  //x
 13167:         this.epp = x.epp;
 13168:         this.dvl = x.dvl;
 13169:         this.cvl = x.cvl;
 13170:       } else {  //両方NaN以外でx<y
 13171:         this.flg = y.flg;  //y
 13172:         this.epp = y.epp;
 13173:         this.dvl = y.dvl;
 13174:         this.cvl = y.cvl;
 13175:       }
 13176:       return this;
 13177:     }  //efp.max(EFP)
 13178: 
 13179:     //------------------------------------------------------------------------
 13180:     //x = x.min (y)
 13181:     //  x=min(x,y)
 13182:     //z = z.min (x, y)
 13183:     //  z=min(x,y)
 13184:     //  最小値
 13185:     //
 13186:     //  どちらかがNaNのときはNaN
 13187:     //  -0<+0とみなされる
 13188:     //
 13189:     public final EFP min (EFP y) {
 13190:       return this.min (this, y);
 13191:     }  //efp.min(EFP)
 13192:     public final EFP min (EFP x, EFP y) {
 13193:       if ((x.flg | y.flg) << 3 < 0) {  //どちらかがNaN
 13194:         this.flg = N;  //NaN
 13195:       } else if (x.compareTo (y) <= 0) {  //両方NaN以外でx<=y。cmpは+0<=-0なので不可
 13196:         this.flg = x.flg;  //x
 13197:         this.epp = x.epp;
 13198:         this.dvl = x.dvl;
 13199:         this.cvl = x.cvl;
 13200:       } else {  //両方NaN以外でx<y
 13201:         this.flg = y.flg;  //y
 13202:         this.epp = y.epp;
 13203:         this.dvl = y.dvl;
 13204:         this.cvl = y.cvl;
 13205:       }
 13206:       return this;
 13207:     }  //efp.min(EFP)
 13208: 
 13209:     //------------------------------------------------------------------------
 13210:     //x = x.mul (y)
 13211:     //  x*=y
 13212:     //z = z.mul (x, y)
 13213:     //  z=x*y
 13214:     //  乗算
 13215:     //
 13216:     //  (xn/xd)*(yn/yd)
 13217:     //    =(xn*yn)/(xd*yd)
 13218:     //
 13219:     //  分割統治法による多倍長乗算
 13220:     //    2分割
 13221:     //      (a*x+b)*(c*x+d) = a*c*x^2+(a*d+b*c)*x+b*d
 13222:     //                        (1)      (2) (3)    (4)
 13223:     //                      = a*c*(x^2+x)+b*d*(x+1)-(a-b)*(c-d)*x
 13224:     //                        (1)         (2)           (3)
 13225:     //        (3)の積は(a,b),(c,d)の大小関係によって加える場合と引く場合がある
 13226:     //      桁数を2倍にしたとき乗算のコストが3倍になる
 13227:     //      桁数n=2^kのときのコストは3^k=3^log2(n)=n^log2(3)≒n^1.585
 13228:     //    3分割
 13229:     //      (a*x^2+b*x+c)*(d*x^2+e*x+f) = a*d*x^4+(a*e+b*d)*x^3+(a*f+b*e+c*d)*x^2+(b*f+c*e)*x+c*f
 13230:     //                                    (1)      (2) (3)       (4) (5) (6)       (7) (8)    (9)
 13231:     //                                  = a*d*(x^4+x^3+x^2)+b*e*(x^3+x^2+x)+c*f*(x^2+x+1)-(a-b)*(d-e)*x^3-(a-c)*(d-f)*x^2-(b-c)*(e-f)*x
 13232:     //                                    (1)               (2)             (3)               (4)             (5)             (6)
 13233:     //        (4),(5),(6)の積は(a,b,c),(d,e,f)の大小関係によって加える場合と引く場合がある
 13234:     //      桁数を3倍にしたとき乗算のコストが6倍になる
 13235:     //      桁数n=3^kのときのコストは6^k=6^log3(n)=n^log3(6)≒n^1.631
 13236:     //    分割統治法による多倍長乗算では3分割よりも2分割の方が効率が良い
 13237:     //
 13238:     //    32bit,30bit,30bitに分割する場合
 13239:     //       x^6    x^5    x^4    x^3    x^2    x^1    x^0
 13240:     //      +---------------+-------------+-------------+
 13241:     //      |      a*d      |     c*f     |     c*f     |
 13242:     //      +---------------+-------------+-------------+
 13243:     //             +---------------+-------------+
 13244:     //             |      a*d      |     c*f     |
 13245:     //             +---------------+-------------+
 13246:     //                    +---------------+
 13247:     //                    |      a*d      |
 13248:     //                    +---------------+
 13249:     //               +-------------+-------------+
 13250:     //               |     b*e     |     b*e     |
 13251:     //               +-------------+-------------+
 13252:     //                      +-------------+
 13253:     //                      |     b*e     |
 13254:     //                      +-------------+
 13255:     //             +---------------+-------------+
 13256:     //             | -(a-b)*(d-e)  |-(b-c)*(e-f) |
 13257:     //             +---------------+-------------+
 13258:     //                    +---------------+
 13259:     //                    | -(a-c)*(d-f)  |
 13260:     //                    +---------------+
 13261:     //       x^6    x^5    x^4    x^3    x^2    x^1    x^0
 13262:     //
 13263:     public final EFP mul (EFP y) {
 13264:       int xf = this.flg;
 13265:       int yf = y.flg;
 13266:       {
 13267:         int o;
 13268:         if ((o = xf | yf) << 1 != 0) {  //どちらかが±0,±Inf,NaN
 13269:           if (o << 3 < 0) {  //どちらかがNaNのときNaN
 13270:             this.flg = N;
 13271:           } else if ((o &= (Z | I)) == (Z | I)) {  //±0*±InfのときNaN
 13272:             epbFpsr |= EPB_FPSR_OE;
 13273:             if (yf << 1 < 0) {  //±Inf*±0
 13274:               epbExceptionOperandExponent = yf & M;
 13275:               epbExceptionOperandMantissa = 0x0000000000000000L;
 13276:             } else {  //±0*±Inf
 13277:               epbExceptionOperandExponent = yf & M | 0x7fff << 16;
 13278:               epbExceptionOperandMantissa = 0x0000000000000000L;
 13279:             }
 13280:             this.flg = N;
 13281:           } else {  //両方±0,NaN以外でどちらかが±Infのとき±Inf、両方±Inf,NaN以外でどちらかが±0のとき±0
 13282:             this.flg = (xf ^ yf) & M | o;
 13283:           }
 13284:           return this;
 13285:         }
 13286:       }
 13287:       //符号
 13288:       int zf = xf ^ yf;  //符号が同じならばP、異なればM。ここでセットされるのはMだけ
 13289:       //指数部
 13290:       int ze = this.epp + y.epp;
 13291:       //以下はLEN<=92bitでなければならない
 13292:       //掛ける
 13293:       //  92bitの仮数部を32bit,30bit,30bitに3分割する
 13294:       //                                                                  111111111122222222223333333333444444444455555555556666
 13295:       //                                                        0123456789012345678901234567890123456789012345678901234567890123
 13296:       //                                                 x.dvl  HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMLL
 13297:       //                                                 x.cvl  LLLLLLLLLLLLLLLLLLLLLLLLLLLL000000000000000000000000000000000000
 13298:       long xh = this.dvl;  //                               xh  HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMLL
 13299:       long yh = y.dvl;
 13300:       long xl = (xh << -2 | this.cvl >>> 2) >>> -30;  //xh<<-2  LL00000000000000000000000000000000000000000000000000000000000000
 13301:       //                                             x.cvl>>>2  00LLLLLLLLLLLLLLLLLLLLLLLLLLLL0000000000000000000000000000000000
 13302:       //                                      xh<<-2|x.cvl>>>2  LLLLLLLLLLLLLLLLLLLLLLLLLLLLLL0000000000000000000000000000000000
 13303:       //                                                    xl  0000000000000000000000000000000000LLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
 13304:       long yl = (yh << -2 | y.cvl >>> 2) >>> -30;
 13305:       long xm = xh << 32 >>> -30;  //                   xh<<32  MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMLL00000000000000000000000000000000
 13306:       //                                                    xm  0000000000000000000000000000000000MMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
 13307:       long ym = yh << 32 >>> -30;
 13308:       xh >>>= 32;  //                                       xh  00000000000000000000000000000000HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
 13309:       yh >>>= 32;
 13310:       //           xh xm xl
 13311:       //  *        yh ym yl
 13312:       //  -----------------
 13313:       //              xl*yl
 13314:       //           xl*ym
 13315:       //           yl*xm
 13316:       //        xl*yh
 13317:       //        yl*xh
 13318:       //        xm*ym
 13319:       //     xm*yh
 13320:       //     ym*xh
 13321:       //  xh*yh
 13322:       //  -----------------
 13323:       //  zd    zc    zb
 13324:       long zb = xl * yl;  //60bit
 13325:       long zc = xl * yh + yl * xh + xm * ym;  //62bit*2+60bit
 13326:       long zd = xh * yh;  //64bit
 13327:       xl *= ym;  //xl*ym。60bit
 13328:       yl *= xm;  //yl*xm。60bit
 13329:       xm *= yh;  //xm*yh。62bit
 13330:       ym *= xh;  //ym*xh。62bit
 13331:       zb += (xl << -30 >>> 4) + (yl << -30 >>> 4);  //xl*ymの下位30bit<<30,yl*xmの下位30bit<<30。60bit*3
 13332:       zc += (xm << -30 >>> 4) + (ym << -30 >>> 4);  //xm*yhの下位30bit<<30,ym*xhの下位30bit<<30。62bit*2+60bit*3
 13333:       zc += (xl >>> 30) + (yl >>> 30) + (zb >>> -4);  //xl*ymの上位30bit,yl*xmの上位30bit,zbからのキャリー4bit。62bit*2+60bit*3+30bit*2+4bitで64bitに収まる
 13334:       zd += (xm >>> 30) + (ym >>> 30) + (zc >>> -4);  //xm*yhの上位32bit,ym*xhの上位32bit,zcからのキャリー4bit。積は92*2=184bitで64bit,60bit,60bitに収まる
 13335:       zb <<= 4;  //sticky bitにゴミが残っていると困るので使用済みのキャリーを押し出す
 13336:       zc <<= 4;  //使用済みのキャリーを押し出してzdとzcの隙間を詰める。zcの下位4bitに隙間ができるがsticky bitなのでzbを詰める必要はない
 13337:       //正規化する
 13338:       //  zdのMSBに隙間がないときは整数部が1+1=2bitになっているので指数部を1増やす
 13339:       if (zd < 0L) {
 13340:         ze++;
 13341:       } else {
 13342:         zd = zd << 1 | zc >>> -1;
 13343:         zc <<= 1;
 13344:       }
 13345:       return this.finish2 (zf, ze, zd, zc, zb);
 13346:     }  //efp.mul(EFP)
 13347:     public final EFP imul (EFP y) {
 13348:       int xf = this.flg;
 13349:       int yf = y.flg;
 13350:       {
 13351:         int o;
 13352:         if ((o = xf | yf) << 1 != 0) {  //どちらかが±0,±Inf,NaN
 13353:           if (o << 3 < 0) {  //どちらかがNaNのときNaN
 13354:             this.flg = N;
 13355:           } else if ((o &= (Z | I)) == (Z | I)) {  //±0*±InfのときNaN
 13356:             epbFpsr |= EPB_FPSR_OE;
 13357:             if (yf << 1 < 0) {  //±Inf*±0
 13358:               epbExceptionOperandExponent = yf & M;
 13359:               epbExceptionOperandMantissa = 0x0000000000000000L;
 13360:             } else {  //±0*±Inf
 13361:               epbExceptionOperandExponent = yf & M | 0x7fff << 16;
 13362:               epbExceptionOperandMantissa = 0x0000000000000000L;
 13363:             }
 13364:             this.flg = N;
 13365:           } else {  //両方±0,NaN以外でどちらかが±Infのとき±Inf、両方±Inf,NaN以外でどちらかが±0のとき±0
 13366:             this.flg = (xf ^ yf) & M | o;
 13367:           }
 13368:           return this;
 13369:         }
 13370:       }
 13371:       //符号
 13372:       int zf = xf ^ yf;  //符号が同じならばP、異なればM。ここでセットされるのはMだけ
 13373:       //指数部
 13374:       int ze = this.epp + y.epp;
 13375:       //以下はLEN<=92bitでなければならない
 13376:       //掛ける
 13377:       //  92bitの仮数部を32bit,30bit,30bitに3分割する
 13378:       //                                                                  111111111122222222223333333333444444444455555555556666
 13379:       //                                                        0123456789012345678901234567890123456789012345678901234567890123
 13380:       //                                                 x.dvl  HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMLL
 13381:       //                                                 x.cvl  LLLLLLLLLLLLLLLLLLLLLLLLLLLL000000000000000000000000000000000000
 13382:       long xh = this.dvl;  //                               xh  HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMLL
 13383:       long yh = y.dvl;
 13384:       long xl = (xh << -2 | this.cvl >>> 2) >>> -30;  //xh<<-2  LL00000000000000000000000000000000000000000000000000000000000000
 13385:       //                                             x.cvl>>>2  00LLLLLLLLLLLLLLLLLLLLLLLLLLLL0000000000000000000000000000000000
 13386:       //                                      xh<<-2|x.cvl>>>2  LLLLLLLLLLLLLLLLLLLLLLLLLLLLLL0000000000000000000000000000000000
 13387:       //                                                    xl  0000000000000000000000000000000000LLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
 13388:       long yl = (yh << -2 | y.cvl >>> 2) >>> -30;
 13389:       long xm = xh << 32 >>> -30;  //                   xh<<32  MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMLL00000000000000000000000000000000
 13390:       //                                                    xm  0000000000000000000000000000000000MMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
 13391:       long ym = yh << 32 >>> -30;
 13392:       xh >>>= 32;  //                                       xh  00000000000000000000000000000000HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
 13393:       yh >>>= 32;
 13394:       //           xh xm xl
 13395:       //  *        yh ym yl
 13396:       //  -----------------
 13397:       //              xl*yl
 13398:       //           xl*ym
 13399:       //           yl*xm
 13400:       //        xl*yh
 13401:       //        yl*xh
 13402:       //        xm*ym
 13403:       //     xm*yh
 13404:       //     ym*xh
 13405:       //  xh*yh
 13406:       //  -----------------
 13407:       //  zd    zc    zb
 13408:       long zb = xl * yl;  //60bit
 13409:       long zc = xl * yh + yl * xh + xm * ym;  //62bit*2+60bit
 13410:       long zd = xh * yh;  //64bit
 13411:       xl *= ym;  //xl*ym。60bit
 13412:       yl *= xm;  //yl*xm。60bit
 13413:       xm *= yh;  //xm*yh。62bit
 13414:       ym *= xh;  //ym*xh。62bit
 13415:       zb += (xl << -30 >>> 4) + (yl << -30 >>> 4);  //xl*ymの下位30bit<<30,yl*xmの下位30bit<<30。60bit*3
 13416:       zc += (xm << -30 >>> 4) + (ym << -30 >>> 4);  //xm*yhの下位30bit<<30,ym*xhの下位30bit<<30。62bit*2+60bit*3
 13417:       zc += (xl >>> 30) + (yl >>> 30) + (zb >>> -4);  //xl*ymの上位30bit,yl*xmの上位30bit,zbからのキャリー4bit。62bit*2+60bit*3+30bit*2+4bitで64bitに収まる
 13418:       zd += (xm >>> 30) + (ym >>> 30) + (zc >>> -4);  //xm*yhの上位32bit,ym*xhの上位32bit,zcからのキャリー4bit。積は92*2=184bitで64bit,60bit,60bitに収まる
 13419:       zb <<= 4;  //sticky bitにゴミが残っていると困るので使用済みのキャリーを押し出す
 13420:       zc <<= 4;  //使用済みのキャリーを押し出してzdとzcの隙間を詰める。zcの下位4bitに隙間ができるがsticky bitなのでzbを詰める必要はない
 13421:       //正規化する
 13422:       //  zdのMSBに隙間がないときは整数部が1+1=2bitになっているので指数部を1増やす
 13423:       if (zd < 0L) {
 13424:         ze++;
 13425:       } else {
 13426:         zd = zd << 1 | zc >>> -1;
 13427:         zc <<= 1;
 13428:       }
 13429:       return this.ifinish (zf, ze, zd, zc, zb);
 13430:     }  //efp.imul(EFP)
 13431:     public final EFP mul (EFP x, EFP y) {  //11.7
 13432:       int xf = x.flg;
 13433:       int yf = y.flg;
 13434:       {
 13435:         int o;
 13436:         if ((o = xf | yf) << 1 != 0) {  //どちらかが±0,±Inf,NaN
 13437:           if (o << 3 < 0) {  //どちらかがNaNのときNaN
 13438:             this.flg = N;
 13439:           } else if ((o &= (Z | I)) == (Z | I)) {  //±0*±InfのときNaN
 13440:             epbFpsr |= EPB_FPSR_OE;
 13441:             if (yf << 1 < 0) {  //±Inf*±0
 13442:               epbExceptionOperandExponent = yf & M;
 13443:               epbExceptionOperandMantissa = 0x0000000000000000L;
 13444:             } else {  //±0*±Inf
 13445:               epbExceptionOperandExponent = yf & M | 0x7fff << 16;
 13446:               epbExceptionOperandMantissa = 0x0000000000000000L;
 13447:             }
 13448:             this.flg = N;
 13449:           } else {  //両方±0,NaN以外でどちらかが±Infのとき±Inf、両方±Inf,NaN以外でどちらかが±0のとき±0
 13450:             this.flg = (xf ^ yf) & M | o;
 13451:           }
 13452:           return this;
 13453:         }
 13454:       }
 13455:       //符号
 13456:       int zf = xf ^ yf;  //符号が同じならばP、異なればM。ここでセットされるのはMだけ
 13457:       //指数部
 13458:       int ze = x.epp + y.epp;
 13459:       //以下はLEN<=92bitでなければならない
 13460:       //掛ける
 13461:       //  92bitの仮数部を32bit,30bit,30bitに3分割する
 13462:       //                                                                  111111111122222222223333333333444444444455555555556666
 13463:       //                                                        0123456789012345678901234567890123456789012345678901234567890123
 13464:       //                                                 x.dvl  HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMLL
 13465:       //                                                 x.cvl  LLLLLLLLLLLLLLLLLLLLLLLLLLLL000000000000000000000000000000000000
 13466:       long xh = x.dvl;  //                                  xh  HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMLL
 13467:       long yh = y.dvl;
 13468:       long xl = (xh << -2 | x.cvl >>> 2) >>> -30;  //   xh<<-2  LL00000000000000000000000000000000000000000000000000000000000000
 13469:       //                                             x.cvl>>>2  00LLLLLLLLLLLLLLLLLLLLLLLLLLLL0000000000000000000000000000000000
 13470:       //                                      xh<<-2|x.cvl>>>2  LLLLLLLLLLLLLLLLLLLLLLLLLLLLLL0000000000000000000000000000000000
 13471:       //                                                    xl  0000000000000000000000000000000000LLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
 13472:       long yl = (yh << -2 | y.cvl >>> 2) >>> -30;
 13473:       long xm = xh << 32 >>> -30;  //                   xh<<32  MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMLL00000000000000000000000000000000
 13474:       //                                                    xm  0000000000000000000000000000000000MMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
 13475:       long ym = yh << 32 >>> -30;
 13476:       xh >>>= 32;  //                                       xh  00000000000000000000000000000000HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
 13477:       yh >>>= 32;
 13478:       //           xh xm xl
 13479:       //  *        yh ym yl
 13480:       //  -----------------
 13481:       //              xl*yl
 13482:       //           xl*ym
 13483:       //           yl*xm
 13484:       //        xl*yh
 13485:       //        yl*xh
 13486:       //        xm*ym
 13487:       //     xm*yh
 13488:       //     ym*xh
 13489:       //  xh*yh
 13490:       //  -----------------
 13491:       //  zd    zc    zb
 13492:       long zb = xl * yl;  //60bit
 13493:       long zc = xl * yh + yl * xh + xm * ym;  //62bit*2+60bit
 13494:       long zd = xh * yh;  //64bit
 13495:       xl *= ym;  //xl*ym。60bit
 13496:       yl *= xm;  //yl*xm。60bit
 13497:       xm *= yh;  //xm*yh。62bit
 13498:       ym *= xh;  //ym*xh。62bit
 13499:       zb += (xl << -30 >>> 4) + (yl << -30 >>> 4);  //xl*ymの下位30bit<<30,yl*xmの下位30bit<<30。60bit*3
 13500:       zc += (xm << -30 >>> 4) + (ym << -30 >>> 4);  //xm*yhの下位30bit<<30,ym*xhの下位30bit<<30。62bit*2+60bit*3
 13501:       zc += (xl >>> 30) + (yl >>> 30) + (zb >>> -4);  //xl*ymの上位30bit,yl*xmの上位30bit,zbからのキャリー4bit。62bit*2+60bit*3+30bit*2+4bitで64bitに収まる
 13502:       zd += (xm >>> 30) + (ym >>> 30) + (zc >>> -4);  //xm*yhの上位32bit,ym*xhの上位32bit,zcからのキャリー4bit。積は92*2=184bitで64bit,60bit,60bitに収まる
 13503:       zb <<= 4;  //sticky bitにゴミが残っていると困るので使用済みのキャリーを押し出す
 13504:       zc <<= 4;  //使用済みのキャリーを押し出してzdとzcの隙間を詰める。zcの下位4bitに隙間ができるがsticky bitなのでzbを詰める必要はない
 13505:       //正規化する
 13506:       //  zdのMSBに隙間がないときは整数部が1+1=2bitになっているので指数部を1増やす
 13507:       if (zd < 0L) {
 13508:         ze++;
 13509:       } else {
 13510:         zd = zd << 1 | zc >>> -1;
 13511:         zc <<= 1;
 13512:       }
 13513:       return this.finish2 (zf, ze, zd, zc, zb);
 13514:     }  //efp.mul(EFP,EFP)
 13515:     public final EFP imul (EFP x, EFP y) {  //11.7
 13516:       int xf = x.flg;
 13517:       int yf = y.flg;
 13518:       {
 13519:         int o;
 13520:         if ((o = xf | yf) << 1 != 0) {  //どちらかが±0,±Inf,NaN
 13521:           if (o << 3 < 0) {  //どちらかがNaNのときNaN
 13522:             this.flg = N;
 13523:           } else if ((o &= (Z | I)) == (Z | I)) {  //±0*±InfのときNaN
 13524:             epbFpsr |= EPB_FPSR_OE;
 13525:             if (yf << 1 < 0) {  //±Inf*±0
 13526:               epbExceptionOperandExponent = yf & M;
 13527:               epbExceptionOperandMantissa = 0x0000000000000000L;
 13528:             } else {  //±0*±Inf
 13529:               epbExceptionOperandExponent = yf & M | 0x7fff << 16;
 13530:               epbExceptionOperandMantissa = 0x0000000000000000L;
 13531:             }
 13532:             this.flg = N;
 13533:           } else {  //両方±0,NaN以外でどちらかが±Infのとき±Inf、両方±Inf,NaN以外でどちらかが±0のとき±0
 13534:             this.flg = (xf ^ yf) & M | o;
 13535:           }
 13536:           return this;
 13537:         }
 13538:       }
 13539:       //符号
 13540:       int zf = xf ^ yf;  //符号が同じならばP、異なればM。ここでセットされるのはMだけ
 13541:       //指数部
 13542:       int ze = x.epp + y.epp;
 13543:       //以下はLEN<=92bitでなければならない
 13544:       //掛ける
 13545:       //  92bitの仮数部を32bit,30bit,30bitに3分割する
 13546:       //                                                                  111111111122222222223333333333444444444455555555556666
 13547:       //                                                        0123456789012345678901234567890123456789012345678901234567890123
 13548:       //                                                 x.dvl  HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMLL
 13549:       //                                                 x.cvl  LLLLLLLLLLLLLLLLLLLLLLLLLLLL000000000000000000000000000000000000
 13550:       long xh = x.dvl;  //                                  xh  HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMLL
 13551:       long yh = y.dvl;
 13552:       long xl = (xh << -2 | x.cvl >>> 2) >>> -30;  //   xh<<-2  LL00000000000000000000000000000000000000000000000000000000000000
 13553:       //                                             x.cvl>>>2  00LLLLLLLLLLLLLLLLLLLLLLLLLLLL0000000000000000000000000000000000
 13554:       //                                      xh<<-2|x.cvl>>>2  LLLLLLLLLLLLLLLLLLLLLLLLLLLLLL0000000000000000000000000000000000
 13555:       //                                                    xl  0000000000000000000000000000000000LLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
 13556:       long yl = (yh << -2 | y.cvl >>> 2) >>> -30;
 13557:       long xm = xh << 32 >>> -30;  //                   xh<<32  MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMLL00000000000000000000000000000000
 13558:       //                                                    xm  0000000000000000000000000000000000MMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
 13559:       long ym = yh << 32 >>> -30;
 13560:       xh >>>= 32;  //                                       xh  00000000000000000000000000000000HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
 13561:       yh >>>= 32;
 13562:       //           xh xm xl
 13563:       //  *        yh ym yl
 13564:       //  -----------------
 13565:       //              xl*yl
 13566:       //           xl*ym
 13567:       //           yl*xm
 13568:       //        xl*yh
 13569:       //        yl*xh
 13570:       //        xm*ym
 13571:       //     xm*yh
 13572:       //     ym*xh
 13573:       //  xh*yh
 13574:       //  -----------------
 13575:       //  zd    zc    zb
 13576:       long zb = xl * yl;  //60bit
 13577:       long zc = xl * yh + yl * xh + xm * ym;  //62bit*2+60bit
 13578:       long zd = xh * yh;  //64bit
 13579:       xl *= ym;  //xl*ym。60bit
 13580:       yl *= xm;  //yl*xm。60bit
 13581:       xm *= yh;  //xm*yh。62bit
 13582:       ym *= xh;  //ym*xh。62bit
 13583:       zb += (xl << -30 >>> 4) + (yl << -30 >>> 4);  //xl*ymの下位30bit<<30,yl*xmの下位30bit<<30。60bit*3
 13584:       zc += (xm << -30 >>> 4) + (ym << -30 >>> 4);  //xm*yhの下位30bit<<30,ym*xhの下位30bit<<30。62bit*2+60bit*3
 13585:       zc += (xl >>> 30) + (yl >>> 30) + (zb >>> -4);  //xl*ymの上位30bit,yl*xmの上位30bit,zbからのキャリー4bit。62bit*2+60bit*3+30bit*2+4bitで64bitに収まる
 13586:       zd += (xm >>> 30) + (ym >>> 30) + (zc >>> -4);  //xm*yhの上位32bit,ym*xhの上位32bit,zcからのキャリー4bit。積は92*2=184bitで64bit,60bit,60bitに収まる
 13587:       zb <<= 4;  //sticky bitにゴミが残っていると困るので使用済みのキャリーを押し出す
 13588:       zc <<= 4;  //使用済みのキャリーを押し出してzdとzcの隙間を詰める。zcの下位4bitに隙間ができるがsticky bitなのでzbを詰める必要はない
 13589:       //正規化する
 13590:       //  zdのMSBに隙間がないときは整数部が1+1=2bitになっているので指数部を1増やす
 13591:       if (zd < 0L) {
 13592:         ze++;
 13593:       } else {
 13594:         zd = zd << 1 | zc >>> -1;
 13595:         zc <<= 1;
 13596:       }
 13597:       return this.ifinish (zf, ze, zd, zc, zb);
 13598:     }  //efp.imul(EFP,EFP)
 13599: 
 13600:     //------------------------------------------------------------------------
 13601:     //x = x.mul2 ()
 13602:     //  x*=2
 13603:     //y = y.mul2 (x)
 13604:     //  y=x*2
 13605:     //  2倍
 13606:     //
 13607:     //  グラフ
 13608:     //    perl -e "use Graph;$g=new Graph();$g->grid();$g->func(sub{2*$_[0]});print$g"
 13609:     //    +---------+---------+---------+---------+---------+---------**--------+---------+
 13610:     //    |                                       |                  **                   |
 13611:     //    |                                       |                 **                    |
 13612:     //    |                                       |                **                     |
 13613:     //    |                                       |               **                      |
 13614:     //    +                                       +              **                       +
 13615:     //    |                                       |             **                        |
 13616:     //    |                                       |            **                         |
 13617:     //    |                                       |           **                          |
 13618:     //    |                                       |          **                           |
 13619:     //    +                                       +         **                            +
 13620:     //    |                                       |        **                             |
 13621:     //    |                                       |       **                              |
 13622:     //    |                                       |      **                               |
 13623:     //    |                                       |     **                                |
 13624:     //    +                                       +    **                                 +
 13625:     //    |                                       |   **                                  |
 13626:     //    |                                       |  **                                   |
 13627:     //    |                                       | **                                    |
 13628:     //    |                                       |**                                     |
 13629:     //    +---------+---------+---------+---------**--------+---------+---------+---------+
 13630:     //    |                                      **                                       |
 13631:     //    |                                     **|                                       |
 13632:     //    |                                    ** |                                       |
 13633:     //    |                                   **  |                                       |
 13634:     //    +                                  **   +                                       +
 13635:     //    |                                 **    |                                       |
 13636:     //    |                                **     |                                       |
 13637:     //    |                               **      |                                       |
 13638:     //    |                              **       |                                       |
 13639:     //    +                             **        +                                       +
 13640:     //    |                            **         |                                       |
 13641:     //    |                           **          |                                       |
 13642:     //    |                          **           |                                       |
 13643:     //    |                         **            |                                       |
 13644:     //    +                        **             +                                       +
 13645:     //    |                       **              |                                       |
 13646:     //    |                      **               |                                       |
 13647:     //    |                     **                |                                       |
 13648:     //    |                    **                 |                                       |
 13649:     //    +---------+---------**--------+---------+---------+---------+---------+---------+
 13650:     //    echo read("../misc/efp.gp");eval("mul2(x)=x*2");graph(mul2) | gp -q
 13651:     //    +---------+---------+---------+---------+---------+---------*---------+---------+
 13652:     //    |                                       |                  *                    |
 13653:     //    |                                       |                 *                     |
 13654:     //    |                                       |                *                      |
 13655:     //    |                                       |               *                       |
 13656:     //    +                                       +              *                        +
 13657:     //    |                                       |             *                         |
 13658:     //    |                                       |            *                          |
 13659:     //    |                                       |           *                           |
 13660:     //    |                                       |          *                            |
 13661:     //    +                                       +         *                             +
 13662:     //    |                                       |        *                              |
 13663:     //    |                                       |       *                               |
 13664:     //    |                                       |      *                                |
 13665:     //    |                                       |     *                                 |
 13666:     //    +                                       +    *                                  +
 13667:     //    |                                       |   *                                   |
 13668:     //    |                                       |  *                                    |
 13669:     //    |                                       | *                                     |
 13670:     //    |                                       |*                                      |
 13671:     //    +---------+---------+---------+---------*---------+---------+---------+---------+
 13672:     //    |                                      *|                                       |
 13673:     //    |                                     * |                                       |
 13674:     //    |                                    *  |                                       |
 13675:     //    |                                   *   |                                       |
 13676:     //    +                                  *    +                                       +
 13677:     //    |                                 *     |                                       |
 13678:     //    |                                *      |                                       |
 13679:     //    |                               *       |                                       |
 13680:     //    |                              *        |                                       |
 13681:     //    +                             *         +                                       +
 13682:     //    |                            *          |                                       |
 13683:     //    |                           *           |                                       |
 13684:     //    |                          *            |                                       |
 13685:     //    |                         *             |                                       |
 13686:     //    +                        *              +                                       +
 13687:     //    |                       *               |                                       |
 13688:     //    |                      *                |                                       |
 13689:     //    |                     *                 |                                       |
 13690:     //    |                    *                  |                                       |
 13691:     //    +---------+---------*---------+---------+---------+---------+---------+---------+
 13692:     //
 13693:     public final EFP mul2 () {
 13694:       return this.finish (this.flg, this.epp + 1, this.dvl, this.cvl, 0L);
 13695:     }  //efp.mul2()
 13696:     public final EFP imul2 () {
 13697:       this.epp++;
 13698:       return this;
 13699:     }  //efp.imul2()
 13700:     public final EFP mul2 (EFP x) {
 13701:       return this.finish (x.flg, x.epp + 1, x.dvl, x.cvl, 0L);
 13702:     }  //efp.mul2(EFP)
 13703:     public final EFP imul2 (EFP x) {
 13704:       this.flg = x.flg;
 13705:       this.epp = x.epp + 1;
 13706:       this.dvl = x.dvl;
 13707:       this.cvl = x.cvl;
 13708:       return this;
 13709:     }  //efp.imul2(EFP)
 13710: 
 13711:     //------------------------------------------------------------------------
 13712:     //x = x.mul3 ()
 13713:     //  x*=3
 13714:     //y = y.mul3 (x)
 13715:     //  y=x*3
 13716:     //  3倍
 13717:     //
 13718:     //  グラフ
 13719:     //    perl -e "use Graph;$g=new Graph();$g->grid();$g->func(sub{3*$_[0]});print$g"
 13720:     //    echo read("../misc/efp.gp");eval("mul3(x)=x*3");graph(mul3) | gp -q
 13721:     //    +---------+---------+---------+---------+---------+--**-----+---------+---------+
 13722:     //    |                                       |           **                          |
 13723:     //    |                                       |           *                           |
 13724:     //    |                                       |          **                           |
 13725:     //    |                                       |         **                            |
 13726:     //    +                                       +         *                             +
 13727:     //    |                                       |        **                             |
 13728:     //    |                                       |       **                              |
 13729:     //    |                                       |       *                               |
 13730:     //    |                                       |      **                               |
 13731:     //    +                                       +     **                                +
 13732:     //    |                                       |     *                                 |
 13733:     //    |                                       |    **                                 |
 13734:     //    |                                       |   **                                  |
 13735:     //    |                                       |   *                                   |
 13736:     //    +                                       +  **                                   +
 13737:     //    |                                       | **                                    |
 13738:     //    |                                       | *                                     |
 13739:     //    |                                       |**                                     |
 13740:     //    |                                       **                                      |
 13741:     //    +---------+---------+---------+---------*---------+---------+---------+---------+
 13742:     //    |                                      **                                       |
 13743:     //    |                                     **|                                       |
 13744:     //    |                                     * |                                       |
 13745:     //    |                                    ** |                                       |
 13746:     //    +                                   **  +                                       +
 13747:     //    |                                   *   |                                       |
 13748:     //    |                                  **   |                                       |
 13749:     //    |                                 **    |                                       |
 13750:     //    |                                 *     |                                       |
 13751:     //    +                                **     +                                       +
 13752:     //    |                               **      |                                       |
 13753:     //    |                               *       |                                       |
 13754:     //    |                              **       |                                       |
 13755:     //    |                             **        |                                       |
 13756:     //    +                             *         +                                       +
 13757:     //    |                            **         |                                       |
 13758:     //    |                           **          |                                       |
 13759:     //    |                           *           |                                       |
 13760:     //    |                          **           |                                       |
 13761:     //    +---------+---------+-----**--+---------+---------+---------+---------+---------+
 13762:     //
 13763:     public final EFP mul3 () {
 13764:       return this.muli (this, 3);
 13765:     }  //efp.mul3()
 13766:     public final EFP mul3 (EFP x) {
 13767:       //return this.muli (x, 3);  //x*3
 13768:       int xf = x.flg;
 13769:       if (xf << 1 != 0) {  //±0,±Inf,NaN
 13770:         this.flg = xf;
 13771:         return this;
 13772:       }
 13773:       //±0,±Inf,NaN以外
 13774:       int ze = x.epp + 1;
 13775:       long zd = x.dvl;
 13776:       long zc = x.cvl;
 13777:       long t = zc;
 13778:       zc += (zc >>> 1);  //bit63が1→0のときcから溢れている
 13779:       zd += (zd >>> 1) + ((zc & ~t) >>> -1);  //bit63が1→0のときdから溢れている
 13780:       if (zd >= 0L) {  //2bit増えた
 13781:         zc = zd << -1 | zc >>> 1;
 13782:         zd = MSB | zd >>> 1;
 13783:         ze++;
 13784:       }
 13785:       return this.finish (xf, ze, zd, zc, 0L);
 13786:     }  //efp.mul3(EFP)
 13787: 
 13788:     //------------------------------------------------------------------------
 13789:     //x = x.muli (n)
 13790:     //  x*=n
 13791:     //z = z.muli (x, n)
 13792:     //  z=x*n
 13793:     //  int乗算
 13794:     //
 13795:     public final EFP muli (int n) {
 13796:       return this.muli (this, n);
 13797:     }  //efp.muli(int)
 13798:     public final EFP muli (EFP x, int n) {
 13799:       //return this.mul (x, new EFP (n));  //x*n
 13800:       int xf = x.flg;
 13801:       if (n == 0) {  //0倍
 13802:         this.flg = (xf & (I | N)) != 0 ? N : xf | Z;  //±Inf*0=NaN, NaN*0=NaN, ±0*0=±0, ±x*0=±0
 13803:         return this;
 13804:       }
 13805:       if (xf << 1 != 0) {  //xが±0,±Inf,NaN
 13806:         this.flg = xf << 3 < 0 ? N : xf ^ (n & M);  //NaN*±n=NaN, ±Inf*±n=±Inf, ±0*±n=±0
 13807:         return this;
 13808:       }
 13809:       //両方±0,±Inf,NaN以外
 13810:       int ze = x.epp;
 13811:       long zd = x.dvl;
 13812:       long zc = x.cvl;
 13813:       if (n < 0) {  //乗数が負
 13814:         xf ^= M;
 13815:         if (n == 0x80000000) {
 13816:           ze += 31;
 13817:           if ((short) ze != ze) {  //オーバーフロー
 13818:             epbFpsr |= EPB_FPSR_OF;  //オーバーフロー
 13819:             epbExceptionOperandExponent = xf;
 13820:             epbExceptionOperandMantissa = zd;
 13821:             return this.sete (OVFL_RESULTS[epbRoundingPrec << 3 | epbRoundingMode << 1 | xf >>> 31]).finish ();  //±Inf
 13822:           }
 13823:           this.flg = xf;
 13824:           this.epp = ze;
 13825:           this.dvl = zd;
 13826:           this.cvl = zc;
 13827:           return this;
 13828:         }
 13829:         n = -n;
 13830:       }
 13831:       if (n > 1) {
 13832:         long y = (long) n;  //0x80000000は処理済みなので0xffffffffLでマスクする必要はない
 13833:         //掛ける
 13834:         //     x0 x1 x2
 13835:         //  *        y0
 13836:         //  -----------
 13837:         //        x2*y0
 13838:         //     x1*y0
 13839:         //  x0*y0
 13840:         //  -----------
 13841:         //     zd    zc
 13842:         zc = (zc >>> 32) * y;
 13843:         long t = (zd & 0xffffffffL) * y + (zc >>> 32);
 13844:         zc = t << 32 | (zc & 0xffffffffL);
 13845:         zd = (zd >>> 32) * y + (t >>> 32);
 13846:         //正規化する
 13847:         int o = Long.numberOfLeadingZeros (zd);
 13848:         ze += 32 - o;
 13849:         if (o > 0) {
 13850:           zd = zd << o | zc >>> -o;
 13851:           zc <<= o;
 13852:         }
 13853:       }
 13854:       return this.finish (xf, ze, zd, zc, 0L);
 13855:     }  //efp.muli(EFP,int)
 13856: 
 13857:     //------------------------------------------------------------------------
 13858:     //x = x.mulpi ()
 13859:     //  x*=pi
 13860:     //y = y.mulpi (x)
 13861:     //  y=x*pi
 13862:     //  円周率倍
 13863:     //
 13864:     //  グラフ
 13865:     //    perl -e "use Graph;$g=new Graph();$g->grid();$g->func(sub{4*atan2(1,1)*$_[0]});print$g"
 13866:     //    echo read("../misc/efp.gp");eval("mulpi(x)=x*Pi");graph(mulpi) | gp -q
 13867:     //    +---------+---------+---------+---------+---------+-**------+---------+---------+
 13868:     //    |                                       |           *                           |
 13869:     //    |                                       |          **                           |
 13870:     //    |                                       |          *                            |
 13871:     //    |                                       |         **                            |
 13872:     //    +                                       +        **                             +
 13873:     //    |                                       |        *                              |
 13874:     //    |                                       |       **                              |
 13875:     //    |                                       |      **                               |
 13876:     //    |                                       |      *                                |
 13877:     //    +                                       +     **                                +
 13878:     //    |                                       |    **                                 |
 13879:     //    |                                       |    *                                  |
 13880:     //    |                                       |   **                                  |
 13881:     //    |                                       |   *                                   |
 13882:     //    +                                       +  **                                   +
 13883:     //    |                                       | **                                    |
 13884:     //    |                                       | *                                     |
 13885:     //    |                                       |**                                     |
 13886:     //    |                                       **                                      |
 13887:     //    +---------+---------+---------+---------*---------+---------+---------+---------+
 13888:     //    |                                      **                                       |
 13889:     //    |                                     **|                                       |
 13890:     //    |                                     * |                                       |
 13891:     //    |                                    ** |                                       |
 13892:     //    +                                   **  +                                       +
 13893:     //    |                                   *   |                                       |
 13894:     //    |                                  **   |                                       |
 13895:     //    |                                  *    |                                       |
 13896:     //    |                                 **    |                                       |
 13897:     //    +                                **     +                                       +
 13898:     //    |                                *      |                                       |
 13899:     //    |                               **      |                                       |
 13900:     //    |                              **       |                                       |
 13901:     //    |                              *        |                                       |
 13902:     //    +                             **        +                                       +
 13903:     //    |                            **         |                                       |
 13904:     //    |                            *          |                                       |
 13905:     //    |                           **          |                                       |
 13906:     //    |                           *           |                                       |
 13907:     //    +---------+---------+------**-+---------+---------+---------+---------+---------+
 13908:     //
 13909:     public final EFP mulpi () {
 13910:       return this.mul (this, PI);
 13911:     }  //efp.mulpi()
 13912:     public final EFP mulpi (EFP x) {
 13913:       return this.mul (x, PI);  //x*pi
 13914:     }  //efp.mulpi(EFP)
 13915: 
 13916:     //------------------------------------------------------------------------
 13917:     //z = z.imulw (w, x, y)
 13918:     //  z+w=x*y
 13919:     //  倍精度乗算
 13920:     //  zはz.imul(x,y)の結果と等しい
 13921:     //  zはnearest-evenで丸められる
 13922:     //  wの符号はzの符号と同じとは限らない
 13923:     //  wの絶対値はulp(z)/2以下
 13924:     //  結果は常に正確
 13925:     //
 13926:     public final EFP imulw (EFP w, EFP x, EFP y) {
 13927:       int xf = x.flg;
 13928:       int yf = y.flg;
 13929:       {
 13930:         int o;
 13931:         if ((o = xf | yf) << 1 != 0) {  //どちらかが±0,±Inf,NaN
 13932:           if (o << 3 < 0) {  //どちらかがNaNのときNaN
 13933:             this.flg = N;
 13934:           } else if ((o &= (Z | I)) == (Z | I)) {  //±0*±InfのときNaN
 13935:             epbFpsr |= EPB_FPSR_OE;
 13936:             if (yf << 1 < 0) {  //±Inf*±0
 13937:               epbExceptionOperandExponent = yf & M;
 13938:               epbExceptionOperandMantissa = 0x0000000000000000L;
 13939:             } else {  //±0*±Inf
 13940:               epbExceptionOperandExponent = yf & M | 0x7fff << 16;
 13941:               epbExceptionOperandMantissa = 0x0000000000000000L;
 13942:             }
 13943:             this.flg = N;
 13944:           } else {  //両方±0,NaN以外でどちらかが±Infのとき±Inf、両方±Inf,NaN以外でどちらかが±0のとき±0
 13945:             this.flg = (xf ^ yf) & M | o;
 13946:           }
 13947:           w.flg = this.flg;  //zが±0,±Inf,NaNのときwも±0,±Inf,NaN
 13948:           return this;
 13949:         }
 13950:       }
 13951:       //符号
 13952:       int zf = xf ^ yf;  //符号が同じならばP、異なればM。ここでセットされるのはMだけ
 13953:       //指数部
 13954:       int ze = x.epp + y.epp;
 13955:       //以下はLEN<=92bitでなければならない
 13956:       //掛ける
 13957:       //  92bitの仮数部を32bit,30bit,30bitに3分割する
 13958:       //                                                                  111111111122222222223333333333444444444455555555556666
 13959:       //                                                        0123456789012345678901234567890123456789012345678901234567890123
 13960:       //                                                 x.dvl  HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMLL
 13961:       //                                                 x.cvl  LLLLLLLLLLLLLLLLLLLLLLLLLLLL000000000000000000000000000000000000
 13962:       long xh = x.dvl;  //                                  xh  HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMLL
 13963:       long yh = y.dvl;
 13964:       long xl = (xh << -2 | x.cvl >>> 2) >>> -30;  //   xh<<-2  LL00000000000000000000000000000000000000000000000000000000000000
 13965:       //                                             x.cvl>>>2  00LLLLLLLLLLLLLLLLLLLLLLLLLLLL0000000000000000000000000000000000
 13966:       //                                      xh<<-2|x.cvl>>>2  LLLLLLLLLLLLLLLLLLLLLLLLLLLLLL0000000000000000000000000000000000
 13967:       //                                                    xl  0000000000000000000000000000000000LLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
 13968:       long yl = (yh << -2 | y.cvl >>> 2) >>> -30;
 13969:       long xm = xh << 32 >>> -30;  //                   xh<<32  MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMLL00000000000000000000000000000000
 13970:       //                                                    xm  0000000000000000000000000000000000MMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
 13971:       long ym = yh << 32 >>> -30;
 13972:       xh >>>= 32;  //                                       xh  00000000000000000000000000000000HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
 13973:       yh >>>= 32;
 13974:       //           xh xm xl
 13975:       //  *        yh ym yl
 13976:       //  -----------------
 13977:       //              xl*yl
 13978:       //           xl*ym
 13979:       //           yl*xm
 13980:       //        xl*yh
 13981:       //        yl*xh
 13982:       //        xm*ym
 13983:       //     xm*yh
 13984:       //     ym*xh
 13985:       //  xh*yh
 13986:       //  -----------------
 13987:       //  zd    zc    zb
 13988:       long zb = xl * yl;  //60bit
 13989:       long zc = xl * yh + yl * xh + xm * ym;  //62bit*2+60bit
 13990:       long zd = xh * yh;  //64bit
 13991:       xl *= ym;  //xl*ym。60bit
 13992:       yl *= xm;  //yl*xm。60bit
 13993:       xm *= yh;  //xm*yh。62bit
 13994:       ym *= xh;  //ym*xh。62bit
 13995:       zb += (xl << -30 >>> 4) + (yl << -30 >>> 4);  //xl*ymの下位30bit<<30,yl*xmの下位30bit<<30。60bit*3
 13996:       zc += (xm << -30 >>> 4) + (ym << -30 >>> 4);  //xm*yhの下位30bit<<30,ym*xhの下位30bit<<30。62bit*2+60bit*3
 13997:       zc += (xl >>> 30) + (yl >>> 30) + (zb >>> -4);  //xl*ymの上位30bit,yl*xmの上位30bit,zbからのキャリー4bit。62bit*2+60bit*3+30bit*2+4bitで64bitに収まる
 13998:       zd += (xm >>> 30) + (ym >>> 30) + (zc >>> -4);  //xm*yhの上位32bit,ym*xhの上位32bit,zcからのキャリー4bit。積は92*2=184bitで64bit,60bit,60bitに収まる
 13999:       zb <<= 4;  //使用済みのキャリーを押し出す
 14000:       zc = zc << 4 | zb >>> -4;  //使用済みのキャリーを押し出してzbから4bit持ってくる
 14001:       zb <<= 4;
 14002:       //上位を正規化する
 14003:       //  zdのMSBに隙間がないときは整数部が1+1=2bitになっているので指数部を1増やす
 14004:       if (zd < 0L) {
 14005:         ze++;
 14006:       } else {
 14007:         zd = zd << 1 | zc >>> -1;
 14008:         zc = zc << 1 | zb >>> -1;
 14009:         zb <<= 1;
 14010:       }
 14011:       //積を上位と下位に分ける
 14012:       //                111111111122222222223333333333444444444455555555556666
 14013:       //      0123456789012345678901234567890123456789012345678901234567890123
 14014:       //  zd  HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
 14015:       //  zc  hhhhhhhhhhhhhhhhhhhhhhhhhhhhLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
 14016:       //  zb  llllllllllllllllllllllllllllllllllllllllllllllllllllllll00000000
 14017:       //  zd  HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
 14018:       //  zc  hhhhhhhhhhhhhhhhhhhhhhhhhhhh000000000000000000000000000000000000
 14019:       //  wd  LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLllllllllllllllllllllllllllll
 14020:       //  wc  llllllllllllllllllllllllllll000000000000000000000000000000000000
 14021:       int wf = zf;
 14022:       int we = ze - LEN;
 14023:       long wd = zc << LEN - 64 | zb >>> -(LEN - 64);
 14024:       long wc = zb << LEN - 64;
 14025:       zc &= -LSB;
 14026:       //zb = 0L;
 14027:       //下位の絶対値を上位の1/2ulp以下にする
 14028:       if (wd < 0L && (zc & LSB | wd << 1 | wc) != 0L) {  //guard bitが1かつLSBとround bitとsticky bitのいずれかが0でない
 14029:         //下位からLSBを引く(LSBから下位を引いて符号を反転する)
 14030:         wf ^= M;
 14031:         wc = -(wc >>> 1);
 14032:         wd = -wd - (wc >>> -1);
 14033:         wc <<= 1;
 14034:         //上位にLSBを加える
 14035:         if ((zc += LSB) == 0L && ++zd == 0L) {  //LSBを加えて、溢れたとき
 14036:           zd = MSB;  //MSBだけセットして
 14037:           ze++;  //指数部を1増やす
 14038:         }
 14039:       }
 14040:       //下位を正規化する
 14041:       if (wd >= 0L) {  //正規化が必要
 14042:         if (wd != 0L) {
 14043:           int o = Long.numberOfLeadingZeros (wd);  //1以上
 14044:           we -= o;
 14045:           wd = wd << o | wc >>> -o;  //o==0は不可
 14046:           wc <<= o;
 14047:         } else if (wc != 0L) {
 14048:           int o = Long.numberOfLeadingZeros (wc);  //0以上
 14049:           we -= 64 + o;
 14050:           wd = wc << o;
 14051:           wc = 0L;
 14052:         } else {
 14053:           wf |= Z;
 14054:         }
 14055:       }
 14056:       //結果
 14057:       if (ze > 32767) {  //オーバーフロー
 14058:         epbFpsr |= EPB_FPSR_OF;  //オーバーフロー
 14059:         epbExceptionOperandExponent = zf;
 14060:         epbExceptionOperandMantissa = zd;
 14061:         return this.sete (w.sete (OVFL_RESULTS[epbRoundingPrec << 3 | epbRoundingMode << 1 | zf >>> 31]));  //±Inf
 14062:       } else if (ze < -32768 || wf << 1 >= 0 && we < -32768) {  //アンダーフロー
 14063:         epbFpsr |= EPB_FPSR_UF;  //アンダーフロー
 14064:         epbExceptionOperandExponent = zf;
 14065:         epbExceptionOperandMantissa = zd;
 14066:         return this.sete (w.sete (UNFL_RESULTS[epbRoundingPrec << 3 | epbRoundingMode << 1 | zf >>> 31]));  //±0
 14067:       } else {
 14068:         this.flg = zf;
 14069:         this.epp = ze;
 14070:         this.dvl = zd;
 14071:         this.cvl = zc;
 14072:         w.flg = wf;
 14073:         w.epp = we;
 14074:         w.dvl = wd;
 14075:         w.cvl = wc;
 14076:         return this;
 14077:       }
 14078:     }  //efp.imulw(EFP,EFP,EFP)
 14079: 
 14080:     //------------------------------------------------------------------------
 14081:     //b = x.ne (y)
 14082:     //  b=x!=y
 14083:     //  等しくないか
 14084:     //
 14085:     //  -Inf==-Inf<-x<-0==+0<+x<+Inf==+Inf
 14086:     //
 14087:     //  NaNの扱い
 14088:     //    どちらかがNaNのときはtrueを返す
 14089:     //
 14090:     public boolean ne (EFP y) {
 14091:       int xf = this.flg;
 14092:       int yf = y.flg;
 14093:       return ((xf | yf) << 1 != 0 ?  //どちらかが±0,±Inf,NaN
 14094:               EFP_NE_TABLE[xf >>> 28] << (yf >>> 28 - 1) < 0
 14095:               : //両方±0,±Inf,NaN以外
 14096:               xf != yf || this.epp != y.epp || this.dvl != y.dvl || this.cvl != y.cvl);
 14097:     }  //efp.ne(EFP)
 14098: 
 14099:     //------------------------------------------------------------------------
 14100:     //x = x.neg ()
 14101:     //  x=-x
 14102:     //y = y.neg (x)
 14103:     //  y=-x
 14104:     //  符号反転
 14105:     //x = x.neg (b)
 14106:     //  x=b?-x:x
 14107:     //y = y.neg (x, b)
 14108:     //  y=b?-x:x
 14109:     //  条件付き符号反転
 14110:     //
 14111:     //  グラフ
 14112:     //    perl -e "use Graph;$g=new Graph();$g->grid();$g->func(sub{-$_[0]});print$g"
 14113:     //    echo read("../misc/efp.gp");eval("neg(x)=-x");graph(neg) | gp -q
 14114:     //    **--------+---------+---------+---------+---------+---------+---------+---------+
 14115:     //    |***                                    |                                       |
 14116:     //    |  ***                                  |                                       |
 14117:     //    |    ***                                |                                       |
 14118:     //    |      ***                              |                                       |
 14119:     //    +        ***                            +                                       +
 14120:     //    |          ***                          |                                       |
 14121:     //    |            ***                        |                                       |
 14122:     //    |              ***                      |                                       |
 14123:     //    |                ***                    |                                       |
 14124:     //    +                  ***                  +                                       +
 14125:     //    |                    ***                |                                       |
 14126:     //    |                      ***              |                                       |
 14127:     //    |                        ***            |                                       |
 14128:     //    |                          ***          |                                       |
 14129:     //    +                            ***        +                                       +
 14130:     //    |                              ***      |                                       |
 14131:     //    |                                ***    |                                       |
 14132:     //    |                                  ***  |                                       |
 14133:     //    |                                    ***|                                       |
 14134:     //    +---------+---------+---------+--------***--------+---------+---------+---------+
 14135:     //    |                                       |***                                    |
 14136:     //    |                                       |  ***                                  |
 14137:     //    |                                       |    ***                                |
 14138:     //    |                                       |      ***                              |
 14139:     //    +                                       +        ***                            +
 14140:     //    |                                       |          ***                          |
 14141:     //    |                                       |            ***                        |
 14142:     //    |                                       |              ***                      |
 14143:     //    |                                       |                ***                    |
 14144:     //    +                                       +                  ***                  +
 14145:     //    |                                       |                    ***                |
 14146:     //    |                                       |                      ***              |
 14147:     //    |                                       |                        ***            |
 14148:     //    |                                       |                          ***          |
 14149:     //    +                                       +                            ***        +
 14150:     //    |                                       |                              ***      |
 14151:     //    |                                       |                                ***    |
 14152:     //    |                                       |                                  ***  |
 14153:     //    |                                       |                                    ***|
 14154:     //    +---------+---------+---------+---------+---------+---------+---------+--------**
 14155:     //
 14156:     public final EFP neg () {
 14157:       return this.finish (0 <= this.flg << 3 ? this.flg ^ M : this.flg, this.epp, this.dvl, this.cvl, 0L);  //NaN以外のとき符号反転
 14158:     }  //efp.neg()
 14159:     public final EFP ineg () {
 14160:       if (0 <= this.flg << 3) {  //NaN以外のとき
 14161:         this.flg ^= M;  //符号反転
 14162:       }
 14163:       return this;
 14164:     }  //efp.ineg()
 14165:     public final EFP neg (boolean b) {
 14166:       return this.finish (b && 0 <= this.flg << 3 ? this.flg ^ M : this.flg, this.epp, this.dvl, this.cvl, 0L);  //bかつNaN以外のとき符号反転
 14167:     }  //efp.neg(boolean)
 14168:     public final EFP ineg (boolean b) {
 14169:       if (b && 0 <= this.flg << 3) {  //bかつNaN以外のとき
 14170:         this.flg ^= M;  //符号反転
 14171:       }
 14172:       return this;
 14173:     }  //efp.ineg(boolean)
 14174:     public final EFP neg (EFP x) {
 14175:       return this.finish (0 <= x.flg << 3 ? x.flg ^ M : x.flg, x.epp, x.dvl, x.cvl, 0L);  //NaN以外のとき符号反転
 14176:     }  //efp.neg(EFP)
 14177:     public final EFP ineg (EFP x) {
 14178:       this.flg = 0 <= x.flg << 3 ? x.flg ^ M : x.flg;  //NaN以外のとき符号反転
 14179:       this.epp = x.epp;
 14180:       this.dvl = x.dvl;
 14181:       this.cvl = x.cvl;
 14182:       return this;
 14183:     }  //efp.ineg(EFP)
 14184:     public final EFP neg (EFP x, boolean b) {
 14185:       return this.finish (b && 0 <= x.flg << 3 ? x.flg ^ M : x.flg, x.epp, x.dvl, x.cvl, 0L);  //bかつNaN以外のとき符号反転
 14186:     }  //efp.neg(EFP,boolean)
 14187:     public final EFP ineg (EFP x, boolean b) {
 14188:       this.flg = b && 0 <= x.flg << 3 ? x.flg ^ M : x.flg;  //bかつNaN以外のとき符号反転
 14189:       this.epp = x.epp;
 14190:       this.dvl = x.dvl;
 14191:       this.cvl = x.cvl;
 14192:       return this;
 14193:     }  //efp.ineg(EFP,boolean)
 14194: 
 14195:     //------------------------------------------------------------------------
 14196:     //x = x.negdec ()
 14197:     //  x=1-x
 14198:     //y = y.negdec (x)
 14199:     //  y=1-x
 14200:     //  1から引く(逆デクリメント)
 14201:     //
 14202:     //  x.dec(y).neg()と同じ
 14203:     //
 14204:     public final EFP negdec () {
 14205:       return this.inner ().dec ().outer ().neg (0 <= this.flg << 1);  //x-1==+0のとき1-x==+0にするため符号反転しない
 14206:     }  //efp.negdec()
 14207:     public final EFP negdec (EFP x) {
 14208:       return this.inner ().dec (x).outer ().neg (0 <= this.flg << 1);  //x-1==+0のとき1-x==+0にするため符号反転しない
 14209:     }  //efp.negdec(EFP)
 14210: 
 14211:     //------------------------------------------------------------------------
 14212:     //y = y.negset0 ()
 14213:     //  -0代入
 14214:     //
 14215:     public final EFP negset0 () {
 14216:       this.flg = M | Z;
 14217:       //this.epp = 0;
 14218:       //this.dvl = 0L;
 14219:       //this.cvl = 0L;
 14220:       return this;
 14221:     }  //efp.negset0()
 14222: 
 14223:     //------------------------------------------------------------------------
 14224:     //y = y.negset1 ()
 14225:     //  -1代入
 14226:     //
 14227:     public final EFP negset1 () {
 14228:       this.flg = M;
 14229:       this.epp = 0;
 14230:       this.dvl = MSB;
 14231:       this.cvl = 0L;
 14232:       return this;
 14233:     }  //efp.negset1()
 14234: 
 14235:     //------------------------------------------------------------------------
 14236:     //y = y.negsetinf ()
 14237:     //  -Inf代入
 14238:     //
 14239:     public final EFP negsetinf () {
 14240:       this.flg = M | I;
 14241:       //this.epp = 0;
 14242:       //this.dvl = 0L;
 14243:       //this.cvl = 0L;
 14244:       return this;
 14245:     }  //efp.negsetinf()
 14246: 
 14247:     //------------------------------------------------------------------------
 14248:     //x = x.negsub (y)
 14249:     //  x=y-x
 14250:     //  逆減算
 14251:     //
 14252:     //  x.sub(y).neg()と同じ
 14253:     //  z.negsub(x,y)はz.sub(y,x)と同じ
 14254:     //
 14255:     public final EFP negsub (EFP y) {
 14256:       int xf = y.flg;
 14257:       int xe = y.epp;
 14258:       long xd = y.dvl;
 14259:       long xc = y.cvl;
 14260:       long xb = 0L;
 14261:       int yf = this.flg;
 14262:       if ((xf | yf) << 1 != 0) {  //どちらかが±0,±Inf,NaN
 14263:         if ((xf | yf) << 3 < 0) {  //どちらかがNaNのときNaN
 14264:           this.flg = N;
 14265:           return this;
 14266:         }
 14267:         if ((xf & yf) << 2 < 0 && xf == yf) {  //両方±Infで符号が同じときNaN
 14268:           epbFpsr |= EPB_FPSR_OE;
 14269:           epbExceptionOperandExponent = yf & M | 0x7fff << 16;
 14270:           epbExceptionOperandMantissa = 0x0000000000000000L;
 14271:           this.flg = N;
 14272:           return this;
 14273:         }
 14274:         if ((xf & yf) << 1 < 0 && xf == yf) {  //両方±0で符号が同じとき
 14275:           this.flg = epbRoundingMode == EPB_MODE_RM ? M | Z : P | Z;  //RMのとき-0,それ以外は+0
 14276:           return this;
 14277:         }
 14278:         if (xf << 1 < 0 || yf << 2 < 0) {  //xが±0またはyが±Infのとき-y
 14279:           xf = yf ^ M;
 14280:           xe = this.epp;
 14281:           xd = this.dvl;
 14282:           xc = this.cvl;
 14283:         }
 14284:         //xが±Infまたはyが±0のときx
 14285:       } else {  //両方±0,±Inf,NaN以外
 14286:         //減算なのでyの符号を反転して加算する
 14287:         yf ^= M;
 14288:         long yd = this.dvl;
 14289:         long yc = this.cvl;
 14290:         int o = xe - this.epp;
 14291:         if (o < 0 || o == 0 && (xd < yd || xd == yd && xc >>> 1 < yc >>> 1)) {  //yの方が絶対値が大きい
 14292:           //xとyを入れ換える
 14293:           xf = yf;
 14294:           xe += o = -o;  //xe=this.epp
 14295:           xd = yd;
 14296:           xc = yc;
 14297:           yf = y.flg;  //後で符号を比較するときに使う
 14298:           yd = y.dvl;
 14299:           yc = y.cvl;
 14300:         }
 14301:         //xの方が絶対値が大きいか等しい
 14302:         //yを右にずらして小数点の位置を合わせる
 14303:         if (0 < o) {
 14304:           if (o <= 63) {
 14305:             xb = yc << -o;
 14306:             yc = yd << -o | yc >>> o;
 14307:             yd >>>= o;
 14308:           } else if (o == 64) {
 14309:             xb = yc;
 14310:             yc = yd;
 14311:             yd = 0L;
 14312:           } else if (o <= 127) {
 14313:             xb = yd << -o | yc;
 14314:             yc = yd >>> o;
 14315:             yd = 0L;
 14316:           } else {
 14317:             xb = yd | yc;  //絶対値減算を行うとき下位からのボローとして必要
 14318:             yc = 0L;
 14319:             yd = 0L;
 14320:           }
 14321:         }
 14322:         //絶対値加算または絶対値減算を行う
 14323:         if (xf == yf) {  //符号が同じなので絶対値加算を行う
 14324:           //yc[1]とyc[0]をsticky bitに押し出す
 14325:           xb |= yc << 62;
 14326:           //右にずらしてxd[63]を空ける
 14327:           xc = xd << 63 | xc >>> 1;
 14328:           xd >>>= 1;
 14329:           yc = yd << 63 | yc >>> 1;
 14330:           yd >>>= 1;
 14331:           //下位を右にずらしてxc[63]を空ける
 14332:           yc >>>= 1;
 14333:           xc >>>= 1;
 14334:           //足す
 14335:           xc += yc;
 14336:           xd += yd + (xc >>> 63);
 14337:           //下位を左にずらしてxc[63]を詰める
 14338:           xc <<= 1;
 14339:           //溢れの処理
 14340:           if (xd < 0L) {  //溢れたとき
 14341:             xe++;
 14342:           } else {  //溢れなかったとき
 14343:             xd = xd << 1 | xc >>> 63;  //左にずらしてxd[63]を詰める
 14344:             xc <<= 1;
 14345:           }
 14346:         } else {  //符号が異なるので絶対値減算を行う
 14347:           //yc[0]をsticky bitに押し出す
 14348:           xb |= yc << 63;
 14349:           //下位を右にずらしてxc[63]を空ける
 14350:           yc >>>= 1;
 14351:           xc >>>= 1;
 14352:           //引く
 14353:           //  xの方が絶対値が大きいか等しいので負になることはないが0になることがある
 14354:           if (xb != 0L) {
 14355:             xc--;
 14356:           }
 14357:           xc -= yc;
 14358:           xd -= yd + (xc >>> 63);
 14359:           //下位を左にずらしてxc[63]を詰める
 14360:           xc <<= 1;
 14361:           //正規化する
 14362:           if (0L <= xd) {
 14363:             if (xd != 0L) {
 14364:               xe -= o = Long.numberOfLeadingZeros (xd);
 14365:               xd = xd << o | xc >>> -o;
 14366:               xc <<= o;
 14367:             } else if (xc != 0L) {
 14368:               xe -= o = 64 + Long.numberOfLeadingZeros (xc);
 14369:               xd = xc << o;
 14370:               xc = 0L;
 14371:             } else {  //0になった
 14372:               xf = epbRoundingMode == EPB_MODE_RM ? M | Z : P | Z;  //RMのとき-0,それ以外は+0
 14373:             }
 14374:           }
 14375:         }  //if 符号が同じなので絶対値加算を行う/符号が異なるので絶対値減算を行う
 14376:       }  //if どちらかが±0,±Inf,NaN/両方±0,±Inf,NaN以外
 14377:       return this.finish (xf, xe, xd, xc, xb);
 14378:     }  //efp.negsub(EFP)
 14379:     public final EFP negsub (EFP x, EFP y) {
 14380:       int xf = y.flg;
 14381:       int xe = y.epp;
 14382:       long xd = y.dvl;
 14383:       long xc = y.cvl;
 14384:       long xb = 0L;
 14385:       int yf = x.flg;
 14386:       if ((xf | yf) << 1 != 0) {  //どちらかが±0,±Inf,NaN
 14387:         if ((xf | yf) << 3 < 0) {  //どちらかがNaNのときNaN
 14388:           this.flg = N;
 14389:           return this;
 14390:         }
 14391:         if ((xf & yf) << 2 < 0 && xf == yf) {  //両方±Infで符号が同じときNaN
 14392:           epbFpsr |= EPB_FPSR_OE;
 14393:           epbExceptionOperandExponent = yf & M | 0x7fff << 16;
 14394:           epbExceptionOperandMantissa = 0x0000000000000000L;
 14395:           this.flg = N;
 14396:           return this;
 14397:         }
 14398:         if ((xf & yf) << 1 < 0 && xf == yf) {  //両方±0で符号が同じとき
 14399:           this.flg = epbRoundingMode == EPB_MODE_RM ? M | Z : P | Z;  //RMのとき-0,それ以外は+0
 14400:           return this;
 14401:         }
 14402:         if (xf << 1 < 0 || yf << 2 < 0) {  //xが±0またはyが±Infのとき-y
 14403:           xf = yf ^ M;
 14404:           xe = x.epp;
 14405:           xd = x.dvl;
 14406:           xc = x.cvl;
 14407:         }
 14408:         //xが±Infまたはyが±0のときx
 14409:       } else {  //両方±0,±Inf,NaN以外
 14410:         //減算なのでyの符号を反転して加算する
 14411:         yf ^= M;
 14412:         long yd = x.dvl;
 14413:         long yc = x.cvl;
 14414:         int o = xe - x.epp;
 14415:         if (o < 0 || o == 0 && (xd < yd || xd == yd && xc >>> 1 < yc >>> 1)) {  //yの方が絶対値が大きい
 14416:           //xとyを入れ換える
 14417:           xf = yf;
 14418:           xe += o = -o;  //xe=x.epp
 14419:           xd = yd;
 14420:           xc = yc;
 14421:           yf = y.flg;  //後で符号を比較するときに使う
 14422:           yd = y.dvl;
 14423:           yc = y.cvl;
 14424:         }
 14425:         //xの方が絶対値が大きいか等しい
 14426:         //yを右にずらして小数点の位置を合わせる
 14427:         if (0 < o) {
 14428:           if (o <= 63) {
 14429:             xb = yc << -o;
 14430:             yc = yd << -o | yc >>> o;
 14431:             yd >>>= o;
 14432:           } else if (o == 64) {
 14433:             xb = yc;
 14434:             yc = yd;
 14435:             yd = 0L;
 14436:           } else if (o <= 127) {
 14437:             xb = yd << -o | yc;
 14438:             yc = yd >>> o;
 14439:             yd = 0L;
 14440:           } else {
 14441:             xb = yd | yc;  //絶対値減算を行うとき下位からのボローとして必要
 14442:             yc = 0L;
 14443:             yd = 0L;
 14444:           }
 14445:         }
 14446:         //絶対値加算または絶対値減算を行う
 14447:         if (xf == yf) {  //符号が同じなので絶対値加算を行う
 14448:           //yc[1]とyc[0]をsticky bitに押し出す
 14449:           xb |= yc << 62;
 14450:           //右にずらしてxd[63]を空ける
 14451:           xc = xd << 63 | xc >>> 1;
 14452:           xd >>>= 1;
 14453:           yc = yd << 63 | yc >>> 1;
 14454:           yd >>>= 1;
 14455:           //下位を右にずらしてxc[63]を空ける
 14456:           yc >>>= 1;
 14457:           xc >>>= 1;
 14458:           //足す
 14459:           xc += yc;
 14460:           xd += yd + (xc >>> 63);
 14461:           //下位を左にずらしてxc[63]を詰める
 14462:           xc <<= 1;
 14463:           //溢れの処理
 14464:           if (xd < 0L) {  //溢れたとき
 14465:             xe++;
 14466:           } else {  //溢れなかったとき
 14467:             xd = xd << 1 | xc >>> 63;  //左にずらしてxd[63]を詰める
 14468:             xc <<= 1;
 14469:           }
 14470:         } else {  //符号が異なるので絶対値減算を行う
 14471:           //yc[0]をsticky bitに押し出す
 14472:           xb |= yc << 63;
 14473:           //下位を右にずらしてxc[63]を空ける
 14474:           yc >>>= 1;
 14475:           xc >>>= 1;
 14476:           //引く
 14477:           //  xの方が絶対値が大きいか等しいので負になることはないが0になることがある
 14478:           if (xb != 0L) {
 14479:             xc--;
 14480:           }
 14481:           xc -= yc;
 14482:           xd -= yd + (xc >>> 63);
 14483:           //下位を左にずらしてxc[63]を詰める
 14484:           xc <<= 1;
 14485:           //正規化する
 14486:           if (0L <= xd) {
 14487:             if (xd != 0L) {
 14488:               xe -= o = Long.numberOfLeadingZeros (xd);
 14489:               xd = xd << o | xc >>> -o;
 14490:               xc <<= o;
 14491:             } else if (xc != 0L) {
 14492:               xe -= o = 64 + Long.numberOfLeadingZeros (xc);
 14493:               xd = xc << o;
 14494:               xc = 0L;
 14495:             } else {  //0になった
 14496:               xf = epbRoundingMode == EPB_MODE_RM ? M | Z : P | Z;  //RMのとき-0,それ以外は+0
 14497:             }
 14498:           }
 14499:         }  //if 符号が同じなので絶対値加算を行う/符号が異なるので絶対値減算を行う
 14500:       }  //if どちらかが±0,±Inf,NaN/両方±0,±Inf,NaN以外
 14501:       return this.finish (xf, xe, xd, xc, xb);
 14502:     }  //efp.negsub(EFP,EFP)
 14503: 
 14504:     //------------------------------------------------------------------------
 14505:     //x = x.nextdowne ()
 14506:     //y = y.nextdowne (x)
 14507:     //  EFPで表現できるxの-Inf側の隣接値
 14508:     //x = x.nextdownd ()
 14509:     //y = y.nextdownd (x)
 14510:     //  doubleで表現できるxよりも小さい最大の値
 14511:     //x = x.nextdownf ()
 14512:     //y = y.nextdownf (x)
 14513:     //  floatで表現できるxよりも小さい最大の値
 14514:     //x = x.nextdownx ()
 14515:     //y = y.nextdownx (x)
 14516:     //  extendedで表現できるxよりも小さい最大の値
 14517:     //x = x.nextdowny ()
 14518:     //y = y.nextdowny (x)
 14519:     //  tripleで表現できるxよりも小さい最大の値
 14520:     //x = x.nextdown (prec)
 14521:     //y = y.nextdown (x, prec)
 14522:     //  precの精度で表現できるxよりも小さい最大の値
 14523:     //
 14524:     //  nextdown(±0)=負の最小値
 14525:     //  nextdown(+Inf)=最大値
 14526:     //  nextdown(-Inf)=-Inf
 14527:     //  nextdown(NaN)=NaN
 14528:     //  nextdown(最小値)=-Inf
 14529:     //
 14530:     public final EFP nextdowne () {
 14531:       return this.nextdowne (this);
 14532:     }  //efp.nextdowne()
 14533:     public final EFP nextdowne (EFP x) {
 14534:       int xf = x.flg;
 14535:       int xe = x.epp;
 14536:       long xd = x.dvl;
 14537:       long xc = x.cvl;
 14538:       if (xf << 1 != 0) {  //±0,±Inf,NaN
 14539:         if (xf << 1 < 0) {  //±0
 14540:           xf = M;  //負の最大値
 14541:           xe = -32768;
 14542:           xd = MSB;
 14543:           xc = 0L;
 14544:         } else if (xf == (P | I)) {  //+Inf
 14545:           xf = P;  //最大値
 14546:           xe = 32767;
 14547:           xd = -1L;
 14548:           xc = -1L << 128 - LEN;
 14549:         }
 14550:         //-Inf,NaNはそのまま
 14551:       } else if (xf >= 0) {  //+x
 14552:         if (xc != 0L) {
 14553:           xc -= 1L << 128 - LEN;  //最下位bitから1を引く
 14554:         } else if (xd != MSB) {
 14555:           xc = -1L << 128 - LEN;
 14556:           xd--;
 14557:         } else if (xe > -32768) {
 14558:           xc = -1L << 128 - LEN;
 14559:           xd = -1L;
 14560:           xe--;
 14561:         } else {  //アンダーフロー
 14562:           epbFpsr |= EPB_FPSR_UF;  //アンダーフロー
 14563:           epbExceptionOperandExponent = xf | 0x3fff + 0x6000 + xe << 16;
 14564:           epbExceptionOperandMantissa = xd;
 14565:           return this.set0 ();  //+0
 14566:         }
 14567:       } else {  //-x
 14568:         if (xc != -1L << 128 - LEN) {
 14569:           xc += (1L << 128 - LEN);  //最下位bitに1を加える
 14570:         } else if (xd != -1L) {
 14571:           xc = 0L;
 14572:           xd++;
 14573:         } else if (xe < 32767) {
 14574:           xc = 0L;
 14575:           xd = MSB;
 14576:           xe++;
 14577:         } else {  //オーバーフロー
 14578:           epbFpsr |= EPB_FPSR_OF;  //オーバーフロー
 14579:           epbExceptionOperandExponent = xf;
 14580:           epbExceptionOperandMantissa = xd;
 14581:           return this.negsetinf ();  //-Inf
 14582:         }
 14583:       }
 14584:       this.flg = xf;
 14585:       this.epp = xe;
 14586:       this.dvl = xd;
 14587:       this.cvl = xc;
 14588:       return this;
 14589:     }  //efp.nextdowne(EFP)
 14590:     public final EFP nextdownd () {
 14591:       return this.nextdowne (this).roundd (EPB_MODE_RM);
 14592:     }  //efp.nextdownd()
 14593:     public final EFP nextdownd (EFP x) {
 14594:       return this.nextdowne (x).roundd (EPB_MODE_RM);
 14595:     }  //efp.nextdownd(EFP)
 14596:     public final EFP nextdownf () {
 14597:       return this.nextdowne (this).roundf (EPB_MODE_RM);
 14598:     }  //efp.nextdownf()
 14599:     public final EFP nextdownf (EFP x) {
 14600:       return this.nextdowne (x).roundf (EPB_MODE_RM);
 14601:     }  //efp.nextdownf(EFP)
 14602:     public final EFP nextdowng () {
 14603:       return this.nextdowne (this).roundg (EPB_MODE_RM);
 14604:     }  //efp.nextdowng()
 14605:     public final EFP nextdowng (EFP x) {
 14606:       return this.nextdowne (x).roundg (EPB_MODE_RM);
 14607:     }  //efp.nextdowng(EFP)
 14608:     public final EFP nextdownx () {
 14609:       return this.nextdowne (this).roundx (EPB_MODE_RM);
 14610:     }  //efp.nextdownx()
 14611:     public final EFP nextdownx (EFP x) {
 14612:       return this.nextdowne (x).roundx (EPB_MODE_RM);
 14613:     }  //efp.nextdownx(EFP)
 14614:     public final EFP nextdowny () {
 14615:       return this.nextdowne (this).roundy (EPB_MODE_RM);
 14616:     }  //efp.nextdowny()
 14617:     public final EFP nextdowny (EFP x) {
 14618:       return this.nextdowne (x).roundy (EPB_MODE_RM);
 14619:     }  //efp.nextdowny(EFP)
 14620:     public final EFP nextdown (int prec) {
 14621:       switch (prec) {
 14622:       case EPB_PREC_EXD:
 14623:         return this.nextdowne (this).roundx (EPB_MODE_RM);
 14624:       case EPB_PREC_SGL:
 14625:         return this.nextdowne (this).roundf (EPB_MODE_RM);
 14626:       case EPB_PREC_DBL:
 14627:       case EPB_PREC_DBL3:
 14628:         return this.nextdowne (this).roundd (EPB_MODE_RM);
 14629:       case EPB_PREC_TPL:
 14630:         return this.nextdowne (this).roundy (EPB_MODE_RM);
 14631:       case EPB_PREC_XSG:
 14632:         return this.nextdowne (this).roundg (EPB_MODE_RM);
 14633:       }
 14634:       return this.nextdowne (this);
 14635:     }  //efp.nextdown(int)
 14636:     public final EFP nextdown (EFP x, int prec) {
 14637:       switch (prec) {
 14638:       case EPB_PREC_EXD:
 14639:         return this.nextdowne (x).roundx (EPB_MODE_RM);
 14640:       case EPB_PREC_SGL:
 14641:         return this.nextdowne (x).roundf (EPB_MODE_RM);
 14642:       case EPB_PREC_DBL:
 14643:       case EPB_PREC_DBL3:
 14644:         return this.nextdowne (x).roundd (EPB_MODE_RM);
 14645:       case EPB_PREC_TPL:
 14646:         return this.nextdowne (x).roundy (EPB_MODE_RM);
 14647:       case EPB_PREC_XSG:
 14648:         return this.nextdowne (x).roundg (EPB_MODE_RM);
 14649:       }
 14650:       return this.nextdowne (x);
 14651:     }  //efp.nextdown(EFP,int)
 14652: 
 14653:     //------------------------------------------------------------------------
 14654:     //x = x.nextupe ()
 14655:     //y = y.nextupe (x)
 14656:     //  EFPで表現できる+Inf側の隣接値
 14657:     //x = x.nextupd ()
 14658:     //y = y.nextupd (x)
 14659:     //  doubleで表現できるxよりも大きい最小の値
 14660:     //x = x.nextupf ()
 14661:     //y = y.nextupf (x)
 14662:     //  floatで表現できるxよりも大きい最小の値
 14663:     //x = x.nextupx ()
 14664:     //y = y.nextupx (x)
 14665:     //  extendedで表現できるxよりも大きい最小の値
 14666:     //x = x.nextupy ()
 14667:     //y = y.nextupy (x)
 14668:     //  tripleで表現できるxよりも大きい最小の値
 14669:     //x = x.nextup (prec)
 14670:     //y = y.nextup (x, prec)
 14671:     //  precの精度で表現できるxよりも大きい最小の値
 14672:     //
 14673:     //  nextup(±0)=正の最小値
 14674:     //  nextup(-Inf)=最小値
 14675:     //  nextup(+Inf)=+Inf
 14676:     //  nextup(NaN)=NaN
 14677:     //  nextup(最大値)=+Inf
 14678:     //
 14679:     public final EFP nextupe () {
 14680:       return this.nextupe (this);
 14681:     }  //efp.nextupe()
 14682:     public final EFP nextupe (EFP x) {
 14683:       int xf = x.flg;
 14684:       int xe = x.epp;
 14685:       long xd = x.dvl;
 14686:       long xc = x.cvl;
 14687:       if (xf << 1 != 0) {  //±0,±Inf,NaN
 14688:         if (xf << 1 < 0) {  //±0
 14689:           xf = P;  //正の最小値
 14690:           xe = -32768;
 14691:           xd = MSB;
 14692:           xc = 0L;
 14693:         } else if (xf == (M | I)) {  //-Inf
 14694:           xf = M;  //最小値
 14695:           xe = 32767;
 14696:           xd = -1L;
 14697:           xc = -1L << 128 - LEN;
 14698:         }
 14699:         //+Inf,NaNはそのまま
 14700:       } else if (xf >= 0) {  //+x
 14701:         if (xc != -1L << 128 - LEN) {
 14702:           xc += (1L << 128 - LEN);  //最下位bitに1を加える
 14703:         } else if (xd != -1L) {
 14704:           xc = 0L;
 14705:           xd++;
 14706:         } else if (xe < 32767) {
 14707:           xc = 0L;
 14708:           xd = MSB;
 14709:           xe++;
 14710:         } else {  //オーバーフロー
 14711:           epbFpsr |= EPB_FPSR_OF;  //オーバーフロー
 14712:           epbExceptionOperandExponent = xf;
 14713:           epbExceptionOperandMantissa = xd;
 14714:           return this.setinf ();  //+Inf
 14715:         }
 14716:       } else {  //-x
 14717:         if (xc != 0L) {
 14718:           xc -= 1L << 128 - LEN;  //最下位bitから1を引く
 14719:         } else if (xd != MSB) {
 14720:           xc = -1L << 128 - LEN;
 14721:           xd--;
 14722:         } else if (xe > -32768) {
 14723:           xc = -1L << 128 - LEN;
 14724:           xd = -1L;
 14725:           xe--;
 14726:         } else {  //アンダーフロー
 14727:           epbFpsr |= EPB_FPSR_UF;  //アンダーフロー
 14728:           epbExceptionOperandExponent = xf;
 14729:           epbExceptionOperandMantissa = xd;
 14730:           return this.negset0 ();  //-0
 14731:         }
 14732:       }
 14733:       this.flg = xf;
 14734:       this.epp = xe;
 14735:       this.dvl = xd;
 14736:       this.cvl = xc;
 14737:       return this;
 14738:     }  //efp.nextupe(EFP)
 14739:     public final EFP nextupd () {
 14740:       return this.nextupe (this).roundd (EPB_MODE_RP);
 14741:     }  //efp.nextupd()
 14742:     public final EFP nextupd (EFP x) {
 14743:       return this.nextupe (x).roundd (EPB_MODE_RP);
 14744:     }  //efp.nextupd(EFP)
 14745:     public final EFP nextupf () {
 14746:       return this.nextupe (this).roundf (EPB_MODE_RP);
 14747:     }  //efp.nextupf()
 14748:     public final EFP nextupf (EFP x) {
 14749:       return this.nextupe (x).roundf (EPB_MODE_RP);
 14750:     }  //efp.nextupf(EFP)
 14751:     public final EFP nextupg () {
 14752:       return this.nextupe (this).roundg (EPB_MODE_RP);
 14753:     }  //efp.nextupg()
 14754:     public final EFP nextupg (EFP x) {
 14755:       return this.nextupe (x).roundg (EPB_MODE_RP);
 14756:     }  //efp.nextupg(EFP)
 14757:     public final EFP nextupx () {
 14758:       return this.nextupe (this).roundx (EPB_MODE_RP);
 14759:     }  //efp.nextupx()
 14760:     public final EFP nextupx (EFP x) {
 14761:       return this.nextupe (x).roundx (EPB_MODE_RP);
 14762:     }  //efp.nextupx(EFP)
 14763:     public final EFP nextupy () {
 14764:       return this.nextupe (this).roundy (EPB_MODE_RP);
 14765:     }  //efp.nextupy()
 14766:     public final EFP nextupy (EFP x) {
 14767:       return this.nextupe (x).roundy (EPB_MODE_RP);
 14768:     }  //efp.nextupy(EFP)
 14769:     public final EFP nextup (int prec) {
 14770:       switch (prec) {
 14771:       case EPB_PREC_EXD:
 14772:         return this.nextupe (this).roundx (EPB_MODE_RP);
 14773:       case EPB_PREC_SGL:
 14774:         return this.nextupe (this).roundf (EPB_MODE_RP);
 14775:       case EPB_PREC_DBL:
 14776:       case EPB_PREC_DBL3:
 14777:         return this.nextupe (this).roundd (EPB_MODE_RP);
 14778:       case EPB_PREC_TPL:
 14779:         return this.nextupe (this).roundy (EPB_MODE_RP);
 14780:       case EPB_PREC_XSG:
 14781:         return this.nextupe (this).roundg (EPB_MODE_RP);
 14782:       }
 14783:       return this.nextupe (this);
 14784:     }  //efp.nextup(int)
 14785:     public final EFP nextup (EFP x, int prec) {
 14786:       switch (prec) {
 14787:       case EPB_PREC_EXD:
 14788:         return this.nextupe (x).roundx (EPB_MODE_RP);
 14789:       case EPB_PREC_SGL:
 14790:         return this.nextupe (x).roundf (EPB_MODE_RP);
 14791:       case EPB_PREC_DBL:
 14792:       case EPB_PREC_DBL3:
 14793:         return this.nextupe (x).roundd (EPB_MODE_RP);
 14794:       case EPB_PREC_TPL:
 14795:         return this.nextupe (x).roundy (EPB_MODE_RP);
 14796:       case EPB_PREC_XSG:
 14797:         return this.nextupe (x).roundg (EPB_MODE_RP);
 14798:       }
 14799:       return this.nextupe (x);
 14800:     }  //efp.nextup(EFP,int)
 14801: 
 14802:     //------------------------------------------------------------------------
 14803:     //y = y.parse (s)
 14804:     //  文字列解析
 14805:     //
 14806:     //    仮数部がInfで始まっているときはInf、Inf以外で仮数部に数字がないときはNaNとみなす
 14807:     //    仮数部が0bで始まっているときは2進数、0oで始まっているときは8進数、0xで始まっているときは16進数、それ以外は10進数とみなす
 14808:     //    0で始まっているだけでは8進数とみなさない
 14809:     //    2進数と8進数と16進数は2の累乗の指数部をp~で、10進数は10の累乗の指数部をe~で指定できる
 14810:     //    Inf、16進数のa~f、指数部のp~とe~は大文字と小文字を区別しない
 14811:     //    後ろのゴミは無視する
 14812:     //    先頭に空白があるときはエラーとなってNaNが返ることに注意
 14813:     //
 14814:     public final EFP parse (String s) {
 14815:       int i = 0;
 14816:       int l = s.length ();
 14817:       char c = i < l ? s.charAt (i++) : '\0';
 14818:       //符号
 14819:       int f;
 14820:       if (c == '-') {
 14821:         f = M;
 14822:         c = i < l ? s.charAt (i++) : '\0';
 14823:       } else {
 14824:         f = P;
 14825:         if (c == '+') {
 14826:           c = i < l ? s.charAt (i++) : '\0';
 14827:         }
 14828:       }
 14829:       //Inf
 14830:       if (i + 1 < l && (c | 0x20) == 'i' && (s.charAt (i) | 0x20) == 'n' && (s.charAt (i + 1) | 0x20) == 'f') {
 14831:         this.flg = f | I;
 14832:         return this;
 14833:       }
 14834:       //仮数部
 14835:       this.inner ();
 14836:       this.flg = P | Z;  //符号は最後に付ける
 14837:       boolean nan = true;  //true=仮数部に数字がない
 14838:       //基数
 14839:       int r = 10;
 14840:       if (c == '$') {  //16進数
 14841:         c = i < l ? s.charAt (i++) : '\0';
 14842:         r = 16;
 14843:       } else if (c == '@') {  //8進数
 14844:         c = i < l ? s.charAt (i++) : '\0';
 14845:         r = 8;
 14846:       } else if (c == '%') {  //2進数
 14847:         c = i < l ? s.charAt (i++) : '\0';
 14848:         r = 2;
 14849:       } else if (c == '0') {
 14850:         nan = false;  //0xの後に数字がなくても0があるのでNaNではなくて0にする
 14851:         c = i < l ? s.charAt (i++) : '\0';
 14852:         if ((c | 0x20) == 'x') {  //16進数
 14853:           c = i < l ? s.charAt (i++) : '\0';
 14854:           r = 16;
 14855:         } else if ((c | 0x20) == 'o') {  //8進数
 14856:           c = i < l ? s.charAt (i++) : '\0';
 14857:           r = 8;
 14858:         } else if ((c | 0x20) == 'b') {  //2進数
 14859:           c = i < l ? s.charAt (i++) : '\0';
 14860:           r = 2;
 14861:         }
 14862:       }
 14863:       //整数部
 14864:       {
 14865:         int t = Character.digit (c, r);
 14866:         if (t >= 0) {
 14867:           nan = false;
 14868:           do {
 14869:             this.imul (EFP_DIGIT[r]).iadd (EFP_DIGIT[t]);
 14870:             c = i < l ? s.charAt (i++) : '\0';
 14871:             t = Character.digit (c, r);
 14872:           } while (t >= 0);
 14873:         }
 14874:       }
 14875:       //小数部
 14876:       int o = 0;  //-小数点以下の桁数またはbit数
 14877:       if (c == '.') {
 14878:         c = i < l ? s.charAt (i++) : '\0';
 14879:         int t = Character.digit (c, r);
 14880:         if (t >= 0) {
 14881:           nan = false;
 14882:           do {
 14883:             o--;
 14884:             this.imul (EFP_DIGIT[r]).iadd (EFP_DIGIT[t]);
 14885:             c = i < l ? s.charAt (i++) : '\0';
 14886:             t = Character.digit (c, r);
 14887:           } while (t >= 0);
 14888:           if (r == 8) {  //8進数のときは1桁が3bit
 14889:             o *= 3;
 14890:           } else if (r == 16) {  //16進数のときは1桁が4bit
 14891:             o <<= 2;
 14892:           }
 14893:         }
 14894:       }
 14895:       //NaN
 14896:       if (nan) {  //仮数部に数字がない
 14897:         this.flg = N;
 14898:         return this.outer ();
 14899:       }
 14900:       //0
 14901:       if (this.flg << 1 < 0) {  //Z
 14902:         this.flg = f | Z;
 14903:         return this.outer ();
 14904:       }
 14905:       //指数部
 14906:       if ((c | 0x20) == (r == 10 ? 'e' : 'p')) {
 14907:         c = i < l ? s.charAt (i++) : '\0';
 14908:         int m;  //指数部の符号
 14909:         if (c == '-') {
 14910:           m = -1;
 14911:           c = i < l ? s.charAt (i++) : '\0';
 14912:         } else {
 14913:           m = 1;
 14914:           if (c == '+') {
 14915:             c = i < l ? s.charAt (i++) : '\0';
 14916:           }
 14917:         }
 14918:         if ('0' <= c && c <= '9') {  //指数部は常に10進数
 14919:           int t = 0;
 14920:           do {
 14921:             t = t * 10 + (c - '0');
 14922:             if (t >= 100000000) {  //オーバーフローまたはアンダーフロー
 14923:               this.outer ();
 14924:               if (m >= 0) {  //オーバーフロー
 14925:                 //0e+999999999は0だが0は除外済み
 14926:                 epbFpsr |= EPB_FPSR_OF;  //オーバーフロー
 14927:                 epbExceptionOperandExponent = 0;
 14928:                 epbExceptionOperandMantissa = 0L;
 14929:                 return this.sete (OVFL_RESULTS[epbRoundingPrec << 3 | epbRoundingMode << 1 | f >>> 31]).finish ();  //±Inf
 14930:               } else {  //アンダーフロー
 14931:                 //1e-999999999は0
 14932:                 epbFpsr |= EPB_FPSR_UF;  //アンダーフロー
 14933:                 epbExceptionOperandExponent = 0;
 14934:                 epbExceptionOperandMantissa = 0L;
 14935:                 return this.sete (UNFL_RESULTS[epbRoundingPrec << 3 | epbRoundingMode << 1 | f >>> 31]).finish ();  //±0
 14936:               }
 14937:             }
 14938:             c = i < l ? s.charAt (i++) : '\0';
 14939:           } while ('0' <= c && c <= '9');
 14940:           o += m * t;  //指数部-小数点以下の桁数
 14941:         }
 14942:       }
 14943:       if (r != 10) {  //2^oを掛ける
 14944:         this.shl (o);  //8進数または16進数のときも指数部はbit単位
 14945:       } else if (o > 0) {  //10^oを掛ける
 14946:         //this.imul (new EFP (TEN).pow (o));
 14947:         EFP t = new EFP (ONE);
 14948:         for (int j = 0, m = o; m != 0; j++, m >>>= 1) {
 14949:           if ((m & 1) != 0) {
 14950:             t.imul (EFP_TEN_POWER_P[j]);
 14951:           }
 14952:         }
 14953:         this.imul (t);
 14954:       } else if (o < 0) {  //10^-oで割る
 14955:         //this.div (new EFP (TEN).pow (-o));
 14956:         EFP t = new EFP (ONE);
 14957:         for (int j = 0, m = -o; m != 0; j++, m >>>= 1) {
 14958:           if ((m & 1) != 0) {
 14959:             t.imul (EFP_TEN_POWER_P[j]);
 14960:           }
 14961:         }
 14962:         this.div (t);
 14963:       }
 14964:       //符号
 14965:       return this.outer ().neg (f < 0);
 14966:     }  //efp.parse(String)
 14967: 
 14968:     //------------------------------------------------------------------------
 14969:     //x = x.pow (y)
 14970:     //  x=x^y
 14971:     //z = z.pow (x, y)
 14972:     //  z=x^y
 14973:     //  累乗
 14974:     //
 14975:     //  指数関数との関係
 14976:     //    x^y=(e^(log(x)))^y
 14977:     //       =e^(log(x)*y)
 14978:     //       =(2^(log2(x)))^y
 14979:     //       =2^(log2(x)*y)
 14980:     //
 14981:     //  メモ
 14982:     //    log2(x)はxが0に近すぎると-Infになってしまう
 14983:     //    x=2^k*v
 14984:     //    log2(2^k*v)=k+log2(v)
 14985:     //    x^y=2^(log2(x)*y)
 14986:     //       =2^(log2(2^k*v)*y)
 14987:     //       =2^((k+log2(v))*y)
 14988:     //       =2^(k*y+log2(v)*y)
 14989:     //       =2^(k*y)*2^(log2(v)*y)
 14990:     //
 14991:     public final EFP pow (EFP y) {
 14992:       return this.pow (this, y);
 14993:     }  //efp.pow(EFP)
 14994:     public final EFP pow (EFP x, EFP y) {
 14995:       int xf = x.flg;
 14996:       int yf = y.flg;
 14997:       if (yf << 1 != 0) {  //yが±0,±Inf,NaN
 14998:         if (yf << 1 < 0) {
 14999:           this.flg = P;  //x^±0=1。NaN^±0=1を含む
 15000:           this.epp = 0;
 15001:           this.dvl = MSB;
 15002:           this.cvl = 0L;
 15003:           return this;
 15004:         } else {
 15005:           int s;
 15006:           this.flg = (yf << 3 < 0 ||  //x^NaN=NaN
 15007:                       xf << 3 < 0 ||  //NaN^(y!=±0)=NaN
 15008:                       (s = x.cmp1abs ()) == 0 ? N :  //(|x|==1)^±Inf=NaN
 15009:                       (s ^ yf) >= 0 ? P | I :  //(|x|>1)^+Inf=(|x|<1)^-Inf=+Inf。±Inf^±Inf=+Infを含む
 15010:                       P | Z);  //(|x|>1)^-Inf=(|x|<1)^+Inf=+0。±Inf^∓Inf=+0を含む
 15011:           return this;
 15012:         }
 15013:       } else if (xf << 1 != 0) {  //xが±0,±Inf,NaNでyが±0,±Inf,NaN以外
 15014:         this.flg = (xf << 3 < 0 ? N :  //NaN^(y!=±0)=NaN
 15015:                     xf >= 0 ?  //xが+0,+Inf
 15016:                     (xf << 2 ^ yf) >= 0 ? P | Z :  //+0^(y>0)=+0,+Inf^(y<0)=+0
 15017:                     P | I :  //+0^(y<0)=+Inf,+Inf^(y>0)=+Inf
 15018:                     //xが-0,-Inf
 15019:                     y.isodd () ?  //yが奇数
 15020:                     (xf << 2 ^ yf) >= 0 ? M | Z :  //-0^(y>0 and is odd)=-0,-Inf^(y<0 and is odd)=-0
 15021:                     M | I :  //-0^(y<0 and is odd)=-Inf,-0^(y<0 and is odd)=-Inf
 15022:                     //yが奇数でない(偶数であるまたは整数でない)
 15023:                     //!!! (-Inf)^-1.5は+0なのか?
 15024:                     //  System.out.println(Math.pow(Double.NEGATIVE_INFINITY,-1.5));
 15025:                     //  0.0
 15026:                     (xf << 2 ^ yf) >= 0 ? P | Z :  //-0^(y>0 and is not odd)=+0,-Inf^(y<0 and is even)=+0
 15027:                     P | I);  //-0^(y<0 and is even)=+Inf,-Inf^(y>0 and is even)=+Inf
 15028:         return this;
 15029:       } else if (xf < 0) {  //両方±0,±Inf,NaN以外でxが負
 15030:         this.inner ();
 15031:         if (y.iseven ()) {  //yが偶数
 15032:           EFP w = new EFP ();
 15033:           this.imulw (w, new EFP ().ineg (x).log2 (), y);
 15034:           if (this.epp >= 16) {  //指数が大きすぎる
 15035:             this.flg = this.flg >= 0 ? P | I : P | Z;  //2^+big=+Inf,2^-big=+0
 15036:             return this.outer ();
 15037:           } else {
 15038:             int k = this.geti ();
 15039:             return this.frac ().iadd (w).exp2 ().outer ().shl (k);
 15040:           }
 15041:         } else if (y.isodd ()) {  //yが奇数
 15042:           EFP w = new EFP ();
 15043:           this.imulw (w, new EFP ().ineg (x).log2 (), y);
 15044:           if (this.epp >= 16) {  //指数が大きすぎる
 15045:             this.flg = this.flg >= 0 ? M | I : M | Z;  //-(2^+big)=-Inf,-(2^-big)=-0
 15046:             return this.outer ();
 15047:           } else {
 15048:             int k = this.geti ();
 15049:             return this.frac ().iadd (w).exp2 ().shl (k).outer ().neg ();
 15050:           }
 15051:         } else {  //yが整数でない
 15052:           this.flg = N;  //(x<0)^(y is not integer)=NaN
 15053:           return this.outer ();
 15054:         }
 15055:       } else {  //両方±0,±Inf,NaN以外でxが正
 15056:         this.inner ();
 15057:         EFP w = new EFP ();
 15058:         this.imulw (w, new EFP ().log2 (x), y);
 15059:         if (this.epp >= 16) {  //指数が大きすぎる
 15060:           this.flg = this.flg >= 0 ? P | I : P | Z;  //2^+big=+Inf,2^-big=+0
 15061:           return this.outer ();
 15062:         } else {
 15063:           int k = this.geti ();
 15064:           return this.frac ().iadd (w).exp2 ().outer ().shl (k);
 15065:         }
 15066:       }
 15067:     }  //efp.pow(EFP,EFP)
 15068: 
 15069:     //------------------------------------------------------------------------
 15070:     //x = x.powi (n)
 15071:     //  x=x^n
 15072:     //z = z.powi (x, n)
 15073:     //  z=x^n
 15074:     //  int累乗
 15075:     //
 15076:     public final EFP powi (int n) {
 15077:       return this.powi (this, n);
 15078:     }  //efp.powi(int)
 15079:     public final EFP powi (EFP x, int n) {
 15080:       int xf = x.flg;
 15081:       if (n == 0) {  //yが±0,±Inf,NaN
 15082:         //this.set1 ();
 15083:         this.flg = P;  //x^±0=1。NaN^±0=1を含む
 15084:         this.epp = 0;
 15085:         this.dvl = MSB;
 15086:         this.cvl = 0L;
 15087:         return this;
 15088:       } else if (xf << 1 != 0) {  //xが±0,±Inf,NaNでyが±0,±Inf,NaN以外
 15089:         this.flg = (xf << 3 < 0 ? N :  //NaN^(y!=±0)=NaN
 15090:                     xf >= 0 ?  //xが+0,+Inf
 15091:                     (xf << 2 ^ n) >= 0 ? P | Z :  //+0^(y>0)=+0,+Inf^(y<0)=+0
 15092:                     P | I :  //+0^(y<0)=+Inf,+Inf^(y>0)=+Inf
 15093:                     //xが-0,-Inf
 15094:                     (n & 1) != 0 ?  //yが奇数
 15095:                     (xf << 2 ^ n) >= 0 ? M | Z :  //-0^(y>0 and is odd)=-0,-Inf^(y<0 and is odd)=-0
 15096:                     M | I :  //-0^(y<0 and is odd)=-Inf,-0^(y<0 and is odd)=-Inf
 15097:                     //yが奇数でない(偶数であるまたは整数でない)
 15098:                     //!!! (-Inf)^-1.5は+0なのか?
 15099:                     //  System.out.println(Math.pow(Double.NEGATIVE_INFINITY,-1.5));
 15100:                     //  0.0
 15101:                     (xf << 2 ^ n) >= 0 ? P | Z :  //-0^(y>0 and is not odd)=+0,-Inf^(y<0 and is even)=+0
 15102:                     P | I);  //-0^(y<0 and is even)=+Inf,-Inf^(y>0 and is even)=+Inf
 15103:         return this;
 15104:       } else {  //両方±0,±Inf,NaN以外
 15105:         //  y==0は処理済み
 15106:         int t = n >= 0 ? n : -n;  //|y|
 15107:         if (t >>> 16 != 0) {  //t==0x80000000の場合があるのでt>65535は不可
 15108:           //|x|が1に近くて|n|が大きいとき乗算を繰り返す方法では誤差が大きくなるのでpowに計算させる
 15109:           int xe = x.epp;
 15110:           long xd = x.dvl;
 15111:           if (xe == 0 && xd >>> -16 == 0x8000L ||
 15112:               xe == -1 && xd >>> -16 == 0xffffL) {  //±1±ε
 15113:             return this.pow (x, new EFP (n));
 15114:           }
 15115:         }
 15116:         this.inner ();
 15117:         EFP w = new EFP (x);  //x^(2^0)
 15118:         if ((t & 1) == 0) {
 15119:           //this.set1 ();
 15120:           this.flg = P;  //x^0=1
 15121:           this.epp = 0;
 15122:           this.dvl = MSB;
 15123:           this.cvl = 0L;
 15124:         } else {
 15125:           //this.sete (x);
 15126:           this.flg = xf;  //x^1=x
 15127:           this.epp = x.epp;
 15128:           this.dvl = x.dvl;
 15129:           this.cvl = x.cvl;
 15130:         }
 15131:         while ((t >>>= 1) != 0) {
 15132:           w.squ ();  //x^(2^k)。指数部分が32bitでも足りなくなることがあるのでisquは不可
 15133:           if ((t & 1) != 0) {
 15134:             this.mul (w);
 15135:           }
 15136:         }
 15137:         if (n < 0) {  //x^(y<0)=1/x^-y
 15138:           this.rcp ();
 15139:         }
 15140:         return this.outer ().finish ();
 15141:       }
 15142:     }  //efp.powi(EFP,int)
 15143: 
 15144:     //------------------------------------------------------------------------
 15145:     //x = x.quo (y)
 15146:     //  x=trunc(x/y)
 15147:     //z = z.quo (x, y)
 15148:     //  z=trunc(x/y)
 15149:     //  商
 15150:     //
 15151:     public final EFP quo (EFP y) {
 15152:       return this.quo (this, y);
 15153:     }  //efp.quo(EFP)
 15154:     public final EFP quo (EFP x, EFP y) {
 15155:       int xf = x.flg;
 15156:       int yf = y.flg;
 15157:       if ((xf | yf) << 1 != 0) {  //どちらかが±0,±Inf,NaN
 15158:         this.flg = ((xf | yf) << 3 != 0 || (xf & yf & (Z | I)) != 0 ? N :  //どちらかがNaNまたは±0/±0または±Inf/±InfのときNaN
 15159:                     (xf ^ yf) & M | ((xf & Z | yf & I) != 0 ? Z : I));  //±0/(±0,NaN以外)または(±Inf,NaN以外)/±Infのとき±0、(±0,NaN以外)/±0または±Inf/(±Inf,NaN以外)のとき±Inf
 15160:         return this;
 15161:       }
 15162:       //±0,±Inf,NaN以外
 15163:       int zf = xf ^ yf;  //符号が同じならばP、異なればM。ここでセットされるのはMだけ
 15164:       int ze = x.epp - y.epp;  //商の小数点はq0の左端から右にzeの位置
 15165:       if (ze < 0) {  //|x|<|y|。商は0
 15166:         this.flg = zf | Z;
 15167:         return this;
 15168:       }
 15169:       //仮数部を31bitずつ3分割する
 15170:       long r01 = x.dvl;
 15171:       long y01 = y.dvl;
 15172:       long r2 = (r01 << -2 | x.cvl >>> 2) >>> 33;
 15173:       long y2 = (y01 << -2 | y.cvl >>> 2) >>> 33;
 15174:       r01 >>>= 2;
 15175:       y01 >>>= 2;
 15176:       long y0 = y01 >>> 31;
 15177:       long y1 = y01 & 0x7fffffffL;
 15178:       //先頭1bit
 15179:       boolean qq;
 15180:       if (r01 < y01 || (r01 == y01 && r2 < y2)) {  //xの仮数部<yの仮数部
 15181:         if (ze == 0) {  //|x|<|y|。商は0
 15182:           this.flg = zf | Z;
 15183:           return this;
 15184:         }
 15185:         qq = false;
 15186:       } else {
 15187:         qq = true;
 15188:         r2 -= y2;
 15189:         r01 -= y01;
 15190:         if (r2 < 0L) {
 15191:           r2 += 0x80000000L;
 15192:           r01--;
 15193:         }
 15194:       }
 15195:       long q0, q1, q2;
 15196:       //1桁目
 15197:       q0 = r01 >> 31 == y0 ? 0x7fffffffL : r01 / y0;
 15198:       r01 = (r01 - q0 * y0 << 31) + r2 - q0 * y1;
 15199:       if (r01 < 0L) {
 15200:         q0--;
 15201:         r01 += y01;
 15202:       }
 15203:       r2 = q0 * y2 + 0x7fffffffL;
 15204:       r01 -= r2 >> 31;
 15205:       r2 = ~r2 & 0x7fffffffL;  //~(r2 | ~0x7fffffffL)
 15206:       if (r01 < 0L) {
 15207:         q0--;
 15208:         r2 += y2;
 15209:         r01 += y01 + (r2 >> 31);
 15210:         r2 &= 0x7fffffffL;
 15211:       }
 15212:       if (ze <= 31) {
 15213:         q0 &= ~0x7fffffffL >> ze;
 15214:         q1 = q2 = 0L;
 15215:       } else {
 15216:         //2桁目
 15217:         q1 = r01 >> 31 == y0 ? 0x7fffffffL : r01 / y0;
 15218:         r01 = (r01 - q1 * y0 << 31) + r2 - q1 * y1;
 15219:         if (r01 < 0L) {
 15220:           q1--;
 15221:           r01 += y01;
 15222:         }
 15223:         r2 = q1 * y2 + 0x7fffffffL;
 15224:         r01 -= r2 >> 31;
 15225:         r2 = ~r2 & 0x7fffffffL;  //~(r2 | ~0x7fffffffL)
 15226:         if (r01 < 0L) {
 15227:           q1--;
 15228:           r2 += y2;
 15229:           r01 += y01 + (r2 >> 31);
 15230:           r2 &= 0x7fffffffL;
 15231:         }
 15232:         if (ze <= 62) {
 15233:           q1 &= ~0x7fffffffL >> ze - 31;
 15234:           q2 = 0L;
 15235:         } else {
 15236:           //3桁目
 15237:           q2 = r01 >> 31 == y0 ? 0x7fffffffL : r01 / y0;
 15238:           r01 = (r01 - q2 * y0 << 31) + r2 - q2 * y1;
 15239:           if (r01 < 0L) {
 15240:             q2--;
 15241:             r01 += y01;
 15242:           }
 15243:           r2 = q2 * y2 + 0x7fffffffL;
 15244:           r01 -= r2 >> 31;
 15245:           r2 = ~r2 & 0x7fffffffL;  //~(r2 | ~0x7fffffffL)
 15246:           if (r01 < 0L) {
 15247:             q2--;
 15248:             //r2 += y2;
 15249:             //r01 += y01 + (r2 >> 31);
 15250:             //r2 &= 0x7fffffffL;
 15251:           }
 15252:           if (ze <= 93) {
 15253:             q2 &= ~0x7fffffffL >> ze - 62;
 15254:           }
 15255:         }
 15256:       }
 15257:       //商  (((qq ? 1 : 0) << 31 | q0) << 31 | q1) << 31 | q2
 15258:       //正規化する
 15259:       if (qq) {  //商は94bit
 15260:         q0 = MSB | q0 << 32 | q1 << 1 | q2 >>> 30;
 15261:         q2 <<= -30;
 15262:       } else {  //商は93bit
 15263:         ze--;
 15264:         q0 = q0 << -31 | q1 << 2 | q2 >>> 29;
 15265:         q2 <<= -29;
 15266:       }
 15267:       return this.finish (zf, ze, q0, q2, 0L);
 15268:     }  //efp.quo(EFP,EFP)
 15269: 
 15270:     //------------------------------------------------------------------------
 15271:     //x = x.rad ()
 15272:     //  x*=pi/180
 15273:     //y = y.rad (x)
 15274:     //  y=x*pi/180
 15275:     //  pi/180倍(ラジアン)
 15276:     //
 15277:     //  グラフ
 15278:     //    perl -e "use Graph;$g=new Graph();$g->grid();$g->func(sub{atan2(1,1)/45*$_[0]});print$g"
 15279:     //    echo read("../misc/efp.gp");eval("rad(x)=x*(Pi/180)");graph(rad) | gp -q
 15280:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
 15281:     //    |                                       |                                       |
 15282:     //    |                                       |                                       |
 15283:     //    |                                       |                                       |
 15284:     //    |                                       |                                       |
 15285:     //    +                                       +                                       +
 15286:     //    |                                       |                                       |
 15287:     //    |                                       |                                       |
 15288:     //    |                                       |                                       |
 15289:     //    |                                       |                                       |
 15290:     //    +                                       +                                       +
 15291:     //    |                                       |                                       |
 15292:     //    |                                       |                                       |
 15293:     //    |                                       |                                       |
 15294:     //    |                                       |                                       |
 15295:     //    +                                       +                                       +
 15296:     //    |                                       |                                       |
 15297:     //    |                                       |                                       |
 15298:     //    |                                       |                                       |
 15299:     //    |                                       |                                       |
 15300:     //    *********************************************************************************
 15301:     //    |                                       |                                       |
 15302:     //    |                                       |                                       |
 15303:     //    |                                       |                                       |
 15304:     //    |                                       |                                       |
 15305:     //    +                                       +                                       +
 15306:     //    |                                       |                                       |
 15307:     //    |                                       |                                       |
 15308:     //    |                                       |                                       |
 15309:     //    |                                       |                                       |
 15310:     //    +                                       +                                       +
 15311:     //    |                                       |                                       |
 15312:     //    |                                       |                                       |
 15313:     //    |                                       |                                       |
 15314:     //    |                                       |                                       |
 15315:     //    +                                       +                                       +
 15316:     //    |                                       |                                       |
 15317:     //    |                                       |                                       |
 15318:     //    |                                       |                                       |
 15319:     //    |                                       |                                       |
 15320:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
 15321:     //
 15322:     public final EFP rad () {
 15323:       return this.mul (this, TO_RAD);  //x*pi/180
 15324:     }  //efp.rad()
 15325:     public final EFP rad (EFP x) {
 15326:       return this.mul (x, TO_RAD);  //x*pi/180
 15327:     }  //efp.rad(EFP)
 15328: 
 15329:     //------------------------------------------------------------------------
 15330:     //y = y.random ()
 15331:     //  y=random()
 15332:     //  乱数
 15333:     //
 15334:     //  0以上1未満の乱数
 15335:     //  0以上1未満の1/2^LENの倍数がほぼ一様に出現するはず
 15336:     //  指数部が小さい数は有効桁数が少ない
 15337:     //
 15338:     public final EFP random () {
 15339:       int xf = P;
 15340:       int xe = -1;
 15341:       long xd = epbRand48 ();
 15342:       long xc = epbRand48 ();
 15343:       xd = xd << 16 | xc >>> 32;
 15344:       xc = xc << 32 & -LSB;
 15345:       if (xd != 0L) {
 15346:         int o = Long.numberOfLeadingZeros (xd);
 15347:         if (o > 0) {
 15348:           xe -= o;
 15349:           xd = xd << o | xc >>> -o;
 15350:           xc <<= o;
 15351:         }
 15352:       } else if (xc != 0L) {
 15353:         int o = Long.numberOfLeadingZeros (xc);
 15354:         xe -= 64 + o;
 15355:         xd = xc << o;
 15356:         xc = 0L;
 15357:       } else {
 15358:         xf = P | Z;
 15359:       }
 15360:       return this.finish (xf, xe, xd, xc, 0L);
 15361:     }  //efp.random()
 15362: 
 15363:     //------------------------------------------------------------------------
 15364:     //x = x.rcp ()
 15365:     //  x=1/x
 15366:     //y = y.rcp (x)
 15367:     //  y=1/x
 15368:     //  逆数 reciprocal
 15369:     //
 15370:     //  グラフ
 15371:     //    perl -e "use Graph;$g=new Graph();$g->grid();$g->func(sub{1/$_[0]});print$g"
 15372:     //    echo read("../misc/efp.gp");eval("rcp(x)=1/x");graph(rcp) | gp -q
 15373:     //    +---------+---------+---------+---------+-**------+---------+---------+---------+
 15374:     //    |                                       |  *                                    |
 15375:     //    |                                       |  *                                    |
 15376:     //    |                                       |  *                                    |
 15377:     //    |                                       |  *                                    |
 15378:     //    +                                       +  *                                    +
 15379:     //    |                                       |  **                                   |
 15380:     //    |                                       |   *                                   |
 15381:     //    |                                       |   *                                   |
 15382:     //    |                                       |   **                                  |
 15383:     //    +                                       +    *                                  +
 15384:     //    |                                       |    **                                 |
 15385:     //    |                                       |     **                                |
 15386:     //    |                                       |      **                               |
 15387:     //    |                                       |       **                              |
 15388:     //    +                                       +        ***                            +
 15389:     //    |                                       |          ****                         |
 15390:     //    |                                       |             *******                   |
 15391:     //    |                                       |                   **************      |
 15392:     //    |                                       |                                ********
 15393:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
 15394:     //    ********                                |                                       |
 15395:     //    |      **************                   |                                       |
 15396:     //    |                   *******             |                                       |
 15397:     //    |                         ****          |                                       |
 15398:     //    +                            ***        +                                       +
 15399:     //    |                              **       |                                       |
 15400:     //    |                               **      |                                       |
 15401:     //    |                                **     |                                       |
 15402:     //    |                                 **    |                                       |
 15403:     //    +                                  *    +                                       +
 15404:     //    |                                  **   |                                       |
 15405:     //    |                                   *   |                                       |
 15406:     //    |                                   *   |                                       |
 15407:     //    |                                   **  |                                       |
 15408:     //    +                                    *  +                                       +
 15409:     //    |                                    *  |                                       |
 15410:     //    |                                    *  |                                       |
 15411:     //    |                                    *  |                                       |
 15412:     //    |                                    *  |                                       |
 15413:     //    +---------+---------+---------+------**-+---------+---------+---------+---------+
 15414:     //
 15415:     //  ニュートン法
 15416:     //    f(x)=a-1/x
 15417:     //    f'(x)=1/x^2
 15418:     //    x'=x-f(x)/f'(x)
 15419:     //      =x-(a-1/x)/(1/x^2)
 15420:     //      =x-(a*x^2-x)
 15421:     //      =2*x-a*x^2
 15422:     //
 15423:     public final EFP rcp () {
 15424:       return this.div (ONE, this);
 15425:     }  //efp.rcp()
 15426:     public final EFP rcp (EFP x) {
 15427:       if (false) {  //1を割る。[93] 55.7ns。正確だが遅い
 15428:         return this.div (ONE, x);
 15429:       } else {  //ニュートン法。[91] 37.0ns。速いが誤差が大きい
 15430:         int xf = x.flg;
 15431:         if (xf << 1 != 0) {  //±0,±Inf,NaN
 15432:           if (xf << 1 < 0) {  //±0
 15433:             epbFpsr |= EPB_FPSR_DZ;
 15434:             epbExceptionOperandExponent = xf & M;
 15435:             epbExceptionOperandMantissa = 0x0000000000000000L;
 15436:             this.flg = xf ^ (Z | I);  //1/±0=±Inf
 15437:           } else if (xf << 2 < 0) {  //±Inf
 15438:             this.flg = xf ^ (Z | I);  //1/±Inf=±0
 15439:           } else {  //NaN
 15440:             this.flg = N;
 15441:           }
 15442:           return this;
 15443:         }
 15444:         //±0,±Inf,NaN以外
 15445:         this.inner ();
 15446:         long s = Double.doubleToLongBits (1.0 / Double.longBitsToDouble ((long) 1023 << 52 | x.dvl << 1 >>> 12));
 15447:         EFP t = new EFP (xf, (int) (s >>> 52) - 1023 - x.epp, MSB | s << 12 >>> 1, 0L);
 15448:         //return this.imul (x, t).negsub (TWO).outer ().mul (t);  //(2-x*t)*t。[91] 38.4ns
 15449:         this.imul2 (t);  //2*t
 15450:         t.isqu ().imul (x);  //x*t^2
 15451:         return this.outer ().sub (t);  //2*t-x*t^2。[91] 37.0ns。mulがsquになっている分速い
 15452:       }
 15453:     }  //efp.rcp(EFP)
 15454: 
 15455:     //------------------------------------------------------------------------
 15456:     //x = x.rcpdiv (y)
 15457:     //  x=y/x
 15458:     //  逆除算
 15459:     //
 15460:     //  x.div(y).rcp()と同じ
 15461:     //  z.rcpdiv(x,y)はz.div(y,x)と同じ
 15462:     //
 15463:     public final EFP rcpdiv (EFP y) {
 15464:       return this.div (y, this);
 15465:     }  //efp.rcpdiv(EFP)
 15466:     public final EFP rcpdiv (EFP x, EFP y) {
 15467:       return this.div (y, x);
 15468:     }  //efp.rcpdiv(EFP,EFP)
 15469: 
 15470:     //------------------------------------------------------------------------
 15471:     //x = x.rem (y)
 15472:     //  x%=y
 15473:     //z = z.rem (x, y)
 15474:     //  z=x%y
 15475:     //  剰余(round-to-zero)
 15476:     //
 15477:     //  x%y=x-trunc(x/y)*y
 15478:     //  (xn/xd)-trunc(x/y)*(yn/yd)
 15479:     //    =(xn/xd)-((trunc(x/y)*yn)/yd)
 15480:     //    =(xn*yd-xd*((trunc(x/y)*yn))/(xd*yd)
 15481:     //
 15482:     //  Javaのx%yと同じ
 15483:     //    x%y=x-(x/y)*y
 15484:     //       =isNaN(x)||isNaN(y)||isInfinite(x)?NaN:isInfinite(y)?x:(t=x-trunc(x/y)*y)==0?copySign(0,x):t
 15485:     //    Javaの%演算子はdoubleをdoubleのまま計算する
 15486:     //  被除数から0の方向にある最も近い除数の倍数を引いた結果を返す
 15487:     //  倍数の符号は任意なので除数の符号は結果に影響しない
 15488:     //     5.0 %  3.0 ==  5.0 - (long) ( 5.0 /  3.0) *  3.0 ==  2.0
 15489:     //     5.0 % -3.0 ==  5.0 - (long) ( 5.0 / -3.0) * -3.0 ==  2.0
 15490:     //    -5.0 %  3.0 == -5.0 - (long) (-5.0 /  3.0) *  3.0 == -2.0
 15491:     //    -5.0 % -3.0 == -5.0 - (long) (-5.0 / -3.0) * -3.0 == -2.0
 15492:     //  z  余り remainder
 15493:     //  x  被除数 dividend
 15494:     //  y  除数 divisor
 15495:     //
 15496:     public final EFP rem (EFP y) {
 15497:       return this.rem (this, y);
 15498:     }  //efp.rem(EFP)
 15499:     public final EFP rem (EFP x, EFP y) {
 15500:       int xf = x.flg;
 15501:       int yf = y.flg;
 15502:       epbFpsr &= 0xff00ffff;  //quotient byteをクリアする
 15503:       if ((xf | yf) << 1 != 0) {  //どちらかが±0,±Inf,NaN
 15504:         if ((xf | yf) << 3 < 0) {  //rem(NaN,y)=NaN, rem(x,NaN)=NaN
 15505:           this.flg = N;
 15506:         } else if (xf << 2 < 0 ||  //rem(±Inf,y)=NaN
 15507:                    yf << 1 < 0) {  //rem(x,±0)=NaN
 15508:           //除数が±0でもゼロ除算にはならない
 15509:           epbFpsr |= EPB_FPSR_OE;
 15510:           if (yf << 1 < 0) {  //±0
 15511:             epbExceptionOperandExponent = yf & M;
 15512:             epbExceptionOperandMantissa = 0x0000000000000000L;
 15513:           } else if (yf << 2 < 0) {  //±Inf
 15514:             epbExceptionOperandExponent = yf & M | 0x7fff << 16;
 15515:             epbExceptionOperandMantissa = 0x0000000000000000L;
 15516:           } else {  //±y
 15517:             epbExceptionOperandExponent = yf & M | 0x3fff + y.epp << 16;
 15518:             epbExceptionOperandMantissa = y.dvl;
 15519:           }
 15520:           this.flg = N;
 15521:         } else if (xf << 1 < 0) {  //rem(±0,y)=±0
 15522:           epbFpsr |= ((xf ^ yf) & M) >>> 8;  //quotient byteに商の符号を入れる
 15523:           this.flg = xf;
 15524:         } else {  //rem(x,±Inf)=x
 15525:           epbFpsr |= ((xf ^ yf) & M) >>> 8;  //quotient byteに商の符号を入れる
 15526:           this.finish (xf, x.epp, x.dvl, x.cvl, 0L);  //xが非正規化数のときUFをセットする
 15527:         }
 15528:         return this;
 15529:       }
 15530:       //両方±0,±Inf,NaN以外
 15531:       epbFpsr |= ((xf ^ yf) & M) >>> 8;  //quotient byteに商の符号を入れる
 15532:       if (false) {
 15533:         this.inner ();
 15534:         //this.sub (x, new EFP ().div (x, y).trunc ().imul (y));  //x-trunc(x/y)*y。this==x||this==yの場合に注意
 15535:         int s;
 15536:         long t;
 15537:         if ((s = x.epp - y.epp) < 0 ||
 15538:             s == 0 && ((t = x.dvl - y.dvl) < 0L ||
 15539:                        t == 0L && (x.cvl >>> 1) - (y.cvl >>> 1) < 0L)) {  //|x|<|y|。商が0
 15540:           //this.sete (x);  //被除数がそのまま余りになる
 15541:           this.flg = xf;
 15542:           this.epp = x.epp;
 15543:           this.dvl = x.dvl;
 15544:           this.cvl = x.cvl;
 15545:         } else {  //|x|>=|y|。商が0ではない
 15546:           EFP xx = x != this ? x : new EFP (x);  //xのコピー
 15547:           EFP yy = y != this ? y : new EFP (y);  //yのコピー
 15548:           this.divrz (xx, yy).trunc ();  //trunc(x/y)。商。divを使うと丸め(RN)で商の絶対値が1大きくなってしまうことがあるのでdivrzを使う
 15549:           epbQuotient = this.geti32abs ();
 15550:           epbFpsr |= (epbQuotient & 127) << 16;  //商の絶対値の下位7bit
 15551:           EFP ww = new EFP ();
 15552:           this.imulw (ww, this, yy).negsub (xx).sub (ww);  //x-trunc(x/y)*y。余り。xがyの倍数に近いとき桁落ちが発生するので乗算を倍精度で行う
 15553:           if (this.flg << 1 < 0) {  //余りが0
 15554:             this.flg = xf | Z;  //0にxの符号を付ける
 15555:           }
 15556:         }
 15557:         return this.outer ().finish ();
 15558:       } else {
 15559:         this.inner ();
 15560:         int ye = y.epp;  //this==yの場合があるので順序に注意する
 15561:         long yd = y.dvl;
 15562:         long yc = y.cvl;
 15563:         long yc1 = yc >>> 1;
 15564:         this.epp = x.epp;
 15565:         this.dvl = x.dvl;
 15566:         this.cvl = x.cvl;
 15567:         int i;
 15568:         long l;
 15569:         int q = 0;
 15570:         if ((i = this.epp - ye) > 0 ||
 15571:             i == 0 && ((l = this.dvl - yd) > 0L ||
 15572:                        l == 0L && this.cvl >>> 1 >= yc1)) {  //|x|>=|y|。商は0ではない
 15573:           this.flg = P;  //|x|。余りの初期値
 15574:           EFP t = new EFP (P, 0, yd, yc);
 15575:           do {
 15576:             t.epp = i = (l = this.dvl - yd) > 0L || l == 0L && this.cvl >>> 1 >= yc1 ? this.epp : this.epp - 1;  //指数部を揃えて
 15577:             if ((i -= ye) <= 31) {
 15578:               q |= 1 << i;
 15579:             }
 15580:             this.sub (t);  //引く。アンダーフローのチェックは後で行う
 15581:           } while (this.flg == 0 &&  //0ではない
 15582:                    ((i = this.epp - ye) > 0 ||
 15583:                     i == 0 && ((l = this.dvl - yd) > 0L ||
 15584:                                l == 0L && this.cvl >>> 1 >= yc1)));  //this>=|y|。まだ引ける。指数部が極端に違うと繰り返す回数が大きくなる
 15585:           this.flg |= xf;  //余りが0の場合も含めてyの符号に関係なくxの符号を付ける
 15586:         } else {  //|x|<|y|。商は0
 15587:           this.flg = xf;  //被除数がそのまま余りになる
 15588:         }
 15589:         epbQuotient = q;
 15590:         epbFpsr |= (q & 127) << 16;  //商の絶対値の下位7bit
 15591:         return this.outer ().finish ();
 15592:       }
 15593:     }  //efp.rem(EFP,EFP)
 15594: 
 15595:     //------------------------------------------------------------------------
 15596:     //x = x.rint ()
 15597:     //  x=rint(x)
 15598:     //y = y.rint (x)
 15599:     //  y=rint(x)
 15600:     //  丸め(nearest-even)
 15601:     //
 15602:     //  グラフ
 15603:     //    perl -e "use Graph;$g=new Graph();$g->grid();$g->func(sub{my$x=$_[0];my$t=int$x;my$f=abs($x-$t);$t+($f==0.5&&($t&1)!=0||$f>0.5?$x<=>0:0)});print$g"
 15604:     //    echo read("../misc/efp.gp");eval("rint(x)={my(f=floor(x),s=sign(x-floor(x)-0.5));if(s==0&&(f%2==0)||s<0,f,f+1)}");graph(rint) | gp -q
 15605:     //    +---------+---------+---------+---------+---------+---------+---------+----******
 15606:     //    |                                       |                                       |
 15607:     //    |                                       |                                       |
 15608:     //    |                                       |                                       |
 15609:     //    |                                       |                                       |
 15610:     //    +                                       +                        ***********    +
 15611:     //    |                                       |                                       |
 15612:     //    |                                       |                                       |
 15613:     //    |                                       |                                       |
 15614:     //    |                                       |                                       |
 15615:     //    +                                       +              ***********              +
 15616:     //    |                                       |                                       |
 15617:     //    |                                       |                                       |
 15618:     //    |                                       |                                       |
 15619:     //    |                                       |                                       |
 15620:     //    +                                       +    ***********                        +
 15621:     //    |                                       |                                       |
 15622:     //    |                                       |                                       |
 15623:     //    |                                       |                                       |
 15624:     //    |                                       |                                       |
 15625:     //    +---------+---------+---------+----***********----+---------+---------+---------+
 15626:     //    |                                       |                                       |
 15627:     //    |                                       |                                       |
 15628:     //    |                                       |                                       |
 15629:     //    |                                       |                                       |
 15630:     //    +                        ***********    +                                       +
 15631:     //    |                                       |                                       |
 15632:     //    |                                       |                                       |
 15633:     //    |                                       |                                       |
 15634:     //    |                                       |                                       |
 15635:     //    +              ***********              +                                       +
 15636:     //    |                                       |                                       |
 15637:     //    |                                       |                                       |
 15638:     //    |                                       |                                       |
 15639:     //    |                                       |                                       |
 15640:     //    +    ***********                        +                                       +
 15641:     //    |                                       |                                       |
 15642:     //    |                                       |                                       |
 15643:     //    |                                       |                                       |
 15644:     //    |                                       |                                       |
 15645:     //    ******----+---------+---------+---------+---------+---------+---------+---------+
 15646:     //
 15647:     //  最も近い整数に丸める
 15648:     //  小数点以下が0.5のときは偶数の方向に丸める
 15649:     //
 15650:     public final EFP rint () {
 15651:       return this.rint (this);
 15652:     }  //efp.rint()
 15653:     public final EFP rint (EFP x) {  //4.6ns
 15654:       int xf = x.flg;
 15655:       if (xf << 1 != 0) {  //±0,±Inf,NaN
 15656:         this.flg = xf;
 15657:         return this;
 15658:       }
 15659:       //±0,±Inf,NaN以外
 15660:       int xe = x.epp;
 15661:       long xd = x.dvl;
 15662:       long xc = x.cvl;
 15663:       if (xe < 0) {  //0<|x|<1
 15664:         epbFpsr |= EPB_FPSR_X2;  //不正確な結果
 15665:         if (xe < -1 || xd == MSB && xc == 0L) {  //0<|x|<=1/2
 15666:           this.flg = xf | Z;  //rint(-1/2<=x<0)=-0, rint(0<x<=1/2)=+0
 15667:         } else {  //1/2<|x|<1
 15668:           this.flg = xf;  //rint(-1<x<-1/2)=-1, rint(1/2<x<1)=1
 15669:           this.epp = 0;
 15670:           this.dvl = MSB;
 15671:           this.cvl = 0L;
 15672:         }
 15673:         return this;
 15674:       }
 15675:       //整数部がある
 15676:       long m = MSB >> xe;  //整数部のマスク。符号に注意
 15677:       if (xe <= 62) {  //0..62。dの途中まで整数部
 15678:         if ((xd & ~m | xc) != 0L) {  //小数部が0ではない
 15679:           epbFpsr |= EPB_FPSR_X2;  //不正確な結果
 15680:           long t = xd;  //保存して
 15681:           xd &= m;  //小数部を切り捨てる
 15682:           if ((t & -(m >> 1)) != 0L && (t & (-m | ~(m >> 1)) | xc) != 0L) {  //guard bitが1かつLSBまたはguard bit以外の端数が0ではない
 15683:             xd -= m;  //絶対値に1を加える。符号に注意
 15684:             if (xd >= 0L) {  //dから溢れた
 15685:               xd = MSB;
 15686:               xe++;
 15687:               if ((short) xe != xe) {  //オーバーフローした
 15688:                 epbFpsr |= EPB_FPSR_OF;  //オーバーフロー
 15689:                 epbExceptionOperandExponent = xf;
 15690:                 epbExceptionOperandMantissa = xd;
 15691:                 return this.sete (OVFL_RESULTS[epbRoundingPrec << 3 | epbRoundingMode << 1 | xf >>> 31]).finish ();  //±Inf
 15692:               }
 15693:             }
 15694:           }
 15695:           xc = 0L;
 15696:         }
 15697:       } else if (xe == 63) {  //63。dの末尾まで整数部
 15698:         if (xc != 0L) {  //小数部が0ではない
 15699:           epbFpsr |= EPB_FPSR_X2;  //不正確な結果
 15700:           if (xc < 0L && (xd << -1 | xc << 1) != 0L) {  //guard bitが1かつLSBまたはguard bit以外の端数が0ではない
 15701:             xd++;  //絶対値に1を加える
 15702:             if (xd >= 0L) {  //dから溢れた
 15703:               xd = MSB;
 15704:               xe++;
 15705:               if ((short) xe != xe) {  //オーバーフローした
 15706:                 epbFpsr |= EPB_FPSR_OF;  //オーバーフロー
 15707:                 epbExceptionOperandExponent = xf;
 15708:                 epbExceptionOperandMantissa = xd;
 15709:                 return this.sete (OVFL_RESULTS[epbRoundingPrec << 3 | epbRoundingMode << 1 | xf >>> 31]).finish ();  //±Inf
 15710:               }
 15711:             }
 15712:           }
 15713:           xc = 0L;
 15714:         }
 15715:       } else if (xe <= LEN - 2) {  //64..90。cの途中まで整数部
 15716:         if ((xc & ~m) != 0L) {  //小数部が0ではない
 15717:           epbFpsr |= EPB_FPSR_X2;  //不正確な結果
 15718:           long t = xc;  //保存して
 15719:           xc &= m;  //小数部を切り捨てる
 15720:           if ((t & -(m >> 1)) != 0L && (t & (-m | ~(m >> 1))) != 0L) {  //guard bitが1かつLSBまたはguard bit以外の端数が0ではない
 15721:             xc -= m;  //絶対値に1を加える。符号に注意
 15722:             if ((t ^ xc) < 0L) {  //cから溢れた
 15723:               xd++;
 15724:               if (xd >= 0L) {  //dから溢れた
 15725:                 xd = MSB;
 15726:                 xe++;
 15727:                 if ((short) xe != xe) {  //オーバーフローした
 15728:                   epbFpsr |= EPB_FPSR_OF;  //オーバーフロー
 15729:                   epbExceptionOperandExponent = xf;
 15730:                   epbExceptionOperandMantissa = xd;
 15731:                   return this.sete (OVFL_RESULTS[epbRoundingPrec << 3 | epbRoundingMode << 1 | xf >>> 31]).finish ();  //±Inf
 15732:                 }
 15733:               }
 15734:             }
 15735:           }
 15736:         }
 15737:       }
 15738:       //すべて整数部のときはそのまま
 15739:       return finish (xf, xe, xd, xc, 0L);
 15740:     }  //efp.rint(EFP)
 15741: 
 15742:     //------------------------------------------------------------------------
 15743:     //x = x.round ()
 15744:     //x = x.round (roundingMode)
 15745:     //x = x.round (x)
 15746:     //x = x.round (x, roundingMode)
 15747:     //  丸め
 15748:     //
 15749:     //  サイズの制限を与えずに整数に丸める
 15750:     //
 15751:     public final EFP round () {
 15752:       return this.round (this, EPB_MODE_RN);
 15753:     }  //efp.round()
 15754:     public final EFP round (int roundingMode) {
 15755:       return this.round (this, roundingMode);
 15756:     }  //efp.round(int)
 15757:     public final EFP round (EFP x) {
 15758:       return this.round (x, EPB_MODE_RN);
 15759:     }  //efp.round(EFP)
 15760:     public final EFP round (EFP x, int roundingMode) {
 15761:       return (roundingMode == EPB_MODE_RN ? this.rint (x) :
 15762:               roundingMode == EPB_MODE_RM ? this.floor (x) :
 15763:               roundingMode == EPB_MODE_RP ? this.ceil (x) :
 15764:               this.trunc (x));
 15765:     }  //efp.round(EFP,int)
 15766: 
 15767:     //------------------------------------------------------------------------
 15768:     //x = x.roundd ()
 15769:     //x = x.roundd (roundingMode)
 15770:     //x = x.roundd (x)
 15771:     //x = x.roundd (x, roundingMode)
 15772:     //  double丸め
 15773:     //
 15774:     //  この関数はepbRoundingModeとepbRoundingPrecを無視する
 15775:     //  double(指数部11bit,仮数部52+1bit,非正規化数を含む)で表現できる値に丸める
 15776:     //  doubleで表現できないときは±Infに変換する
 15777:     //
 15778:     public final EFP roundd () {
 15779:       return this.roundd (this, EPB_MODE_RN);
 15780:     }  //efp.roundd()
 15781:     public final EFP roundd (int roundingMode) {
 15782:       return this.roundd (this, roundingMode);
 15783:     }  //efp.roundd(int)
 15784:     public final EFP roundd (EFP x) {
 15785:       return this.roundd (x, EPB_MODE_RN);
 15786:     }  //efp.roundd(EFP)
 15787:     public final EFP roundd (EFP x, int roundingMode) {
 15788:       int xf = x.flg;
 15789:       if (xf << 1 != 0) {  //±0,±Inf,NaN
 15790:         this.flg = xf;
 15791:         return this;
 15792:       }
 15793:       //±0,±Inf,NaN以外
 15794:       int xe = x.epp;  //正規化数は-1022<=xe<=1023、非正規化数は-1075<=xe<=-1023
 15795:       long xd = x.dvl;
 15796:       long xc = x.cvl;
 15797:       if (xe < -1075) {  //指数部が小さすぎる。非正規化数の最小値は2^-1074だが丸めで繰り上がる場合があるので一旦2^-1075まで受け入れる
 15798:         epbFpsr |= EPB_FPSR_UF | EPB_FPSR_X2;  //アンダーフロー、不正確な結果
 15799:         epbExceptionOperandExponent = xf | 0x3fff + 0x6000 + xe << 16;
 15800:         epbExceptionOperandMantissa = xd;
 15801:         return this.sete (UNFL_RESULTS[EPB_PREC_DBL << 3 | roundingMode << 1 | xf >>> 31]);  //±0
 15802:       }
 15803:       if (1023 < xe) {  //指数部が大きすぎる
 15804:         if (true) {
 15805:           epbFpsr |= EPB_FPSR_OF;  //オーバーフロー
 15806:           if ((xd << 53 | xc) != 0L) {  //端数が0ではない
 15807:             epbFpsr |= EPB_FPSR_X2;  //不正確な結果
 15808:           }
 15809:         } else {
 15810:           epbFpsr |= EPB_FPSR_OF | EPB_FPSR_X2;  //オーバーフロー、不正確な結果
 15811:         }
 15812:         epbExceptionOperandExponent = xf | 0x3fff - 0x6000 + xe << 16;
 15813:         epbExceptionOperandMantissa = xd;
 15814:         return this.sete (OVFL_RESULTS[EPB_PREC_DBL << 3 | roundingMode << 1 | xf >>> 31]);  //±Inf
 15815:       }
 15816:       long xb = 0L;
 15817:       int o = xe <= -1023 ? 11 + -1022 - xe : 11;  //右にずらすbit数。正規化数は11、非正規化数は11+1<=o<=11+53
 15818:       if (o < 64) {
 15819:         xb = xc << -o;
 15820:         xc = xd << -o | xc >>> o;
 15821:         xd >>>= o;
 15822:       } else {
 15823:         xb = xc;
 15824:         xc = xd;
 15825:         xd = 0L;
 15826:       }
 15827:       if ((xc | xb) != 0L) {  //端数が0ではない
 15828:         epbFpsr |= EPB_FPSR_X2;  //不正確な結果
 15829:         epbExceptionOperandExponent = x.flg & M | 0x3fff + 0x6000 + x.epp << 16;
 15830:         epbExceptionOperandMantissa = x.dvl;
 15831:         if (roundingMode == EPB_MODE_RN && xc < 0L && (xd << 63 | xc << 1 | xb) != 0L ||  //RNでguard bitが1かつLSBまたはguard bit以外の端数が0ではないまたは
 15832:             roundingMode == EPB_MODE_RM && xf < 0 ||  //端数が0ではなくてRMで-または
 15833:             roundingMode == EPB_MODE_RP && 0 <= xf) {  //端数が0ではなくてRPで+のとき
 15834:           xd++;  //繰り上げる
 15835:           if (xd >>> 53 != 0L) {  //繰り上がって溢れたとき
 15836:             xd = 1L << 52;
 15837:             xe++;  //指数部をインクリメントする。ここでxe=1024になる場合がある
 15838:             if (1023 < xe) {  //指数部が大きすぎる
 15839:               epbFpsr |= EPB_FPSR_OF;  //オーバーフロー
 15840:               return this.sete (OVFL_RESULTS[EPB_PREC_DBL << 3 | roundingMode << 1 | xf >>> 31]);  //±Inf
 15841:             }
 15842:           } else if (11 < o) {  //非正規化数のとき
 15843:             if (xd << o - 1 < 0L) {  //1bit増えたとき
 15844:               xe++;  //指数部をインクリメントする
 15845: /* roundd */
 15846:               if (xe == -1022) {  //非正規化数が繰り上がって正規化数になったとき
 15847:                 //xd = 1L << 52;
 15848:                 epbFpsr |= EPB_FPSR_UF | EPB_FPSR_X2;  //アンダーフロー、不正確な結果
 15849:                 epbExceptionOperandExponent = xf | 0x3fff + 0x6000 + xe << 16;
 15850:                 epbExceptionOperandMantissa = xd;
 15851:               }
 15852: /**/
 15853:             }
 15854:           }
 15855:         }
 15856:         //RZ toward zeroのときは端数を切り捨てるだけなので何もしなくてよい
 15857:         if (xe <= -1023) {  //非正規化数
 15858:           epbFpsr |= EPB_FPSR_UF;  //アンダーフロー
 15859:           if (xd == 0L) {  //非正規化数でxe==-1075だったとき、先頭の1がxcにあって丸めで繰り上がらなかった
 15860:             return this.sete (UNFL_RESULTS[EPB_PREC_DBL << 3 | roundingMode << 1 | xf >>> 31]);  //±0
 15861:           }
 15862:         }  //if 非正規化数
 15863:       } else {  //端数が0
 15864:         if (xe <= -1023) {  //非正規化数
 15865:           epbFpsr |= EPB_FPSR_UF;  //アンダーフロー
 15866:           epbExceptionOperandExponent = x.flg & M | 0x3fff + 0x6000 + x.epp << 16;
 15867:           epbExceptionOperandMantissa = x.dvl;
 15868:           if (xd == 0L) {  //非正規化数でxe==-1075だったとき、先頭の1がxcにあって丸めで繰り上がらなかった
 15869:             return this.sete (UNFL_RESULTS[EPB_PREC_DBL << 3 | roundingMode << 1 | xf >>> 31]);  //±0
 15870:           }
 15871:         }  //if 非正規化数
 15872:       }  //if 端数が0ではない/端数が0
 15873:       xd <<= Long.numberOfLeadingZeros (xd);  //xcとxbはゴミが残っているので加えないこと
 15874:       //結果
 15875:       this.flg = xf;
 15876:       this.epp = xe;
 15877:       this.dvl = xd;
 15878:       this.cvl = 0L;
 15879:       return this;
 15880:     }  //efp.roundd(EFP,int)
 15881: 
 15882:     //------------------------------------------------------------------------
 15883:     //x = x.roundf ()
 15884:     //x = x.roundf (roundingMode)
 15885:     //y = y.roundf (x)
 15886:     //y = y.roundf (x, roundingMode)
 15887:     //  float丸め
 15888:     //
 15889:     //  この関数はepbRoundingModeとepbRoundingPrecを無視する
 15890:     //  float(指数部8bit,仮数部23+1bit,非正規化数を含む)で表現できる値に丸める
 15891:     //  floatで表現できないときは±Infに変換する
 15892:     //
 15893:     public final EFP roundf () {
 15894:       return this.roundf (this, EPB_MODE_RN);
 15895:     }  //efp.roundf()
 15896:     public final EFP roundf (int roundingMode) {
 15897:       return this.roundf (this, roundingMode);
 15898:     }  //efp.roundf(int)
 15899:     public final EFP roundf (EFP x) {
 15900:       return this.roundf (x, EPB_MODE_RN);
 15901:     }  //efp.roundf(EFP)
 15902:     public final EFP roundf (EFP x, int roundingMode) {
 15903:       int xf = x.flg;
 15904:       if (xf << 1 != 0) {  //±0,±Inf,NaN
 15905:         this.flg = xf;
 15906:         return this;
 15907:       }
 15908:       //±0,±Inf,NaN以外
 15909:       int xe = x.epp;  //正規化数は-126<=xe<=127、非正規化数は-149<=xe<=-127
 15910:       long xd = x.dvl;
 15911:       long xc = x.cvl;
 15912:       if (xe < -150) {  //指数部が小さすぎる。非正規化数の最小値は2^-149だが丸めで繰り上がる場合があるので一旦2^-150まで受け入れる
 15913:         epbFpsr |= EPB_FPSR_UF | EPB_FPSR_X2;  //アンダーフロー、不正確な結果
 15914:         epbExceptionOperandExponent = xf | 0x3fff + 0x6000 + xe << 16;
 15915:         epbExceptionOperandMantissa = xd;
 15916:         return this.sete (UNFL_RESULTS[EPB_PREC_SGL << 3 | roundingMode << 1 | xf >>> 31]);  //±0
 15917:       }
 15918:       if (127 < xe) {  //指数部が大きすぎる
 15919:         if (true) {
 15920:           epbFpsr |= EPB_FPSR_OF;  //オーバーフロー
 15921:           if ((xd << 24 | xc) != 0L) {  //端数が0ではない
 15922:             epbFpsr |= EPB_FPSR_X2;  //不正確な結果
 15923:           }
 15924:         } else {
 15925:           epbFpsr |= EPB_FPSR_OF | EPB_FPSR_X2;  //オーバーフロー、不正確な結果
 15926:         }
 15927:         epbExceptionOperandExponent = xf | 0x3fff - 0x6000 + xe << 16;
 15928:         epbExceptionOperandMantissa = xd;
 15929:         return this.sete (OVFL_RESULTS[EPB_PREC_SGL << 3 | roundingMode << 1 | xf >>> 31]);  //±Inf
 15930:       }
 15931:       long xb = 0L;
 15932:       int o = xe <= -127 ? 40 + -126 - xe : 40;  //右にずらすbit数。正規化数は40、非正規化数は40+1<=o<=40+24
 15933:       if (o < 64) {
 15934:         xb = xc << -o;
 15935:         xc = xd << -o | xc >>> o;
 15936:         xd >>>= o;
 15937:       } else {
 15938:         xb = xc;
 15939:         xc = xd;
 15940:         xd = 0L;
 15941:       }
 15942:       if ((xc | xb) != 0L) {  //端数が0ではない
 15943:         epbFpsr |= EPB_FPSR_X2;  //不正確な結果
 15944:         epbExceptionOperandExponent = x.flg & M | 0x3fff + 0x6000 + x.epp << 16;
 15945:         epbExceptionOperandMantissa = x.dvl;
 15946:         if (roundingMode == EPB_MODE_RN && xc < 0L && (xd << -1 | xc << 1 | xb) != 0L ||  //RNでguard bitが1かつLSBまたはguard bit以外の端数が0ではないまたは
 15947:             roundingMode == EPB_MODE_RM && xf < 0 ||  //端数が0ではなくてRMで-または
 15948:             roundingMode == EPB_MODE_RP && 0 <= xf) {  //端数が0ではなくてRPで+のとき
 15949:           xd++;  //繰り上げる
 15950:           if (xd >>> 24 != 0L) {  //繰り上がって溢れたとき
 15951:             xd = 1L << 23;
 15952:             xe++;  //指数部をインクリメントする。ここでxe=128になる場合がある
 15953:             if (127 < xe) {  //指数部が大きすぎる
 15954:               epbFpsr |= EPB_FPSR_OF;  //オーバーフロー
 15955:               return this.sete (OVFL_RESULTS[EPB_PREC_SGL << 3 | roundingMode << 1 | xf >>> 31]);  //±Inf
 15956:             }
 15957:           } else if (40 < o) {  //非正規化数のとき
 15958:             if (xd << o - 1 < 0L) {  //1bit増えたとき
 15959:               xe++;  //指数部をインクリメントする
 15960: /* roundf */
 15961:               if (xe == -126) {  //非正規化数が繰り上がって正規化数になったとき
 15962:                 //xd = 1L << 23;
 15963:                 epbFpsr |= EPB_FPSR_UF | EPB_FPSR_X2;  //アンダーフロー、不正確な結果
 15964:                 epbExceptionOperandExponent = xf | 0x3fff + 0x6000 + xe << 16;
 15965:                 epbExceptionOperandMantissa = xd;
 15966:               }
 15967: /**/
 15968:             }
 15969:           }
 15970:         }
 15971:         //RZ toward zeroのときは端数を切り捨てるだけなので何もしなくてよい
 15972:         if (xe <= -127) {  //非正規化数
 15973:           epbFpsr |= EPB_FPSR_UF;  //アンダーフロー
 15974:           if (xd == 0L) {  //非正規化数でxe==-150だったとき、先頭の1がxcにあって丸めで繰り上がらなかった
 15975:             return this.sete (UNFL_RESULTS[EPB_PREC_SGL << 3 | roundingMode << 1 | xf >>> 31]);  //±0
 15976:           }
 15977:         }  //if 非正規化数
 15978:       } else {  //端数が0
 15979:         if (xe <= -127) {  //非正規化数
 15980:           epbFpsr |= EPB_FPSR_UF;  //アンダーフロー
 15981:           epbExceptionOperandExponent = x.flg & M | 0x3fff + 0x6000 + x.epp << 16;
 15982:           epbExceptionOperandMantissa = x.dvl;
 15983:           if (xd == 0L) {  //非正規化数でxe==-150だったとき、先頭の1がxcにあって丸めで繰り上がらなかった
 15984:             return this.sete (UNFL_RESULTS[EPB_PREC_SGL << 3 | roundingMode << 1 | xf >>> 31]);  //±0
 15985:           }
 15986:         }
 15987:       }
 15988:       xd <<= Long.numberOfLeadingZeros (xd);  //xcとxbはゴミが残っているので加えないこと
 15989:       //結果
 15990:       this.flg = xf;
 15991:       this.epp = xe;
 15992:       this.dvl = xd;
 15993:       this.cvl = 0L;
 15994:       return this;
 15995:     }  //efp.roundf(EFP,int)
 15996: 
 15997:     //------------------------------------------------------------------------
 15998:     //x = x.roundg ()
 15999:     //x = x.roundg (roundingMode)
 16000:     //y = y.roundg (x)
 16001:     //y = y.roundg (x, roundingMode)
 16002:     //  xsg丸め
 16003:     //
 16004:     //  この関数はepbRoundingModeとepbRoundingPrecを無視する
 16005:     //  xsg(指数部15bit,仮数部23+1bit,非正規化数を含む)で表現できる値に丸める
 16006:     //  xsgで表現できないときは±Infに変換する
 16007:     //
 16008:     public final EFP roundg () {
 16009:       return this.roundg (this, EPB_MODE_RN);
 16010:     }  //efp.roundg()
 16011:     public final EFP roundg (int roundingMode) {
 16012:       return this.roundg (this, roundingMode);
 16013:     }  //efp.roundg(int)
 16014:     public final EFP roundg (EFP x) {
 16015:       return this.roundg (x, EPB_MODE_RN);
 16016:     }  //efp.roundg(EFP)
 16017:     public final EFP roundg (EFP x, int roundingMode) {
 16018:       int xf = x.flg;
 16019:       if (xf << 1 != 0) {  //±0,±Inf,NaN
 16020:         this.flg = xf;
 16021:         return this;
 16022:       }
 16023:       //±0,±Inf,NaN以外
 16024:       int xe = x.epp;  //正規化数は-16383<=xe<=16383、非正規化数は-16406<=xe<=-16384
 16025:       long xd = x.dvl;
 16026:       long xc = x.cvl;
 16027:       if (xe < -16407) {  //指数部が小さすぎる。非正規化数の最小値は2^-16406だが丸めで繰り上がる場合があるので一旦2^-16407まで受け入れる
 16028:         epbFpsr |= EPB_FPSR_UF | EPB_FPSR_X2;  //アンダーフロー、不正確な結果
 16029:         epbExceptionOperandExponent = xf | 0x3fff + 0x6000 + xe << 16;
 16030:         epbExceptionOperandMantissa = xd;
 16031:         return this.sete (UNFL_RESULTS[EPB_PREC_XSG << 3 | roundingMode << 1 | xf >>> 31]);  //±0
 16032:       }
 16033:       if (16383 < xe) {  //指数部が大きすぎる
 16034:         if (true) {
 16035:           epbFpsr |= EPB_FPSR_OF;  //オーバーフロー
 16036:           if ((xd << 24 | xc) != 0L) {  //端数が0ではない
 16037:             epbFpsr |= EPB_FPSR_X2;  //不正確な結果
 16038:           }
 16039:         } else {
 16040:           epbFpsr |= EPB_FPSR_OF | EPB_FPSR_X2;  //オーバーフロー、不正確な結果
 16041:         }
 16042:         epbExceptionOperandExponent = xf | 0x3fff - 0x6000 + xe << 16;
 16043:         epbExceptionOperandMantissa = xd;
 16044:         return this.sete (OVFL_RESULTS[EPB_PREC_XSG << 3 | roundingMode << 1 | xf >>> 31]);  //±Inf
 16045:       }
 16046:       long xb = 0L;
 16047:       int o = xe <= -16384 ? 40 + -16383 - xe : 40;  //右にずらすbit数。正規化数は40、非正規化数は40+1<=o<=40+24
 16048:       if (o < 64) {
 16049:         xb = xc << -o;
 16050:         xc = xd << -o | xc >>> o;
 16051:         xd >>>= o;
 16052:       } else {
 16053:         xb = xc;
 16054:         xc = xd;
 16055:         xd = 0L;
 16056:       }
 16057:       if ((xc | xb) != 0L) {  //端数が0ではない
 16058:         epbFpsr |= EPB_FPSR_X2;  //不正確な結果
 16059:         epbExceptionOperandExponent = x.flg & M | 0x3fff + 0x6000 + x.epp << 16;
 16060:         epbExceptionOperandMantissa = x.dvl;
 16061:         if (roundingMode == EPB_MODE_RN && xc < 0L && (xd << -1 | xc << 1 | xb) != 0L ||  //RNでguard bitが1かつLSBまたはguard bit以外の端数が0ではないまたは
 16062:             roundingMode == EPB_MODE_RM && xf < 0 ||  //端数が0ではなくてRMで-または
 16063:             roundingMode == EPB_MODE_RP && 0 <= xf) {  //端数が0ではなくてRPで+のとき
 16064:           xd++;  //繰り上げる
 16065:           if (xd >>> 24 != 0L) {  //繰り上がって溢れたとき
 16066:             xd = 1L << 23;
 16067:             xe++;  //指数部をインクリメントする。ここでxe=16384になる場合がある
 16068:             if (16383 < xe) {  //指数部が大きすぎる
 16069:               epbFpsr |= EPB_FPSR_OF;  //オーバーフロー
 16070:               return this.sete (OVFL_RESULTS[EPB_PREC_XSG << 3 | roundingMode << 1 | xf >>> 31]);  //±Inf
 16071:             }
 16072:           } else if (40 < o) {  //非正規化数のとき
 16073:             if (xd << o - 1 < 0L) {  //1bit増えたとき
 16074:               xe++;  //指数部をインクリメントする
 16075: /* roundg
 16076:               if (xe == -16383) {  //非正規化数が繰り上がって正規化数になったとき
 16077:                 //xd = 1L << 23;
 16078:                 epbFpsr |= EPB_FPSR_UF | EPB_FPSR_X2;  //アンダーフロー、不正確な結果
 16079:                 epbExceptionOperandExponent = xf | 0x3fff + 0x6000 + xe << 16;
 16080:                 epbExceptionOperandMantissa = xd;
 16081:               }
 16082: */
 16083:             }
 16084:           }
 16085:         }
 16086:         //RZ toward zeroのときは端数を切り捨てるだけなので何もしなくてよい
 16087:         if (xe <= -16384) {  //非正規化数
 16088:           epbFpsr |= EPB_FPSR_UF;  //アンダーフロー
 16089:           if (xd == 0L) {  //非正規化数でxe==-16407だったとき、先頭の1がxcにあって丸めで繰り上がらなかった
 16090:             return this.sete (UNFL_RESULTS[EPB_PREC_XSG << 3 | roundingMode << 1 | xf >>> 31]);  //±0
 16091:           }
 16092:         }  //if 非正規化数
 16093:       } else {  //端数が0
 16094:         if (xe <= -16384) {  //非正規化数
 16095:           epbFpsr |= EPB_FPSR_UF;  //アンダーフロー
 16096:           epbExceptionOperandExponent = x.flg & M | 0x3fff + 0x6000 + x.epp << 16;
 16097:           epbExceptionOperandMantissa = x.dvl;
 16098:           if (xd == 0L) {  //非正規化数でxe==-16407だったとき、先頭の1がxcにあって丸めで繰り上がらなかった
 16099:             return this.sete (UNFL_RESULTS[EPB_PREC_XSG << 3 | roundingMode << 1 | xf >>> 31]);  //±0
 16100:           }
 16101:         }
 16102:       }
 16103:       xd <<= Long.numberOfLeadingZeros (xd);  //xcとxbはゴミが残っているので加えないこと
 16104:       //結果
 16105:       this.flg = xf;
 16106:       this.epp = xe;
 16107:       this.dvl = xd;
 16108:       this.cvl = 0L;
 16109:       return this;
 16110:     }  //efp.roundg(EFP,int)
 16111: 
 16112:     //------------------------------------------------------------------------
 16113:     //x = x.roundi ()
 16114:     //x = x.roundi (roundingMode)
 16115:     //x = x.roundi (x)
 16116:     //x = x.roundi (x, roundingMode)
 16117:     //  int丸め
 16118:     //
 16119:     //  int(32bit整数)に丸める
 16120:     //  2^31-1よりも大きい数は2^31-1に、-2^31よりも小さい数は-2^31に変換する(飽和変換)
 16121:     //  NaNは0に変換する
 16122:     //
 16123:     public final EFP roundi () {
 16124:       return this.roundi (this, EPB_MODE_RN);
 16125:     }  //efp.roundi()
 16126:     public final EFP roundi (int roundingMode) {
 16127:       return this.roundi (this, roundingMode);
 16128:     }  //efp.roundi(int)
 16129:     public final EFP roundi (EFP x) {
 16130:       return this.roundi (x, EPB_MODE_RN);
 16131:     }  //efp.roundi(EFP)
 16132:     public final EFP roundi (EFP x, int roundingMode) {
 16133:       return this.seti (x.geti (roundingMode));
 16134:     }  //efp.roundi(EFP,int)
 16135: 
 16136:     //------------------------------------------------------------------------
 16137:     //x = x.roundl ()
 16138:     //x = x.roundl (roundingMode)
 16139:     //x = x.roundl (x)
 16140:     //x = x.roundl (x, roundingMode)
 16141:     //  long丸め
 16142:     //
 16143:     //  long(64bit整数)に丸める
 16144:     //  2^63-1よりも大きい数は2^63-1に、-2^63よりも小さい数は-2^63に変換する(飽和変換)
 16145:     //  NaNは0に変換する
 16146:     //
 16147:     public final EFP roundl () {
 16148:       return this.roundl (this, EPB_MODE_RN);
 16149:     }  //efp.roundl()
 16150:     public final EFP roundl (int roundingMode) {
 16151:       return this.roundl (this, roundingMode);
 16152:     }  //efp.roundl(int)
 16153:     public final EFP roundl (EFP x) {
 16154:       return this.roundl (x, EPB_MODE_RN);
 16155:     }  //efp.roundl(EFP)
 16156:     public final EFP roundl (EFP x, int roundingMode) {
 16157:       return this.setl (x.getl (roundingMode));
 16158:     }  //efp.roundl(EFP,int)
 16159: 
 16160:     //------------------------------------------------------------------------
 16161:     //x = x.roundmand ()
 16162:     //x = x.roundmand (roundingMode)
 16163:     //x = x.roundmand (x)
 16164:     //x = x.roundmand (x, roundingMode)
 16165:     //  仮数部double丸め
 16166:     //  仮数部を(1+52)bitに丸める
 16167:     //
 16168:     public final EFP roundmand () {
 16169:       return this.roundmand (this, EPB_MODE_RN);
 16170:     }  //efp.roundmand()
 16171:     public final EFP roundmand (int roundingMode) {
 16172:       return this.roundmand (this, roundingMode);
 16173:     }  //efp.roundmand(int)
 16174:     public final EFP roundmand (EFP x) {
 16175:       return this.roundmand (x, EPB_MODE_RN);
 16176:     }  //efp.roundmand(EFP)
 16177:     public final EFP roundmand (EFP x, int roundingMode) {
 16178:       int xf = x.flg;
 16179:       if (xf << 1 != 0) {  //±0,±Inf,NaN
 16180:         this.flg = xf;
 16181:         return this;
 16182:       }
 16183:       //±0,±Inf,NaN以外
 16184:       int xe = x.epp;
 16185:       long xd = x.dvl;
 16186:       long xc = x.cvl;
 16187:       long xb = 0L;
 16188:       xb = xc << -11;
 16189:       xc = xd << -11 | xc >>> 11;
 16190:       xd >>>= 11;
 16191:       if ((xc | xb) != 0L) {  //端数が0ではない
 16192:         epbFpsr |= EPB_FPSR_X2;  //不正確な結果
 16193:         epbExceptionOperandExponent = x.flg & M | 0x3fff + 0x6000 + x.epp << 16;
 16194:         epbExceptionOperandMantissa = x.dvl;
 16195:         if (roundingMode == EPB_MODE_RN && xc < 0L && (xd << 63 | xc << 1 | xb) != 0L ||  //RNでguard bitが1かつLSBまたはguard bit以外の端数が0ではないまたは
 16196:             roundingMode == EPB_MODE_RM && xf < 0 ||  //端数が0ではなくてRMで-または
 16197:             roundingMode == EPB_MODE_RP && 0 <= xf) {  //端数が0ではなくてRPで+のとき
 16198:           xd++;  //繰り上げる
 16199:           if (xd >>> 53 != 0L) {  //繰り上がって溢れたとき
 16200:             xd = 1L << 52;
 16201:             xe++;  //指数部をインクリメントする
 16202:           }
 16203:         }
 16204:         //RZ toward zeroのときは端数を切り捨てるだけなので何もしなくてよい
 16205:       }  //if 端数が0ではない
 16206:       xd <<= 11;  //xcとxbはゴミが残っているので加えないこと
 16207:       //結果
 16208:       this.flg = xf;
 16209:       this.epp = xe;
 16210:       this.dvl = xd;
 16211:       this.cvl = 0L;
 16212:       return this;
 16213:     }  //efp.roundmand(EFP,int)
 16214: 
 16215:     //------------------------------------------------------------------------
 16216:     //x = x.roundmanf ()
 16217:     //x = x.roundmanf (roundingMode)
 16218:     //y = y.roundmanf (x)
 16219:     //y = y.roundmanf (x, roundingMode)
 16220:     //  仮数部float丸め
 16221:     //  仮数部を(1+23)bitに丸める
 16222:     //
 16223:     public final EFP roundmanf () {
 16224:       return this.roundmanf (this, EPB_MODE_RN);
 16225:     }  //efp.roundmanf()
 16226:     public final EFP roundmanf (int roundingMode) {
 16227:       return this.roundmanf (this, roundingMode);
 16228:     }  //efp.roundmanf(int)
 16229:     public final EFP roundmanf (EFP x) {
 16230:       return this.roundmanf (x, EPB_MODE_RN);
 16231:     }  //efp.roundmanf(EFP)
 16232:     public final EFP roundmanf (EFP x, int roundingMode) {
 16233:       int xf = x.flg;
 16234:       if (xf << 1 != 0) {  //±0,±Inf,NaN
 16235:         this.flg = xf;
 16236:         return this;
 16237:       }
 16238:       //±0,±Inf,NaN以外
 16239:       int xe = x.epp;
 16240:       long xd = x.dvl;
 16241:       long xc = x.cvl;
 16242:       long xb = 0L;
 16243:       xb = xc << -40;
 16244:       xc = xd << -40 | xc >>> 40;
 16245:       xd >>>= 40;
 16246:       if ((xc | xb) != 0L) {  //端数が0ではない
 16247:         epbFpsr |= EPB_FPSR_X2;  //不正確な結果
 16248:         epbExceptionOperandExponent = x.flg & M | 0x3fff + 0x6000 + x.epp << 16;
 16249:         epbExceptionOperandMantissa = x.dvl;
 16250:         if (roundingMode == EPB_MODE_RN && xc < 0L && (xd << 63 | xc << 1 | xb) != 0L ||  //RNでguard bitが1かつLSBまたはguard bit以外の端数が0ではないまたは
 16251:             roundingMode == EPB_MODE_RM && xf < 0 ||  //端数が0ではなくてRMで-または
 16252:             roundingMode == EPB_MODE_RP && 0 <= xf) {  //端数が0ではなくてRPで+のとき
 16253:           xd++;  //繰り上げる
 16254:           if (xd >>> 24 != 0L) {  //繰り上がって溢れたとき
 16255:             xd = 1L << 23;
 16256:             xe++;  //指数部をインクリメントする
 16257:           }
 16258:         }
 16259:         //RZ toward zeroのときは端数を切り捨てるだけなので何もしなくてよい
 16260:       }  //if 端数が0ではない
 16261:       xd <<= 40;  //xcとxbはゴミが残っているので加えないこと
 16262:       //結果
 16263:       this.flg = xf;
 16264:       this.epp = xe;
 16265:       this.dvl = xd;
 16266:       this.cvl = 0L;
 16267:       return this;
 16268:     }  //efp.roundmanf(EFP,int)
 16269: 
 16270:     //------------------------------------------------------------------------
 16271:     //x = x.roundmanx ()
 16272:     //x = x.roundmanx (roundingMode)
 16273:     //x = x.roundmanx (x)
 16274:     //x = x.roundmanx (x, roundingMode)
 16275:     //  仮数部extended丸め
 16276:     //  仮数部を(1+63)bitに丸める
 16277:     //
 16278:     public final EFP roundmanx () {
 16279:       return this.roundmanx (this, EPB_MODE_RN);
 16280:     }  //efp.roundmanx()
 16281:     public final EFP roundmanx (int roundingMode) {
 16282:       return this.roundmanx (this, roundingMode);
 16283:     }  //efp.roundmanx(int)
 16284:     public final EFP roundmanx (EFP x) {
 16285:       return this.roundmanx (x, EPB_MODE_RN);
 16286:     }  //efp.roundmanx(EFP)
 16287:     public final EFP roundmanx (EFP x, int roundingMode) {
 16288:       int xf = x.flg;
 16289:       if (xf << 1 != 0) {  //±0,±Inf,NaN
 16290:         this.flg = xf;
 16291:         return this;
 16292:       }
 16293:       //±0,±Inf,NaN以外
 16294:       int xe = x.epp;
 16295:       long xd = x.dvl;
 16296:       long xc = x.cvl;
 16297:       long xb = 0L;
 16298:       if ((xc | xb) != 0L) {  //端数が0ではない
 16299:         epbFpsr |= EPB_FPSR_X2;  //不正確な結果
 16300:         epbExceptionOperandExponent = x.flg & M | 0x3fff + 0x6000 + x.epp << 16;
 16301:         epbExceptionOperandMantissa = x.dvl;
 16302:         if (roundingMode == EPB_MODE_RN && xc < 0L && (xd << 63 | xc << 1 | xb) != 0L ||  //RNでguard bitが1かつLSBまたはguard bit以外の端数が0ではないまたは
 16303:             roundingMode == EPB_MODE_RM && xf < 0 ||  //端数が0ではなくてRMで-または
 16304:             roundingMode == EPB_MODE_RP && 0 <= xf) {  //端数が0ではなくてRPで+のとき
 16305:           xd++;  //繰り上げる
 16306:           if (xd == 0L) {  //繰り上がって溢れたとき
 16307:             xd = MSB;
 16308:             xe++;  //指数部をインクリメントする
 16309:           }
 16310:         }
 16311:         //RZ toward zeroのときは端数を切り捨てるだけなので何もしなくてよい
 16312:       }  //if 端数が0ではない
 16313:       xd <<= Long.numberOfLeadingZeros (xd);  //xcとxbはゴミが残っているので加えないこと
 16314:       //結果
 16315:       this.flg = xf;
 16316:       this.epp = xe;
 16317:       this.dvl = xd;
 16318:       this.cvl = 0L;
 16319:       return this;
 16320:     }  //efp.roundmanx(EFP,int)
 16321: 
 16322:     //------------------------------------------------------------------------
 16323:     //x = x.roundmany ()
 16324:     //x = x.roundmany (roundingMode)
 16325:     //x = x.roundmany (x)
 16326:     //x = x.roundmany (x, roundingMode)
 16327:     //  仮数部triple丸め
 16328:     //  仮数部を(1+79)bitに丸める
 16329:     //
 16330:     public final EFP roundmany () {
 16331:       return this.roundmany (this, EPB_MODE_RN);
 16332:     }  //efp.roundmany()
 16333:     public final EFP roundmany (int roundingMode) {
 16334:       return this.roundmany (this, roundingMode);
 16335:     }  //efp.roundmany(int)
 16336:     public final EFP roundmany (EFP x) {
 16337:       return this.roundmany (x, EPB_MODE_RN);
 16338:     }  //efp.roundmany(EFP)
 16339:     public final EFP roundmany (EFP x, int roundingMode) {
 16340:       int xf = x.flg;
 16341:       if (xf << 1 != 0) {  //±0,±Inf,NaN
 16342:         this.flg = xf;
 16343:         return this;
 16344:       }
 16345:       //±0,±Inf,NaN以外
 16346:       int xe = x.epp;
 16347:       long xd = x.dvl;
 16348:       long xc = x.cvl;
 16349:       long xb = 0L;
 16350:       xb = xc << -48;
 16351:       xc = xd << -48 | xc >>> 48;
 16352:       xd >>>= 48;
 16353:       if (xb != 0L) {  //端数が0ではない
 16354:         epbFpsr |= EPB_FPSR_X2;  //不正確な結果
 16355:         epbExceptionOperandExponent = x.flg & M | 0x3fff + 0x6000 + x.epp << 16;
 16356:         epbExceptionOperandMantissa = x.dvl;
 16357:         if (roundingMode == EPB_MODE_RN && xb < 0L && (xc << 63 | xb << 1) != 0L ||  //RNでguard bitが1かつLSBまたはguard bit以外の端数が0ではないまたは
 16358:             roundingMode == EPB_MODE_RM && xf < 0 ||  //端数が0ではなくてRMで-または
 16359:             roundingMode == EPB_MODE_RP && 0 <= xf) {  //端数が0ではなくてRPで+のとき
 16360:           xc++;  //繰り上げる
 16361:           if (xc == 0L) {  //繰り上がって溢れたとき
 16362:             xd++;  //繰り上げる
 16363:             if (xd >>> 16 != 0L) {  //繰り上がって溢れたとき
 16364:               xd = 1L << 15;
 16365:               xe++;  //指数部をインクリメントする
 16366:             }
 16367:           }
 16368:         }
 16369:         //RZ toward zeroのときは端数を切り捨てるだけなので何もしなくてよい
 16370:       }  //if 端数が0ではない
 16371:       xd = xd << 48 | xc >>> -48;
 16372:       xc <<= 48;  //xbはゴミが残っているので加えないこと
 16373:       //結果
 16374:       this.flg = xf;
 16375:       this.epp = xe;
 16376:       this.dvl = xd;
 16377:       this.cvl = xc;
 16378:       return this;
 16379:     }  //efp.roundmany(EFP,int)
 16380: 
 16381:     //------------------------------------------------------------------------
 16382:     //x = x.roundx ()
 16383:     //x = x.roundx (roundingMode)
 16384:     //x = x.roundx (x)
 16385:     //x = x.roundx (x, roundingMode)
 16386:     //  extended丸め
 16387:     //
 16388:     //  この関数はepbRoundingModeとepbRoundingPrecを無視する
 16389:     //  extended(指数部15bit,仮数部64bit,非正規化数を含む)で表現できる値に丸める
 16390:     //  extendedで表現できないときは±Infに変換する
 16391:     //
 16392:     public final EFP roundx () {
 16393:       return this.roundx (this, EPB_MODE_RN);
 16394:     }  //efp.roundx()
 16395:     public final EFP roundx (int roundingMode) {
 16396:       return this.roundx (this, roundingMode);
 16397:     }  //efp.roundx(int)
 16398:     public final EFP roundx2 (int roundingMode) {
 16399:       return this.roundx2 (this, roundingMode);
 16400:     }  //efp.roundx(int)
 16401:     public final EFP roundx (EFP x) {
 16402:       return this.roundx (x, EPB_MODE_RN);
 16403:     }  //efp.roundx(EFP)
 16404:     public final EFP roundx (EFP x, int roundingMode) {
 16405:       int xf = x.flg;
 16406:       if (xf << 1 != 0) {  //±0,±Inf,NaN
 16407:         this.flg = xf;
 16408:         return this;
 16409:       }
 16410:       //±0,±Inf,NaN以外
 16411:       int xe = x.epp;  //正規化数は-16383<=xe<=16383、非正規化数は-16446<=xe<=-16384
 16412:       long xd = x.dvl;
 16413:       long xc = x.cvl;
 16414:       if (xe < -16447) {  //指数部が小さすぎる。非正規化数の最小値は2^-16446だが丸めで繰り上がる場合があるので一旦2^-16447まで受け入れる
 16415:         epbFpsr |= EPB_FPSR_UF | EPB_FPSR_X2;  //アンダーフロー、不正確な結果
 16416:         epbExceptionOperandExponent = xf | 0x3fff + 0x6000 + xe << 16;
 16417:         epbExceptionOperandMantissa = xd;
 16418:         return this.sete (UNFL_RESULTS[EPB_PREC_EXD << 3 | roundingMode << 1 | xf >>> 31]);  //±0
 16419:       }
 16420:       if (16383 < xe) {  //指数部が大きすぎる
 16421:         if (true) {
 16422:           epbFpsr |= EPB_FPSR_OF;  //オーバーフロー
 16423:           if (xc != 0L) {  //端数が0ではない
 16424:             epbFpsr |= EPB_FPSR_X2;  //不正確な結果
 16425:           }
 16426:         } else {
 16427:           epbFpsr |= EPB_FPSR_OF | EPB_FPSR_X2;  //オーバーフロー、不正確な結果
 16428:         }
 16429:         epbExceptionOperandExponent = xf | 0x3fff - 0x6000 + xe << 16;
 16430:         epbExceptionOperandMantissa = xd;
 16431:         return this.sete (OVFL_RESULTS[EPB_PREC_EXD << 3 | roundingMode << 1 | xf >>> 31]);  //±Inf
 16432:       }
 16433:       long xb = 0L;
 16434:       int o = xe <= -16384 ? 0 + -16383 - xe : 0;  //右にずらすbit数。正規化数は0、非正規化数は0+1<=o<=0+64
 16435:       if (o == 0) {
 16436:       } else if (o < 64) {
 16437:         xb = xc << -o;
 16438:         xc = xd << -o | xc >>> o;
 16439:         xd >>>= o;
 16440:       } else {
 16441:         xb = xc;
 16442:         xc = xd;
 16443:         xd = 0L;
 16444:       }
 16445:       if ((xc | xb) != 0L) {  //端数が0ではない
 16446:         epbFpsr |= EPB_FPSR_X2;  //不正確な結果
 16447:         epbExceptionOperandExponent = x.flg & M | 0x3fff + 0x6000 + x.epp << 16;
 16448:         epbExceptionOperandMantissa = x.dvl;
 16449:         if (roundingMode == EPB_MODE_RN && xc < 0L && (xd << 63 | xc << 1 | xb) != 0L ||  //RNでguard bitが1かつLSBまたはguard bit以外の端数が0ではないまたは
 16450:             roundingMode == EPB_MODE_RM && xf < 0 ||  //端数が0ではなくてRMで-または
 16451:             roundingMode == EPB_MODE_RP && 0 <= xf) {  //端数が0ではなくてRPで+のとき
 16452:           xd++;  //繰り上げる
 16453:           if (xd == 0L) {  //繰り上がって溢れたとき
 16454:             xd = MSB;
 16455:             xe++;  //指数部をインクリメントする。ここでxe=16384になる場合がある
 16456:             if (16383 < xe) {  //指数部が大きすぎる
 16457:               epbFpsr |= EPB_FPSR_OF;  //オーバーフロー
 16458:               return this.sete (OVFL_RESULTS[EPB_PREC_EXD << 3 | roundingMode << 1 | xf >>> 31]);  //±Inf
 16459:             }
 16460:           } else if (0 < o) {  //非正規化数のとき
 16461:             if (xd << o - 1 < 0L) {  //1bit増えたとき
 16462:               xe++;  //指数部をインクリメントする
 16463: /* roundx
 16464:               if (xe == -16383) {  //非正規化数が繰り上がって正規化数になったとき
 16465:                 //xd = MSB;
 16466:                 epbFpsr |= EPB_FPSR_UF | EPB_FPSR_X2;  //アンダーフロー、不正確な結果
 16467:                 epbExceptionOperandExponent = xf | 0x3fff + 0x6000 + xe << 16;
 16468:                 epbExceptionOperandMantissa = xd;
 16469:               }
 16470: */
 16471:             }
 16472:           }
 16473:         }
 16474:         //RZ toward zeroのときは端数を切り捨てるだけなので何もしなくてよい
 16475:         if (xe <= -16384) {  //非正規化数
 16476:           epbFpsr |= EPB_FPSR_UF;  //アンダーフロー
 16477:           if (xd == 0L) {  //非正規化数でxe==-16447だったとき、先頭の1がxcにあって丸めで繰り上がらなかった
 16478:             return this.sete (UNFL_RESULTS[EPB_PREC_EXD << 3 | roundingMode << 1 | xf >>> 31]);  //±0
 16479:           }
 16480:         }  //if 非正規化数
 16481:       } else {  //端数が0
 16482:         if (xe <= -16384) {  //非正規化数
 16483:           epbFpsr |= EPB_FPSR_UF;  //アンダーフロー
 16484:           epbExceptionOperandExponent = x.flg & M | 0x3fff + 0x6000 + x.epp << 16;
 16485:           epbExceptionOperandMantissa = x.dvl;
 16486:           if (xd == 0L) {  //非正規化数でxe==-16447だったとき、先頭の1がxcにあって丸めで繰り上がらなかった
 16487:             return this.sete (UNFL_RESULTS[EPB_PREC_EXD << 3 | roundingMode << 1 | xf >>> 31]);  //±0
 16488:           }
 16489:         }  //if 非正規化数
 16490:       }  //if 端数が0ではない/端数が0
 16491:       xd <<= Long.numberOfLeadingZeros (xd);  //xcとxbはゴミが残っているので加えないこと
 16492:       //結果
 16493:       this.flg = xf;
 16494:       this.epp = xe;
 16495:       this.dvl = xd;
 16496:       this.cvl = 0L;
 16497:       return this;
 16498:     }  //efp.roundx(EFP,int)
 16499:     public final EFP roundx2 (EFP x, int roundingMode) {
 16500:       int xf = x.flg;
 16501:       if (xf << 1 != 0) {  //±0,±Inf,NaN
 16502:         this.flg = xf;
 16503:         return this;
 16504:       }
 16505:       //±0,±Inf,NaN以外
 16506:       int xe = x.epp;  //正規化数は-16383<=xe<=16383、非正規化数は-16446<=xe<=-16384
 16507:       long xd = x.dvl;
 16508:       long xc = x.cvl;
 16509:       if (xe < -16447) {  //指数部が小さすぎる。非正規化数の最小値は2^-16446だが丸めで繰り上がる場合があるので一旦2^-16447まで受け入れる
 16510:         epbFpsr |= EPB_FPSR_UF | EPB_FPSR_X2;  //アンダーフロー、不正確な結果
 16511:         epbExceptionOperandExponent = xf | 0x3fff + 0x6000 + xe << 16;
 16512:         epbExceptionOperandMantissa = xd;
 16513:         return this.sete (UNFL_RESULTS[EPB_PREC_EXD << 3 | roundingMode << 1 | xf >>> 31]);  //±0
 16514:       }
 16515:       if (16383 < xe) {  //指数部が大きすぎる
 16516:         if (true) {
 16517:           epbFpsr |= EPB_FPSR_OF;  //オーバーフロー
 16518:           if (xc != 0L) {  //端数が0ではない
 16519:             epbFpsr |= EPB_FPSR_X2;  //不正確な結果
 16520:           }
 16521:         } else {
 16522:           epbFpsr |= EPB_FPSR_OF | EPB_FPSR_X2;  //オーバーフロー、不正確な結果
 16523:         }
 16524:         epbExceptionOperandExponent = xf | 0x3fff - 0x6000 + xe << 16;
 16525:         epbExceptionOperandMantissa = xd;
 16526:         return this.sete (OVFL_RESULTS[EPB_PREC_EXD << 3 | roundingMode << 1 | xf >>> 31]);  //±Inf
 16527:       }
 16528:       long xb = 0L;
 16529:       int o = xe <= -16384 ? 0 + -16383 - xe : 0;  //右にずらすbit数。正規化数は0、非正規化数は0+1<=o<=0+64
 16530:       if (o == 0) {
 16531:       } else if (o < 64) {
 16532:         xb = xc << -o;
 16533:         xc = xd << -o | xc >>> o;
 16534:         xd >>>= o;
 16535:       } else {
 16536:         xb = xc;
 16537:         xc = xd;
 16538:         xd = 0L;
 16539:       }
 16540:       if ((xc | xb) != 0L) {  //端数が0ではない
 16541:         epbFpsr |= EPB_FPSR_X2;  //不正確な結果
 16542:         epbExceptionOperandExponent = x.flg & M | 0x3fff + 0x6000 + x.epp << 16;
 16543:         epbExceptionOperandMantissa = x.dvl;
 16544:         if (roundingMode == EPB_MODE_RN && xc < 0L && (xd << 63 | xc << 1 | xb) != 0L ||  //RNでguard bitが1かつLSBまたはguard bit以外の端数が0ではないまたは
 16545:             roundingMode == EPB_MODE_RM && xf < 0 ||  //端数が0ではなくてRMで-または
 16546:             roundingMode == EPB_MODE_RP && 0 <= xf) {  //端数が0ではなくてRPで+のとき
 16547:           xd++;  //繰り上げる
 16548:           if (xd == 0L) {  //繰り上がって溢れたとき
 16549:             xd = MSB;
 16550:             xe++;  //指数部をインクリメントする。ここでxe=16384になる場合がある
 16551:             if (16383 < xe) {  //指数部が大きすぎる
 16552:               epbFpsr |= EPB_FPSR_OF;  //オーバーフロー
 16553:               return this.sete (OVFL_RESULTS[EPB_PREC_EXD << 3 | roundingMode << 1 | xf >>> 31]);  //±Inf
 16554:             }
 16555:           } else if (0 < o) {  //非正規化数のとき
 16556:             if (xd << o - 1 < 0L) {  //1bit増えたとき
 16557:               xe++;  //指数部をインクリメントする
 16558: /* roundx2 */
 16559:               if (xe == -16383) {  //非正規化数が繰り上がって正規化数になったとき
 16560:                 //xd = MSB;
 16561:                 epbFpsr |= EPB_FPSR_UF | EPB_FPSR_X2;  //アンダーフロー、不正確な結果
 16562:                 epbExceptionOperandExponent = xf | 0x3fff + 0x6000 + xe << 16;
 16563:                 epbExceptionOperandMantissa = xd;
 16564:               }
 16565: /**/
 16566:             }
 16567:           }
 16568:         }
 16569:         //RZ toward zeroのときは端数を切り捨てるだけなので何もしなくてよい
 16570:         if (xe <= -16384) {  //非正規化数
 16571:           epbFpsr |= EPB_FPSR_UF;  //アンダーフロー
 16572:           if (xd == 0L) {  //非正規化数でxe==-16447だったとき、先頭の1がxcにあって丸めで繰り上がらなかった
 16573:             return this.sete (UNFL_RESULTS[EPB_PREC_EXD << 3 | roundingMode << 1 | xf >>> 31]);  //±0
 16574:           }
 16575:         }  //if 非正規化数
 16576:       } else {  //端数が0
 16577:         if (xe <= -16384) {  //非正規化数
 16578:           epbFpsr |= EPB_FPSR_UF;  //アンダーフロー
 16579:           epbExceptionOperandExponent = x.flg & M | 0x3fff + 0x6000 + x.epp << 16;
 16580:           epbExceptionOperandMantissa = x.dvl;
 16581:           if (xd == 0L) {  //非正規化数でxe==-16447だったとき、先頭の1がxcにあって丸めで繰り上がらなかった
 16582:             return this.sete (UNFL_RESULTS[EPB_PREC_EXD << 3 | roundingMode << 1 | xf >>> 31]);  //±0
 16583:           }
 16584:         }  //if 非正規化数
 16585:       }  //if 端数が0ではない/端数が0
 16586:       xd <<= Long.numberOfLeadingZeros (xd);  //xcとxbはゴミが残っているので加えないこと
 16587:       //結果
 16588:       this.flg = xf;
 16589:       this.epp = xe;
 16590:       this.dvl = xd;
 16591:       this.cvl = 0L;
 16592:       return this;
 16593:     }  //efp.roundx(EFP,int)
 16594: 
 16595:     //------------------------------------------------------------------------
 16596:     //x = x.roundy ()
 16597:     //x = x.roundy (roundingMode)
 16598:     //x = x.roundy (x)
 16599:     //x = x.roundy (x, roundingMode)
 16600:     //  triple丸め
 16601:     //
 16602:     //  この関数はepbRoundingModeとepbRoundingPrecを無視する
 16603:     //  triple(指数部15bit,仮数部80bit,非正規化数を含む)で表現できる値に丸める
 16604:     //  tripleで表現できないときは±Infに変換する
 16605:     //
 16606:     public final EFP roundy () {
 16607:       return this.roundy (this, EPB_MODE_RN);
 16608:     }  //efp.roundy()
 16609:     public final EFP roundy (int roundingMode) {
 16610:       return this.roundy (this, roundingMode);
 16611:     }  //efp.roundy(int)
 16612:     public final EFP roundy2 (int roundingMode) {
 16613:       return this.roundy2 (this, roundingMode);
 16614:     }  //efp.roundy(int)
 16615:     public final EFP roundy (EFP x) {
 16616:       return this.roundy (x, EPB_MODE_RN);
 16617:     }  //efp.roundy(EFP)
 16618:     public final EFP roundy (EFP x, int roundingMode) {
 16619:       int xf = x.flg;
 16620:       if (xf << 1 != 0) {  //±0,±Inf,NaN
 16621:         this.flg = xf;
 16622:         return this;
 16623:       }
 16624:       //±0,±Inf,NaN以外
 16625:       int xe = x.epp;  //正規化数は-16383<=xe<=16383、非正規化数は-16462<=xe<=-16384
 16626:       long xd = x.dvl;
 16627:       long xc = x.cvl;
 16628:       if (xe < -16463) {  //指数部が小さすぎる。非正規化数の最小値は2^-16462だが丸めで繰り上がる場合があるので一旦2^-16463まで受け入れる
 16629:         epbFpsr |= EPB_FPSR_UF | EPB_FPSR_X2;  //アンダーフロー、不正確な結果
 16630:         epbExceptionOperandExponent = xf | 0x3fff + 0x6000 + xe << 16;
 16631:         epbExceptionOperandMantissa = xd;
 16632:         return this.sete (UNFL_RESULTS[EPB_PREC_TPL << 3 | roundingMode << 1 | xf >>> 31]);  //±0
 16633:       }
 16634:       if (16383 < xe) {  //指数部が大きすぎる
 16635:         if (true) {
 16636:           epbFpsr |= EPB_FPSR_OF;  //オーバーフロー
 16637:           if (xc << 16 != 0L) {  //端数が0ではない
 16638:             epbFpsr |= EPB_FPSR_X2;  //不正確な結果
 16639:           }
 16640:         } else {
 16641:           epbFpsr |= EPB_FPSR_OF | EPB_FPSR_X2;  //オーバーフロー、不正確な結果
 16642:         }
 16643:         epbExceptionOperandExponent = xf | 0x3fff - 0x6000 + xe << 16;
 16644:         epbExceptionOperandMantissa = xd;
 16645:         return this.sete (OVFL_RESULTS[EPB_PREC_TPL << 3 | roundingMode << 1 | xf >>> 31]);  //±Inf
 16646:       }
 16647:       long xb = 0L;
 16648:       long xa = 0L;
 16649:       int o = xe <= -16384 ? 48 + -16383 - xe : 48;  //右にずらすbit数。正規化数は48、非正規化数は48+1<=o<=48+80
 16650:       if (o < 64) {
 16651:         xb = xc << -o;
 16652:         xc = xd << -o | xc >>> o;
 16653:         xd >>>= o;
 16654:       } else if (o == 64) {
 16655:         xb = xc;
 16656:         xc = xd;
 16657:         xd = 0L;
 16658:       } else if (o < 128) {
 16659:         xa = xc << -o;
 16660:         xb = xd << -o | xc >>> o;
 16661:         xc = xd >>> o;
 16662:         xd = 0L;
 16663:       } else {
 16664:         xa = xc;
 16665:         xb = xd;
 16666:         xc = 0L;
 16667:         xd = 0L;
 16668:       }
 16669:       if ((xb | xa) != 0L) {  //端数が0ではない
 16670:         epbFpsr |= EPB_FPSR_X2;  //不正確な結果
 16671:         epbExceptionOperandExponent = x.flg & M | 0x3fff + 0x6000 + x.epp << 16;
 16672:         epbExceptionOperandMantissa = x.dvl;
 16673:         if (roundingMode == EPB_MODE_RN && xb < 0L && (xc << 63 | xb << 1 | xa) != 0L ||  //RNでguard bitが1かつLSBまたはguard bit以外の端数が0ではないまたは
 16674:             roundingMode == EPB_MODE_RM && xf < 0 ||  //端数が0ではなくてRMで-または
 16675:             roundingMode == EPB_MODE_RP && 0 <= xf) {  //端数が0ではなくてRPで+のとき
 16676:           xc++;  //繰り上げる
 16677:           if (xc == 0L) {  //繰り上がって溢れたとき
 16678:             xd++;  //繰り上げる
 16679:             if (xd >>> 16 != 0L) {  //繰り上がって溢れたとき
 16680:               //xd = 1L << 15;
 16681:               xe++;  //指数部をインクリメントする。ここでxe=16384になる場合がある
 16682:               if (16383 < xe) {  //指数部が大きすぎる
 16683:                 epbFpsr |= EPB_FPSR_OF;  //オーバーフロー
 16684:                 return this.sete (OVFL_RESULTS[EPB_PREC_TPL << 3 | roundingMode << 1 | xf >>> 31]);  //±Inf
 16685:               }  //if 指数部が大きすぎる
 16686:             } else if (48 < o) {  //非正規化数のとき
 16687:               if (xd << o - 1 < 0L) {  //1bit増えたとき
 16688:                 xe++;  //指数部をインクリメントする
 16689: /* roundy
 16690:                 if (xe == -16383) {  //非正規化数が繰り上がって正規化数になったとき
 16691:                   //xd = 1L << 15;
 16692:                   epbFpsr |= EPB_FPSR_UF | EPB_FPSR_X2;  //アンダーフロー、不正確な結果
 16693:                   epbExceptionOperandExponent = xf | 0x3fff + 0x6000 + xe << 16;
 16694:                   epbExceptionOperandMantissa = xd;
 16695:                 }
 16696: */
 16697:               }
 16698:             }
 16699:           }
 16700:         }
 16701:         //RZ toward zeroのときは端数を切り捨てるだけなので何もしなくてよい
 16702:         if (xe <= -16384) {  //非正規化数
 16703:           epbFpsr |= EPB_FPSR_UF;  //アンダーフロー
 16704:           if ((xd | xc) == 0L) {  //非正規化数でxe==-16463だったとき、先頭の1がxbにあって丸めで繰り上がらなかった
 16705:             return this.sete (UNFL_RESULTS[EPB_PREC_TPL << 3 | roundingMode << 1 | xf >>> 31]);  //±0
 16706:           }
 16707:         }  //if 非正規化数
 16708:       } else {  //端数が0
 16709:         if (xe <= -16384) {  //非正規化数
 16710:           epbFpsr |= EPB_FPSR_UF;  //アンダーフロー
 16711:           epbExceptionOperandExponent = x.flg & M | 0x3fff + 0x6000 + x.epp << 16;
 16712:           epbExceptionOperandMantissa = x.dvl;
 16713:           if ((xd | xc) == 0L) {  //非正規化数でxe==-16463だったとき、先頭の1がxbにあって丸めで繰り上がらなかった
 16714:             return this.sete (UNFL_RESULTS[EPB_PREC_TPL << 3 | roundingMode << 1 | xf >>> 31]);  //±0
 16715:           }
 16716:         }  //if 非正規化数
 16717:       }  //if 端数が0ではない/端数が0
 16718:       if (xd != 0L) {
 16719:         o = Long.numberOfLeadingZeros (xd);
 16720:         xd = xd << o | xc >>> -o;
 16721:         xc <<= o;  //xbとxaはゴミが残っているので加えないこと
 16722:       } else {
 16723:         xd = xc << Long.numberOfLeadingZeros (xc);  //xbとxaはゴミが残っているので加えないこと
 16724:         xc = 0L;
 16725:       }
 16726:       //結果
 16727:       this.flg = xf;
 16728:       this.epp = xe;
 16729:       this.dvl = xd;
 16730:       this.cvl = xc;
 16731:       return this;
 16732:     }  //efp.roundy(EFP,int)
 16733:     public final EFP roundy2 (EFP x, int roundingMode) {
 16734:       int xf = x.flg;
 16735:       if (xf << 1 != 0) {  //±0,±Inf,NaN
 16736:         this.flg = xf;
 16737:         return this;
 16738:       }
 16739:       //±0,±Inf,NaN以外
 16740:       int xe = x.epp;  //正規化数は-16383<=xe<=16383、非正規化数は-16462<=xe<=-16384
 16741:       long xd = x.dvl;
 16742:       long xc = x.cvl;
 16743:       if (xe < -16463) {  //指数部が小さすぎる。非正規化数の最小値は2^-16462だが丸めで繰り上がる場合があるので一旦2^-16463まで受け入れる
 16744:         epbFpsr |= EPB_FPSR_UF | EPB_FPSR_X2;  //アンダーフロー、不正確な結果
 16745:         epbExceptionOperandExponent = xf | 0x3fff + 0x6000 + xe << 16;
 16746:         epbExceptionOperandMantissa = xd;
 16747:         return this.sete (UNFL_RESULTS[EPB_PREC_TPL << 3 | roundingMode << 1 | xf >>> 31]);  //±0
 16748:       }
 16749:       if (16383 < xe) {  //指数部が大きすぎる
 16750:         if (true) {
 16751:           epbFpsr |= EPB_FPSR_OF;  //オーバーフロー
 16752:           if (xc << 16 != 0L) {  //端数が0ではない
 16753:             epbFpsr |= EPB_FPSR_X2;  //不正確な結果
 16754:           }
 16755:         } else {
 16756:           epbFpsr |= EPB_FPSR_OF | EPB_FPSR_X2;  //オーバーフロー、不正確な結果
 16757:         }
 16758:         epbExceptionOperandExponent = xf | 0x3fff - 0x6000 + xe << 16;
 16759:         epbExceptionOperandMantissa = xd;
 16760:         return this.sete (OVFL_RESULTS[EPB_PREC_TPL << 3 | roundingMode << 1 | xf >>> 31]);  //±Inf
 16761:       }
 16762:       long xb = 0L;
 16763:       long xa = 0L;
 16764:       int o = xe <= -16384 ? 48 + -16383 - xe : 48;  //右にずらすbit数。正規化数は48、非正規化数は48+1<=o<=48+80
 16765:       if (o < 64) {
 16766:         xb = xc << -o;
 16767:         xc = xd << -o | xc >>> o;
 16768:         xd >>>= o;
 16769:       } else if (o == 64) {
 16770:         xb = xc;
 16771:         xc = xd;
 16772:         xd = 0L;
 16773:       } else if (o < 128) {
 16774:         xa = xc << -o;
 16775:         xb = xd << -o | xc >>> o;
 16776:         xc = xd >>> o;
 16777:         xd = 0L;
 16778:       } else {
 16779:         xa = xc;
 16780:         xb = xd;
 16781:         xc = 0L;
 16782:         xd = 0L;
 16783:       }
 16784:       if ((xb | xa) != 0L) {  //端数が0ではない
 16785:         epbFpsr |= EPB_FPSR_X2;  //不正確な結果
 16786:         epbExceptionOperandExponent = x.flg & M | 0x3fff + 0x6000 + x.epp << 16;
 16787:         epbExceptionOperandMantissa = x.dvl;
 16788:         if (roundingMode == EPB_MODE_RN && xb < 0L && (xc << 63 | xb << 1 | xa) != 0L ||  //RNでguard bitが1かつLSBまたはguard bit以外の端数が0ではないまたは
 16789:             roundingMode == EPB_MODE_RM && xf < 0 ||  //端数が0ではなくてRMで-または
 16790:             roundingMode == EPB_MODE_RP && 0 <= xf) {  //端数が0ではなくてRPで+のとき
 16791:           xc++;  //繰り上げる
 16792:           if (xc == 0L) {  //繰り上がって溢れたとき
 16793:             xd++;  //繰り上げる
 16794:             if (xd >>> 16 != 0L) {  //繰り上がって溢れたとき
 16795:               //xd = 1L << 15;
 16796:               xe++;  //指数部をインクリメントする。ここでxe=16384になる場合がある
 16797:               if (16383 < xe) {  //指数部が大きすぎる
 16798:                 epbFpsr |= EPB_FPSR_OF;  //オーバーフロー
 16799:                 return this.sete (OVFL_RESULTS[EPB_PREC_TPL << 3 | roundingMode << 1 | xf >>> 31]);  //±Inf
 16800:               }  //if 指数部が大きすぎる
 16801:             } else if (48 < o) {  //非正規化数のとき
 16802:               if (xd << o - 1 < 0L) {  //1bit増えたとき
 16803:                 xe++;  //指数部をインクリメントする
 16804: /* roundy2 */
 16805:                 if (xe == -16383) {  //非正規化数が繰り上がって正規化数になったとき
 16806:                   //xd = 1L << 15;
 16807:                   epbFpsr |= EPB_FPSR_UF | EPB_FPSR_X2;  //アンダーフロー、不正確な結果
 16808:                   epbExceptionOperandExponent = xf | 0x3fff + 0x6000 + xe << 16;
 16809:                   epbExceptionOperandMantissa = xd;
 16810:                 }
 16811: /**/
 16812:               }
 16813:             }
 16814:           }
 16815:         }
 16816:         //RZ toward zeroのときは端数を切り捨てるだけなので何もしなくてよい
 16817:         if (xe <= -16384) {  //非正規化数
 16818:           epbFpsr |= EPB_FPSR_UF;  //アンダーフロー
 16819:           if ((xd | xc) == 0L) {  //非正規化数でxe==-16463だったとき、先頭の1がxbにあって丸めで繰り上がらなかった
 16820:             return this.sete (UNFL_RESULTS[EPB_PREC_TPL << 3 | roundingMode << 1 | xf >>> 31]);  //±0
 16821:           }
 16822:         }  //if 非正規化数
 16823:       } else {  //端数が0
 16824:         if (xe <= -16384) {  //非正規化数
 16825:           epbFpsr |= EPB_FPSR_UF;  //アンダーフロー
 16826:           epbExceptionOperandExponent = x.flg & M | 0x3fff + 0x6000 + x.epp << 16;
 16827:           epbExceptionOperandMantissa = x.dvl;
 16828:           if ((xd | xc) == 0L) {  //非正規化数でxe==-16463だったとき、先頭の1がxbにあって丸めで繰り上がらなかった
 16829:             return this.sete (UNFL_RESULTS[EPB_PREC_TPL << 3 | roundingMode << 1 | xf >>> 31]);  //±0
 16830:           }
 16831:         }  //if 非正規化数
 16832:       }  //if 端数が0ではない/端数が0
 16833:       if (xd != 0L) {
 16834:         o = Long.numberOfLeadingZeros (xd);
 16835:         xd = xd << o | xc >>> -o;
 16836:         xc <<= o;  //xbとxaはゴミが残っているので加えないこと
 16837:       } else {
 16838:         xd = xc << Long.numberOfLeadingZeros (xc);  //xbとxaはゴミが残っているので加えないこと
 16839:         xc = 0L;
 16840:       }
 16841:       //結果
 16842:       this.flg = xf;
 16843:       this.epp = xe;
 16844:       this.dvl = xd;
 16845:       this.cvl = xc;
 16846:       return this;
 16847:     }  //efp.roundy(EFP,int)
 16848: 
 16849:     //------------------------------------------------------------------------
 16850:     //x = x.scale (y)
 16851:     //  x*=2^trunc(y)
 16852:     //z = z.scale (x, y)
 16853:     //  z=x*2^trunc(y)
 16854:     //  2^trunc(y)倍
 16855:     //
 16856:     public final EFP scale (EFP y) {
 16857:       return this.scale (this, y);
 16858:     }  //efp.scale(EFP)
 16859:     public final EFP scale (EFP x, EFP y) {
 16860:       int xf = x.flg;
 16861:       int yf = y.flg;
 16862:       if ((xf | yf) << 1 != 0) {  //どちらかが±0,±Inf,NaN
 16863:         if ((xf | yf) << 3 < 0) {  //どちらかがNaN
 16864:           this.flg = N;
 16865:         } else if (yf << 1 < 0) {  //scale(±0,±0)=±0, scale(±Inf,±0)=±Inf, scale(±x,±0)=±x
 16866:           this.finish (x.flg, x.epp, x.dvl, x.cvl, 0L);
 16867:         } else if (yf << 2 < 0) {  //scale(±0,±Inf)=NaN,OE, scale(±Inf,±Inf)=NaN,OE, scale(±x,±Inf)=NaN,OE
 16868:           epbFpsr |= EPB_FPSR_OE;
 16869:           epbExceptionOperandExponent = yf & M | 0x7fff << 16;
 16870:           epbExceptionOperandMantissa = 0x0000000000000000L;
 16871:           this.flg = N;
 16872:         } else if (xf << 1 < 0) {  //scale(±0,±y)=±0
 16873:           this.flg = xf;
 16874:         } else if (xf << 2 < 0) {  //scale(±Inf,±y)=±Inf
 16875:           this.flg = xf;
 16876:         }
 16877:         return this;
 16878:       }
 16879:       //両方±0,±Inf,NaN以外
 16880:       //  スケールをround-to-zeroで整数にする
 16881:       //  geti()は飽和変換だが飽和させるとオペランドエラーがセットされてしまうので先に範囲を確認する
 16882:       int i = (16 <= y.epp ? yf < 0 ? -1 << 16 : 1 << 16 :   //スケールの絶対値が2^16以上
 16883:                y.geti ());
 16884:       if (i <= -1 << 14) {  //スケールが-2^14以下のとき常にアンダーフロー。MC68882に合わせる
 16885:         epbFpsr |= EPB_FPSR_UF | EPB_FPSR_X2;  //アンダーフロー、不正確な結果
 16886:         if (i <= -1 << 16) {  //スケールが-2^16以下
 16887:           epbExceptionOperandExponent = xf;
 16888:           epbExceptionOperandMantissa = x.dvl;
 16889:         } else {
 16890:           epbExceptionOperandExponent = xf | 0x3fff + 0x6000 + i << 16;
 16891:           epbExceptionOperandMantissa = x.dvl;
 16892:         }
 16893:         return this.sete (UNFL_RESULTS[epbRoundingPrec << 3 | epbRoundingMode << 1 | xf >>> 31]).finish ();  //±0
 16894:       }
 16895:       if (1 << 14 <= i) {  //スケールが2^14以上のとき常にオーバーフロー。MC68882に合わせる
 16896:         epbFpsr |= EPB_FPSR_OF;  //オーバーフロー
 16897:         if (1 << 16 <= i) {  //スケールが2^16以上
 16898:           epbExceptionOperandExponent = xf;
 16899:           epbExceptionOperandMantissa = x.dvl;
 16900:         } else {
 16901:           epbExceptionOperandExponent = xf | 0x3fff - 0x6000 + i << 16;
 16902:           epbExceptionOperandMantissa = x.dvl;
 16903:         }
 16904:         return this.sete (OVFL_RESULTS[epbRoundingPrec << 3 | epbRoundingMode << 1 | xf >>> 31]).finish ();  //±Inf
 16905:       }
 16906:       return this.finish2 (xf, x.epp + i, x.dvl, x.cvl, 0L);  //スケールを加える
 16907:     }  //efp.scale(EFP,EFP)
 16908: 
 16909:     //------------------------------------------------------------------------
 16910:     //x = x.sec ()
 16911:     //  x=sec(x)
 16912:     //y = y.sec (x)
 16913:     //  y=sec(x)
 16914:     //  正割 secant セカント
 16915:     //
 16916:     //  グラフ
 16917:     //    perl -e "use Math::Trig;use Graph;$g=new Graph();$g->grid();$g->func(sub{sec($_[0])});print$g"
 16918:     //    echo read("../misc/efp.gp");eval("sec(x)=1/cos(x)");graph(sec) | gp -q
 16919:     //    +---------+---------+------*--+---------+---------+--*------+---------+---------+
 16920:     //    |                          *            |            *                          |
 16921:     //    |                          *            |            *                          |
 16922:     //    |                          *            |            *                          |
 16923:     //    |                          **           |           **                          |
 16924:     //    +                           *           +           *                           +
 16925:     //    |                           *           |           *                           |
 16926:     //    |                           *           |           *                           |
 16927:     //    |                           **          |          **                           |
 16928:     //    |                            *          |          *                            |
 16929:     //    +                            **         +         **                            +
 16930:     //    |                             **        |        **                             |
 16931:     //    |                              **       |       **                              |
 16932:     //    |                               **      |      **                               |
 16933:     //    |                                ****   |   ****                                |
 16934:     //    +                                   *********                                   +
 16935:     //    |                                       |                                       |
 16936:     //    |                                       |                                       |
 16937:     //    |                                       |                                       |
 16938:     //    |                                       |                                       |
 16939:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
 16940:     //    |                                       |                                       |
 16941:     //    |                                       |                                       |
 16942:     //    |                                       |                                       |
 16943:     //    |                                       |                                       |
 16944:     //    +   **********                          +                          **********   +
 16945:     //    | ***        ****                       |                       ****        *** |
 16946:     //    ***             **                      |                      **             ***
 16947:     //    *                **                     |                     **                *
 16948:     //    |                 **                    |                    **                 |
 16949:     //    +                  *                    +                    *                  +
 16950:     //    |                  **                   |                   **                  |
 16951:     //    |                   *                   |                   *                   |
 16952:     //    |                   *                   |                   *                   |
 16953:     //    |                   **                  |                  **                   |
 16954:     //    +                    *                  +                  *                    +
 16955:     //    |                    *                  |                  *                    |
 16956:     //    |                    *                  |                  *                    |
 16957:     //    |                    **                 |                 **                    |
 16958:     //    |                     *                 |                 *                     |
 16959:     //    +---------+---------+-*-------+---------+---------+-------*-+---------+---------+
 16960:     //
 16961:     //  三角関数との関係
 16962:     //    sec(x)=1/cos(x)
 16963:     //
 16964:     public final EFP sec () {
 16965:       return this.sec (this);
 16966:     }  //efp.sec()
 16967:     public final EFP sec (EFP x) {
 16968:       return this.inner ().cos (x).outer ().rcp ();  //1/cos(x)
 16969:     }  //efp.sec(EFP)
 16970: 
 16971:     //------------------------------------------------------------------------
 16972:     //x = x.sech ()
 16973:     //  x=sech(x)
 16974:     //y = y.sech (x)
 16975:     //  y=sech(x)
 16976:     //  双曲線正割 hyperbolic secant ハイパボリックセカント
 16977:     //
 16978:     //  グラフ
 16979:     //    perl -e "use Math::Trig;use Graph;$g=new Graph();$g->grid();$g->func(sub{sech($_[0])});print$g"
 16980:     //    echo read("../misc/efp.gp");eval("sech(x)=1/cosh(x)");graph(sech) | gp -q
 16981:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
 16982:     //    |                                       |                                       |
 16983:     //    |                                       |                                       |
 16984:     //    |                                       |                                       |
 16985:     //    |                                       |                                       |
 16986:     //    +                                       +                                       +
 16987:     //    |                                       |                                       |
 16988:     //    |                                       |                                       |
 16989:     //    |                                       |                                       |
 16990:     //    |                                       |                                       |
 16991:     //    +                                       +                                       +
 16992:     //    |                                       |                                       |
 16993:     //    |                                       |                                       |
 16994:     //    |                                       |                                       |
 16995:     //    |                                       |                                       |
 16996:     //    +                                  ***********                                  +
 16997:     //    |                              *****    |    *****                              |
 16998:     //    |                          *****        |        *****                          |
 16999:     //    |                    *******            |            *******                    |
 17000:     //    |         ************                  |                  ************         |
 17001:     //    ***********---------+---------+---------+---------+---------+---------***********
 17002:     //    |                                       |                                       |
 17003:     //    |                                       |                                       |
 17004:     //    |                                       |                                       |
 17005:     //    |                                       |                                       |
 17006:     //    +                                       +                                       +
 17007:     //    |                                       |                                       |
 17008:     //    |                                       |                                       |
 17009:     //    |                                       |                                       |
 17010:     //    |                                       |                                       |
 17011:     //    +                                       +                                       +
 17012:     //    |                                       |                                       |
 17013:     //    |                                       |                                       |
 17014:     //    |                                       |                                       |
 17015:     //    |                                       |                                       |
 17016:     //    +                                       +                                       +
 17017:     //    |                                       |                                       |
 17018:     //    |                                       |                                       |
 17019:     //    |                                       |                                       |
 17020:     //    |                                       |                                       |
 17021:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
 17022:     //
 17023:     //  双曲線関数との関係
 17024:     //    sech(x)=1/cosh(x)
 17025:     //
 17026:     //  指数関数との関係
 17027:     //    sech(x)=2/(e^x+e^-x)
 17028:     //           =2*e^x/((e^x)^2+1)
 17029:     //
 17030:     public final EFP sech () {
 17031:       return this.sech (this);
 17032:     }  //efp.sech()
 17033:     public final EFP sech (EFP x) {
 17034:       return this.inner ().cosh (x).outer ().rcp ();  //1/cosh(x)
 17035:     }  //efp.sech(EFP)
 17036: 
 17037:     //------------------------------------------------------------------------
 17038:     //y = y.set0 ()
 17039:     //  +0代入
 17040:     //
 17041:     public final EFP set0 () {
 17042:       this.flg = P | Z;
 17043:       //this.epp = 0;
 17044:       //this.dvl = 0L;
 17045:       //this.cvl = 0L;
 17046:       return this;
 17047:     }  //efp.set0()
 17048: 
 17049:     //------------------------------------------------------------------------
 17050:     //y = y.set1 ()
 17051:     //  +1代入
 17052:     //
 17053:     public final EFP set1 () {
 17054:       this.flg = P;
 17055:       this.epp = 0;
 17056:       this.dvl = MSB;
 17057:       this.cvl = 0L;
 17058:       return this;
 17059:     }  //efp.set1()
 17060: 
 17061:     //------------------------------------------------------------------------
 17062:     //y = y.setapery ()
 17063:     //  y=ζ(3)
 17064:     //  アペリーの定数 Apéry's constant
 17065:     //
 17066:     //  式
 17067:     //    ζ(3)=sum[n=1..∞]{1/n^3}
 17068:     //
 17069:     //  値
 17070:     //    echo read("../misc/efp.gp");printf("%.100g\n",zeta(3)) | gp -q
 17071:     //    1.202056903159594285399738161511449990764986292340498881792271555341838205786313090186455873609335258
 17072:     //
 17073:     //  参考
 17074:     //    https://ja.wikipedia.org/wiki/%E3%82%A2%E3%83%9A%E3%83%AA%E3%83%BC%E3%81%AE%E5%AE%9A%E6%95%B0
 17075:     //    https://ja.wikipedia.org/wiki/%E3%82%A2%E3%83%9A%E3%83%AA%E3%83%BC%E3%81%AE%E5%AE%9A%E7%90%86
 17076:     //    https://en.wikipedia.org/wiki/Ap%C3%A9ry%27s_constant
 17077:     //    http://society.math.ntu.edu.tw/~journal/tjm/V4N4/tjm0012_3.pdf
 17078:     //    http://www.numberworld.org/digits/Zeta(3)/
 17079:     //
 17080:     public final EFP setapery () {
 17081:       epbFpsr |= EPB_FPSR_X2;  //不正確な結果
 17082:       return this.sete (ROUNDED_APERY[epbRoundingMode]).finish ();
 17083:     }  //efp.setapery()
 17084: 
 17085:     //------------------------------------------------------------------------
 17086:     //y = y.setcatalan ()
 17087:     //  y=G
 17088:     //  カタランの定数 Catalan's_constant
 17089:     //
 17090:     //  式
 17091:     //    G=beta(2)
 17092:     //     =sum[n=0..∞]{(-1)^n/(2*n+1)^2}
 17093:     //     =1/1^2-1/3^2+1/5^2-1/7^2+1/9^2-1/11^2+1/13^2-1/15^2+1/17^2-1/19^2+...
 17094:     //
 17095:     //  値
 17096:     //    echo read("../misc/efp.gp");printf("%.100g\n",Catalan) | gp -q
 17097:     //    0.9159655941772190150546035149323841107741493742816721342664981196217630197762547694793565129261151062
 17098:     //
 17099:     //  参考
 17100:     //    https://en.wikipedia.org/wiki/Catalan%27s_constant
 17101:     //    http://www.numberworld.org/digits/Catalan/
 17102:     //
 17103:     public final EFP setcatalan () {
 17104:       epbFpsr |= EPB_FPSR_X2;  //不正確な結果
 17105:       return this.sete (ROUNDED_CATALAN[epbRoundingMode]).finish ();
 17106:     }  //efp.setcatalan()
 17107: 
 17108:     //------------------------------------------------------------------------
 17109:     //y = y.setd (d)
 17110:     //y = y.setd01 (b, a)
 17111:     //y = y.setd01 (l)
 17112:     //  double代入
 17113:     //  丸め処理を行わない
 17114:     //
 17115:     public final EFP setd (double d) {
 17116:       return this.setd01 (Double.doubleToLongBits (d));
 17117:     }  //efp.setd(double)
 17118:     public final EFP setd01 (byte[] b, int a) {
 17119:       return this.setd01 ((long) (b[a    ] << 24 | (b[a + 1] & 255) << 16 | (char) (b[a + 2] << 8 | b[a + 3] & 255)) << 32 |
 17120:                           (long) (b[a + 4] << 24 | (b[a + 5] & 255) << 16 | (char) (b[a + 6] << 8 | b[a + 7] & 255)) & 0xffffffffL);
 17121:     }  //efp.setd01(byte[],int)
 17122:     public final EFP setd01 (long l) {
 17123:       int zf = (int) (l >>> 32) & M;  //符号
 17124:       int ze = ((int) (l >>> 52) & 0x7ff) - 1023;  //指数部
 17125:       long zd = 0L;
 17126:       l &= -1L >>> 12;  //仮数部の小数部。doubleは正規化されているとき整数部が省略されているので後で先頭に1を付け足す必要がある
 17127:       if (ze == 1024) {  //±Inf,NaN
 17128:         if (l == 0L) {  //±Inf
 17129:           zf |= I;
 17130:         } else {  //NaN
 17131:           if (l << 12 >= 0L) {  //SNaN
 17132:             epbFpsr |= EPB_FPSR_SN;  //シグナリングNaN
 17133:             epbExceptionOperandExponent = 0x7fff << 16;
 17134:             epbExceptionOperandMantissa = 0xbfffffffffffffffL;
 17135:           }
 17136:           zf = N;
 17137:         }
 17138:       } else if (ze >= -1022) {  //正規化数
 17139:         zd = MSB | l << 11;  //整数部の1を付け足す
 17140:       } else if (l == 0L) {  //±0
 17141:         zf |= Z;
 17142:       } else {  //非正規化数
 17143:         int o = Long.numberOfLeadingZeros (l);
 17144:         ze -= o - 12;
 17145:         zd = l << o;  //非正規化数は整数部が存在しない
 17146:       }
 17147:       this.flg = zf;
 17148:       this.epp = ze;
 17149:       this.dvl = zd;
 17150:       this.cvl = 0L;
 17151:       //非正規化数でもアンダーフロー(UF)をセットしない
 17152:       //丸めない
 17153:       return this;
 17154:     }  //efp.setd01(long)
 17155: 
 17156:     //------------------------------------------------------------------------
 17157:     //y = y.sete (x)
 17158:     //  y=x
 17159:     //  EFP代入
 17160:     //  コピーするだけ
 17161:     //  丸め処理を行わない
 17162:     //
 17163:     public final EFP sete (EFP x) {
 17164:       this.flg = x.flg;
 17165:       this.epp = x.epp;
 17166:       this.dvl = x.dvl;
 17167:       this.cvl = x.cvl;
 17168:       return this;
 17169:     }  //efp.sete(EFP)
 17170: 
 17171:     //------------------------------------------------------------------------
 17172:     //y = y.seteuler ()
 17173:     //  y=γ
 17174:     //  オイラー・マスケローニ定数 Euler-Mascheroni constant
 17175:     //
 17176:     //  式
 17177:     //    γ=lim[n→∞]{sum[k=1..∞]{1/k}-log(n)}
 17178:     //
 17179:     //  値
 17180:     //    echo read("../misc/efp.gp");printf("%.100g\n",Euler) | gp -q
 17181:     //    0.5772156649015328606065120900824024310421593359399235988057672348848677267776646709369470632917467495
 17182:     //
 17183:     //  参考
 17184:     //    https://ja.wikipedia.org/wiki/%E3%82%AA%E3%82%A4%E3%83%A9%E3%83%BC%E3%81%AE%E5%AE%9A%E6%95%B0
 17185:     //    https://en.wikipedia.org/wiki/Euler%E2%80%93Mascheroni_constant
 17186:     //    http://www.numberworld.org/digits/EulerGamma/
 17187:     //
 17188:     public final EFP seteuler () {
 17189:       epbFpsr |= EPB_FPSR_X2;  //不正確な結果
 17190:       return this.sete (ROUNDED_EULER[epbRoundingMode]).finish ();
 17191:     }  //efp.seteuler()
 17192: 
 17193:     //------------------------------------------------------------------------
 17194:     //y = y.setf (f)
 17195:     //y = y.setf0 (b, a)
 17196:     //y = y.setf0 (i)
 17197:     //  float代入
 17198:     //  丸め処理を行わない
 17199:     //
 17200:     public final EFP setf (float f) {
 17201:       return this.setf0 (Float.floatToIntBits (f));
 17202:     }  //efp.setf(float)
 17203:     public final EFP setf0 (byte[] b, int a) {
 17204:       return this.setf0 (b[a] << 24 | (b[a + 1] & 255) << 16 | (char) (b[a + 2] << 8 | b[a + 3] & 255));
 17205:     }  //efp.setf0(byte[],int)
 17206:     public final EFP setf0 (int i) {
 17207:       int zf = i & M;  //符号
 17208:       int ze = (i >>> 23 & 0xff) - 127;  //指数部
 17209:       long zd = 0L;
 17210:       i &= -1 >>> 9;  //仮数部の小数部。floatは正規化されているとき整数部が省略されているので後で先頭に1を付け足す必要がある
 17211:       if (ze == 128) {  //±Inf,NaN
 17212:         if (i == 0) {  //±Inf
 17213:           zf |= I;
 17214:         } else {  //NaN
 17215:           if (i << 9 >= 0) {  //SNaN
 17216:             epbFpsr |= EPB_FPSR_SN;  //シグナリングNaN
 17217:             epbExceptionOperandExponent = 0x7fff << 16;
 17218:             epbExceptionOperandMantissa = 0xbfffffffffffffffL;
 17219:           }
 17220:           zf = N;
 17221:         }
 17222:       } else if (ze >= -126) {  //正規化数
 17223:         zd = (long) (1 << 23 | i) << 32 + 8;  //整数部の1を付け足す
 17224:       } else if (i == 0) {  //±0
 17225:         zf |= Z;
 17226:       } else {  //非正規化数
 17227:         int o = Integer.numberOfLeadingZeros (i);
 17228:         ze -= o - 9;
 17229:         zd = (long) i << 32 + o;  //非正規化数は整数部が存在しない
 17230:       }
 17231:       this.flg = zf;
 17232:       this.epp = ze;
 17233:       this.dvl = zd;
 17234:       this.cvl = 0L;
 17235:       //非正規化数でもアンダーフロー(UF)をセットしない
 17236:       //丸めない
 17237:       return this;
 17238:     }  //efp.setf0(float)
 17239: 
 17240:     //------------------------------------------------------------------------
 17241:     //y = y.seti (i)
 17242:     //  int代入
 17243:     //
 17244:     public final EFP seti (int i) {
 17245:       if (i == 0) {
 17246:         this.flg = P | Z;  //+0
 17247:         return this;
 17248:       }
 17249:       int zf = P;
 17250:       if (i < 0) {  //x<0
 17251:         zf = M;
 17252:         i = -i;
 17253:       }
 17254:       int ze = 31 - Integer.numberOfLeadingZeros (i);
 17255:       long zd = (long) i << 63 - ze;  //0x80000000のとき1拡張になるが余分な1は押し出されるのでマスクは不要
 17256:       return this.finish (zf, ze, zd, 0L, 0L);
 17257:     }  //efp.seti(int)
 17258: 
 17259:     //------------------------------------------------------------------------
 17260:     //y = y.setinf ()
 17261:     //  +Inf代入
 17262:     //
 17263:     public final EFP setinf () {
 17264:       this.flg = P | I;
 17265:       //this.epp = 0;
 17266:       //this.dvl = 0L;
 17267:       //this.cvl = 0L;
 17268:       return this;
 17269:     }  //efp.setinf()
 17270: 
 17271:     //------------------------------------------------------------------------
 17272:     //y = y.setl (l)
 17273:     //  long代入
 17274:     //
 17275:     public final EFP setl (long l) {
 17276:       if (l == 0L) {
 17277:         this.flg = P | Z;  //+0
 17278:         return this;
 17279:       }
 17280:       int zf = P;
 17281:       if (l < 0L) {  //x<0
 17282:         zf = M;
 17283:         l = -l;
 17284:       }
 17285:       int ze = 63 - Long.numberOfLeadingZeros (l);
 17286:       long zd = l << ~ze;
 17287:       return this.finish (zf, ze, zd, 0L, 0L);
 17288:     }  //efp.setl(long)
 17289: 
 17290:     //------------------------------------------------------------------------
 17291:     //y = y.setmax ()
 17292:     //  最大値代入
 17293:     //
 17294:     //  +Infの次に大きい表現可能な値
 17295:     //
 17296:     public final EFP setmax () {
 17297:       return this.finish (P, 32767, 0xffffffffffffffffL, 0xffffffffffffffffL << 128 - LEN, 0L);
 17298:     }  //efp.setmax()
 17299: 
 17300:     //------------------------------------------------------------------------
 17301:     //y = y.setmin ()
 17302:     //  最小値代入
 17303:     //
 17304:     //  -Infの次に小さい表現可能な値
 17305:     //
 17306:     public final EFP setmin () {
 17307:       return this.finish (M, -32767, MSB, 0L, 0L);
 17308:     }  //efp.setmin()
 17309: 
 17310:     //------------------------------------------------------------------------
 17311:     //y = y.setnan ()
 17312:     //  NaN代入
 17313:     //
 17314:     public final EFP setnan () {
 17315:       this.flg = N;
 17316:       //this.epp = 0;
 17317:       //this.dvl = 0L;
 17318:       //this.cvl = 0L;
 17319:       return this;
 17320:     }  //efp.setnan()
 17321: 
 17322:     //------------------------------------------------------------------------
 17323:     //y = y.setnapier ()
 17324:     //  y=e
 17325:     //  ネイピア数 Napier's constant
 17326:     //
 17327:     //  式
 17328:     //    e=sum[n=0..∞]{1/n!}
 17329:     //
 17330:     //  値
 17331:     //    echo read("../misc/efp.gp");printf("%.100g\n",exp(1)) | gp -q
 17332:     //    2.718281828459045235360287471352662497757247093699959574966967627724076630353547594571382178525166427
 17333:     //
 17334:     //  参考
 17335:     //    https://ja.wikipedia.org/wiki/%E3%83%8D%E3%82%A4%E3%83%94%E3%82%A2%E6%95%B0
 17336:     //    https://en.wikipedia.org/wiki/E_(mathematical_constant)
 17337:     //    http://www.numberworld.org/digits/E/
 17338:     //
 17339:     public final EFP setnapier () {
 17340:       epbFpsr |= EPB_FPSR_X2;  //不正確な結果
 17341:       return this.sete (ROUNDED_NAPIER[epbRoundingMode]).finish ();
 17342:     }  //efp.setnapier()
 17343: 
 17344:     //------------------------------------------------------------------------
 17345:     //y = y.setp012 (b, a)
 17346:     //y = y.setp012 (i, l)
 17347:     //  packed代入
 17348:     //
 17349:     public final EFP setp012 (byte[] b, int a) {
 17350:       return this.setp012 (b[a] << 24 | (b[a + 1] & 255) << 16 | (char) (b[a + 2] << 8 | b[a + 3] & 255),
 17351:                            (long) (b[a + 4] << 24 | (b[a + 5] & 255) << 16 | (char) (b[a + 6] << 8 | b[a + 7] & 255)) << 32 |
 17352:                            (long) (b[a + 8] << 24 | (b[a + 9] & 255) << 16 | (char) (b[a + 10] << 8 | b[a + 11] & 255)) & 0xffffffffL);
 17353:     }  //efp.setp012(byte[],int)
 17354:     public final EFP setp012 (int u, long v) {
 17355:       int zf = u & M;  //仮数部の符号
 17356:       int e = XEiJ.FMT_DCB4[u >>> 16 & 0xfff];  //指数部
 17357:       int m0 = XEiJ.FMT_DCB4[u & 0x000f];  //整数部
 17358:       int m1 = XEiJ.FMT_DCB4[(char) (v >>> 48)];  //小数部
 17359:       int m2 = XEiJ.FMT_DCB4[(char) (v >>> 32)];
 17360:       int m3 = XEiJ.FMT_DCB4[(char) (v >>> 16)];
 17361:       int m4 = XEiJ.FMT_DCB4[(char)  v        ];
 17362:       {
 17363:         int t = m0 | m1 | m2 | m3 | m4;
 17364:         if ((u & 0x30000000) != 0 ||  //±Inf,NaN
 17365:             (e | t) < 0) {  //BCDに0..9以外の文字がある
 17366:           if (v == 0L) {  //±Inf
 17367:             this.flg = zf | I;
 17368:           } else {  //NaN
 17369:             if (v << 1 >= 0L) {  //SNaN
 17370:               epbFpsr |= EPB_FPSR_SN;  //シグナリングNaN
 17371:               epbExceptionOperandExponent = 0x7fff << 16;
 17372:               epbExceptionOperandMantissa = 0xbfffffffffffffffL;
 17373:             }
 17374:             this.flg = N;
 17375:           }
 17376:           return this;
 17377:         }
 17378:         if (t == 0) {  //整数部と小数部がすべて0
 17379:           this.flg = zf | Z;  //±0
 17380:           return this;
 17381:         }
 17382:       }
 17383:       //±0,±Inf,NaN以外
 17384:       //FPSRを保存する
 17385:       int savedMode = epbRoundingMode;
 17386:       int savedFpsr = epbFpsr;
 17387:       epbFpsr = 0;
 17388:       //仮数部を変換する
 17389:       this.inner ();
 17390:       EFP t = new EFP ();
 17391:       this.setl ((long) (m0 * 100000000 + m1 * 10000 + m2)).imul (TENXP3).iadd (t.setl ((long) (m3 * 10000 + m4)));  //仮数部
 17392:       //符号を付ける
 17393:       //  符号を付けてから丸めないとRMとRPが逆になってしまう
 17394:       this.flg |= zf;
 17395:       //指数部を変換する
 17396:       if (u << 1 < 0) {  //指数部の符号
 17397:         e = -e;
 17398:       }
 17399:       e -= 16;  //小数点以下の桁数
 17400:       if (e < 0) {  //10^-eで割る
 17401:         e = -e;
 17402:         t.set1 ();
 17403:         for (int i = 0; e != 0; i++, e >>>= 1) {
 17404:           if ((e & 1) != 0) {
 17405:             t.imul (EFP_TEN_POWER_P[i]);
 17406:           }
 17407:         }
 17408:         epbRoundingPrec = EPB_PREC_EXD;
 17409:         epbRoundingMode = savedMode;
 17410:         this.div (t);
 17411:       } else {  //10^eを掛ける
 17412:         t.set1 ();
 17413:         for (int i = 0; e != 0; i++, e >>>= 1) {
 17414:           if ((e & 1) != 0) {
 17415:             t.imul (EFP_TEN_POWER_P[i]);
 17416:           }
 17417:         }
 17418:         epbRoundingPrec = EPB_PREC_EXD;
 17419:         epbRoundingMode = savedMode;
 17420:         this.mul (t);
 17421:       }
 17422:       this.outer ();
 17423:       //基数変換で生じたX2をX1に移す
 17424:       epbFpsr = savedFpsr | epbFpsr >>> 1 & EPB_FPSR_X1;
 17425:       //丸める
 17426:       //  丸めで生じたOF,UF,X2はそのまま返す
 17427:       return this.finish ();
 17428:     }  //efp.setp012(int,long)
 17429: 
 17430:     //------------------------------------------------------------------------
 17431:     //y = y.setpi ()
 17432:     //  y=pi
 17433:     //  円周率
 17434:     //
 17435:     //  式
 17436:     //    Fast multiple-precision evaluation of elementary functions (1976)
 17437:     //      http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.98.4721
 17438:     //    A=1
 17439:     //    B=2^(-1/2)
 17440:     //    T=1/4
 17441:     //    X=1
 17442:     //    while A-B>2^(-n) {
 17443:     //      Y=A
 17444:     //      A=(A+B)/2
 17445:     //      B=sqrt(B*Y)
 17446:     //      T=T-X*(A-Y)^2
 17447:     //      X=2*X
 17448:     //    }
 17449:     //    return A^2/T [or, better, (A+B)^2/(4*T)]
 17450:     //
 17451:     //    AGMアルゴリズム
 17452:     //      http://www.kurims.kyoto-u.ac.jp/~ooura/pi_fft-j.html
 17453:     //    ---- a formula based on the AGM (Arithmetic-Geometric Mean) ----
 17454:     //        c = sqrt(0.125);
 17455:     //        a = 1 + 3 * c;
 17456:     //        b = sqrt(a);
 17457:     //        e = b - 0.625;
 17458:     //        b = 2 * b;
 17459:     //        c = e - c;
 17460:     //        a = a + e;
 17461:     //        npow = 4;
 17462:     //        do {
 17463:     //            npow = 2 * npow;
 17464:     //            e = (a + b) / 2;
 17465:     //            b = sqrt(a * b);
 17466:     //            e = e - b;
 17467:     //            b = 2 * b;
 17468:     //            c = c - e;
 17469:     //            a = e + b;
 17470:     //        } while (e > SQRT_SQRT_EPSILON);
 17471:     //        e = e * e / 4;
 17472:     //        a = a + b;
 17473:     //        pi = (a * a - e - e / 2) / (a * c - e) / npow;
 17474:     //      ---- modification ----
 17475:     //        This is a modified version of Gauss-Legendre formula
 17476:     //        (by T.Ooura). It is faster than original version.
 17477:     //
 17478:     //  値
 17479:     //    echo read("../misc/efp.gp");printf("%.100g\n",Pi) | gp -q
 17480:     //    3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117068
 17481:     //
 17482:     //  参考
 17483:     //    https://ja.wikipedia.org/wiki/%E5%86%86%E5%91%A8%E7%8E%87
 17484:     //    https://en.wikipedia.org/wiki/Pi
 17485:     //    http://www.numberworld.org/digits/Pi/
 17486:     //
 17487:     public final EFP setpi () {
 17488:       epbFpsr |= EPB_FPSR_X2;  //不正確な結果
 17489:       return this.sete (ROUNDED_PI[epbRoundingMode]).finish ();
 17490:     }  //efp.setpi()
 17491: 
 17492:     //------------------------------------------------------------------------
 17493:     //y = y.setx012 (b, a)
 17494:     //y = y.setx012 (i, l)
 17495:     //  extended代入
 17496:     //  丸め処理を行わない
 17497:     //
 17498:     public final EFP setx012 (byte[] b, int a) {
 17499:       return this.setx012 (b[a] << 24 | (b[a + 1] & 255) << 16 | (char) (b[a + 2] << 8 | b[a + 3] & 255),
 17500:                            (long) (b[a + 4] << 24 | (b[a + 5] & 255) << 16 | (char) (b[a + 6] << 8 | b[a + 7] & 255)) << 32 |
 17501:                            (long) (b[a + 8] << 24 | (b[a + 9] & 255) << 16 | (char) (b[a + 10] << 8 | b[a + 11] & 255)) & 0xffffffffL);
 17502:     }  //efp.setx012(byte[],int)
 17503:     public final EFP setx012 (int i, long l) {
 17504:       int zf = i & M;  //符号
 17505:       int ze = (i >>> 16 & 32767) - 16383;  //指数部
 17506:       if (ze == 16384) {  //±Inf,NaN
 17507:         if (l == 0L) {  //±Inf
 17508:           this.flg = zf | I;
 17509:         } else {  //NaN
 17510:           if (l << 1 >= 0L) {  //SNaN
 17511:             epbFpsr |= EPB_FPSR_SN;  //シグナリングNaN
 17512:             epbExceptionOperandExponent = 0x7fff << 16;
 17513:             epbExceptionOperandMantissa = 0xbfffffffffffffffL;
 17514:           }
 17515:           this.flg = N;
 17516:         }
 17517:         return this;
 17518:       }
 17519:       if (l == 0L) {  //±0
 17520:         this.flg = zf | Z;
 17521:         return this;
 17522:       }
 17523:       if (l >= 0L) {  //未正規化数または非正規化数
 17524:         int o = Long.numberOfLeadingZeros (l);  //1..63
 17525:         ze -= o;
 17526:         l <<= o;
 17527:       }
 17528:       this.flg = zf;
 17529:       this.epp = ze;
 17530:       this.dvl = l;
 17531:       this.cvl = 0L;
 17532:       //非正規化数でもアンダーフロー(UF)をセットしない
 17533:       //丸めない
 17534:       return this;
 17535:     }  //efp.setx012(int,long)
 17536: 
 17537:     //------------------------------------------------------------------------
 17538:     //y = y.sety012 (b, a)
 17539:     //y = y.sety012 (i, l)
 17540:     //  triple代入
 17541:     //  丸め処理を行わない
 17542:     //
 17543:     public final EFP sety012 (byte[] b, int a) {
 17544:       return this.sety012 (b[a] << 24 | (b[a + 1] & 255) << 16 | (char) (b[a + 2] << 8 | b[a + 3] & 255),
 17545:                            (long) (b[a + 4] << 24 | (b[a + 5] & 255) << 16 | (char) (b[a + 6] << 8 | b[a + 7] & 255)) << 32 |
 17546:                            (long) (b[a + 8] << 24 | (b[a + 9] & 255) << 16 | (char) (b[a + 10] << 8 | b[a + 11] & 255)) & 0xffffffffL);
 17547:     }  //efp.sety012(byte[],int)
 17548:     public final EFP sety012 (int i, long l) {
 17549:       int zf = i & M;  //符号
 17550:       int ze = (i >>> 16 & 32767) - 16383;  //指数部
 17551:       if (ze == 16384) {  //±Inf,NaN
 17552:         if (l == 0L) {  //±Inf
 17553:           this.flg = zf | I;
 17554:         } else {  //NaN
 17555:           if (l << 1 >= 0L) {  //SNaN
 17556:             epbFpsr |= EPB_FPSR_SN;  //シグナリングNaN
 17557:             epbExceptionOperandExponent = 0x7fff << 16;
 17558:             epbExceptionOperandMantissa = 0xbfffffffffffffffL;
 17559:           }
 17560:           this.flg = N;
 17561:         }
 17562:         return this;
 17563:       }
 17564:       long m = (long) i << 48;  //仮数部の下位16bit
 17565:       if (l == 0L && m == 0L) {  //  //±0
 17566:         this.flg = zf | Z;
 17567:         return this;
 17568:       }
 17569:       if (l >= 0L) {  //未正規化数または非正規化数
 17570:         if (l != 0L) {
 17571:           int o = Long.numberOfLeadingZeros (l);  //1..63
 17572:           ze -= o;
 17573:           l = l << o | m >>> -o;
 17574:           m <<= o;
 17575:         } else {
 17576:           int o = 64 + Long.numberOfLeadingZeros (m);  //64..79
 17577:           ze -= o;
 17578:           l = m << o;
 17579:           m = 0L;
 17580:         }
 17581:       }
 17582:       this.flg = zf;
 17583:       this.epp = ze;
 17584:       this.dvl = l;
 17585:       this.cvl = m;
 17586:       //非正規化数でもアンダーフロー(UF)をセットしない
 17587:       //丸めない
 17588:       return this;
 17589:     }  //efp.sety012(int,long)
 17590: 
 17591:     //------------------------------------------------------------------------
 17592:     //x = x.sgn ()
 17593:     //  x=x<=>0
 17594:     //y = y.sgn (x)
 17595:     //  y=x<=>0
 17596:     //  符号
 17597:     //
 17598:     //  グラフ
 17599:     //    perl -e "use Graph;$g=new Graph();$g->grid();$g->func(sub{$_[0]<=>0});print$g"
 17600:     //    echo read("../misc/efp.gp");graph(sign) | gp -q
 17601:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
 17602:     //    |                                       |                                       |
 17603:     //    |                                       |                                       |
 17604:     //    |                                       |                                       |
 17605:     //    |                                       |                                       |
 17606:     //    +                                       +                                       +
 17607:     //    |                                       |                                       |
 17608:     //    |                                       |                                       |
 17609:     //    |                                       |                                       |
 17610:     //    |                                       |                                       |
 17611:     //    +                                       +                                       +
 17612:     //    |                                       |                                       |
 17613:     //    |                                       |                                       |
 17614:     //    |                                       |                                       |
 17615:     //    |                                       |                                       |
 17616:     //    +                                       *****************************************
 17617:     //    |                                       |                                       |
 17618:     //    |                                       |                                       |
 17619:     //    |                                       |                                       |
 17620:     //    |                                       |                                       |
 17621:     //    +---------+---------+---------+---------*---------+---------+---------+---------+
 17622:     //    |                                       |                                       |
 17623:     //    |                                       |                                       |
 17624:     //    |                                       |                                       |
 17625:     //    |                                       |                                       |
 17626:     //    *****************************************                                       +
 17627:     //    |                                       |                                       |
 17628:     //    |                                       |                                       |
 17629:     //    |                                       |                                       |
 17630:     //    |                                       |                                       |
 17631:     //    +                                       +                                       +
 17632:     //    |                                       |                                       |
 17633:     //    |                                       |                                       |
 17634:     //    |                                       |                                       |
 17635:     //    |                                       |                                       |
 17636:     //    +                                       +                                       +
 17637:     //    |                                       |                                       |
 17638:     //    |                                       |                                       |
 17639:     //    |                                       |                                       |
 17640:     //    |                                       |                                       |
 17641:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
 17642:     //
 17643:     //  isNaN(x)||x==0?x:x>0?1:-1
 17644:     //
 17645:     //  NaNの扱い
 17646:     //    NaNのときはNaNを返す
 17647:     //
 17648:     //  ±0の扱い
 17649:     //    ±0のときは±0を符号を付けたまま返す
 17650:     //
 17651:     public final EFP sgn () {
 17652:       return this.sgn (this);
 17653:     }  //efp.sgn()
 17654:     public final EFP sgn (EFP x) {
 17655:       int xf = x.flg;
 17656:       if ((xf & (Z | N)) != 0) {  //±0,NaN
 17657:         this.flg = xf;
 17658:       } else {  //±0,NaN以外
 17659:         this.flg = xf & M;  //sgn(±Inf)=±1,sgn(±x)=±1
 17660:         this.epp = 0;
 17661:         this.dvl = MSB;
 17662:         this.cvl = 0L;
 17663:       }
 17664:       return this;
 17665:     }  //efp.sgn(EFP)
 17666: 
 17667:     //------------------------------------------------------------------------
 17668:     //x = x.sgnsub (y)
 17669:     //  x=x<=>y
 17670:     //z = z.sgnsub (x, y)
 17671:     //  z=x<=>y
 17672:     //  比較
 17673:     //
 17674:     //  -Inf<-x<-0==+0<+x<+Inf
 17675:     //
 17676:     //  x.sub(y).sgn()と同じ結果を短い時間で返す
 17677:     //    仮数部を比較する必要があるのはフラグと指数部が一致している場合だけ
 17678:     //    仮数部を比較する場合も減算結果を正規化する必要がない
 17679:     //
 17680:     //  結果をbooleanで返す関数の代用にはならないことに注意
 17681:     //    z.sgnsub(x,y)がNaNを返すとき結果をbooleanで返す関数ではtrueにしなければならない場合とfalseにしなければならない場合がある
 17682:     //
 17683:     //  NaNの扱い
 17684:     //    どちらかがNaNのときはNaNを返す
 17685:     //    x.cmp(y)はどちらかがNaNのときに0を返す
 17686:     //
 17687:     //  ±Infの扱い
 17688:     //    +Inf<=>+Infまたは-Inf<=>-InfのときはNaNを返す
 17689:     //
 17690:     //  ±0の扱い
 17691:     //    両方が±0のときは符号に関係なく+0を返す
 17692:     //
 17693:     //  メモ
 17694:     //    EFPではインスタンスのフラグがコンディションコードを兼ねているので純粋にコンディションコードだけを返すメソッドは作れない
 17695:     //    フラグを書き換えると値が変わってしまう
 17696:     //
 17697:     public final EFP sgnsub (EFP y) {
 17698:       return this.sgnsub (this, y);
 17699:     }  //efp.sgnsub(EFP)
 17700:     public final EFP sgnsub (EFP x, EFP y) {
 17701:       int xf = x.flg;
 17702:       int yf = y.flg;
 17703:       if ((xf | yf) << 1 != 0) {  //どちらかが±0,±Inf,NaN
 17704:         if ((xf & yf) << 1 < 0 && xf == yf) {  //両方±0で符号が同じとき+0
 17705:           this.flg = P | Z;
 17706:         } else if ((xf & yf) << 2 < 0 && xf == yf ||  //両方±Infで符号が同じときNaN
 17707:                    (xf | yf) << 3 < 0) {  //どちらかがNaNのときNaN
 17708:           this.flg = N;
 17709:         } else if ((xf << 1 | yf << 2) < 0) {  //xが±0またはyが±Infのときsgn(-y)
 17710:           if (yf << 1 < 0) {
 17711:             this.flg = yf ^ M;
 17712:           } else {
 17713:             this.flg = yf & M ^ M;
 17714:             this.epp = 0;
 17715:             this.dvl = MSB;
 17716:             this.cvl = 0L;
 17717:           }
 17718:         } else {  //xが±Infまたはyが±0のときsgn(x)
 17719:           this.flg = xf & M;
 17720:           this.epp = 0;
 17721:           this.dvl = MSB;
 17722:           this.cvl = 0L;
 17723:         }
 17724:       } else if (xf != yf) {  //両方±0,±Inf,NaN以外で符号が違う
 17725:         this.flg = xf >= 0 ? P : M;
 17726:         this.epp = 0;
 17727:         this.dvl = MSB;
 17728:         this.cvl = 0L;
 17729:       } else {  //両方±0,±Inf,NaN以外で符号が同じ
 17730:         int s;
 17731:         long t;
 17732:         s = (xf >= 0 ? 1 : -1) * ((s = x.epp - y.epp) != 0 ? s >= 0 ? 1 : -1 :
 17733:                                   (t = x.dvl - y.dvl) != 0L ? t >= 0L ? 1 : -1 :
 17734:                                   (t = (x.cvl >>> 1) - (y.cvl >>> 1)) != 0L ? t >= 0L ? 1 : -1 :
 17735:                                   0);
 17736:         if (s != 0) {  //値が違う
 17737:           this.flg = s >= 0 ? P : M;
 17738:           this.epp = 0;
 17739:           this.dvl = MSB;
 17740:           this.cvl = 0L;
 17741:         } else {  //値が同じ
 17742:           this.flg = P | Z;  //+0
 17743:         }
 17744:       }
 17745:       return this;
 17746:     }  //efp.sgnsub(EFP,EFP)
 17747: 
 17748:     //------------------------------------------------------------------------
 17749:     //x = x.shl (n)
 17750:     //  x*=2^n
 17751:     //y = y.shl (x, n)
 17752:     //  y=x*2^n
 17753:     //  2^n倍(左シフト)
 17754:     //
 17755:     public final EFP shl (int n) {
 17756:       //nが大きすぎてInteger.MAX_VALUEを跨いでしまうと都合が悪いのでnに細工をする
 17757:       n = Math.max (-65536, Math.min (65536, n));
 17758:       return this.finish (this.flg, this.epp + n, this.dvl, this.cvl, 0L);
 17759:     }  //efp.shl(int)
 17760:     public final EFP shl (EFP x, int n) {
 17761:       //nが大きすぎてInteger.MAX_VALUEを跨いでしまうと都合が悪いのでnに細工をする
 17762:       n = Math.max (-65536, Math.min (65536, n));
 17763:       return this.finish (x.flg, x.epp + n, x.dvl, x.cvl, 0L);
 17764:     }  //efp.shl(EFP,int)
 17765: 
 17766:     //------------------------------------------------------------------------
 17767:     //x = x.shr (n)
 17768:     //  x/=2^n
 17769:     //y = y.shr (x, n)
 17770:     //  y=x/2^n
 17771:     //  1/2^n倍(右シフト)
 17772:     //
 17773:     public final EFP shr (int n) {
 17774:       //nが大きすぎてInteger.MAX_VALUEを跨いでしまうと都合が悪いのでnに細工をする
 17775:       n = Math.max (-65536, Math.min (65536, n));
 17776:       return this.finish (this.flg, this.epp - n, this.dvl, this.cvl, 0L);
 17777:     }  //efp.shr(int)
 17778:     public final EFP shr (EFP x, int n) {
 17779:       //nが大きすぎてInteger.MAX_VALUEを跨いでしまうと都合が悪いのでnに細工をする
 17780:       n = Math.max (-65536, Math.min (65536, n));
 17781:       return this.finish (x.flg, x.epp - n, x.dvl, x.cvl, 0L);
 17782:     }  //efp.shr(EFP,int)
 17783: 
 17784:     //------------------------------------------------------------------------
 17785:     //x = x.sin ()
 17786:     //  x=sin(x)
 17787:     //y = y.sin (x)
 17788:     //  y=sin(x)
 17789:     //  正弦 sine サイン
 17790:     //
 17791:     //  グラフ
 17792:     //    perl -e "use Math::Trig;use Graph;$g=new Graph();$g->grid();$g->func(sub{sin($_[0])});print$g"
 17793:     //    echo read("../misc/efp.gp");graph(sin) | gp -q
 17794:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
 17795:     //    |                                       |                                       |
 17796:     //    |                                       |                                       |
 17797:     //    |                                       |                                       |
 17798:     //    |                                       |                                       |
 17799:     //    +                                       +                                       +
 17800:     //    |                                       |                                       |
 17801:     //    |                                       |                                       |
 17802:     //    |                                       |                                       |
 17803:     //    |                                       |                                       |
 17804:     //    +                                       +                                       +
 17805:     //    |                                       |                                       |
 17806:     //    |                                       |                                       |
 17807:     //    |                                       |                                       |
 17808:     //    |                                       |                                       |
 17809:     //    +                                       +          **********                   +
 17810:     //    **                                      |       ****        *****               |
 17811:     //    |***                                    |    ****               ***             |
 17812:     //    |  ****                                 |  ***                    ***           |
 17813:     //    |     ***                               |***                        ***         |
 17814:     //    +-------***---------+---------+--------***--------+---------+---------***-------+
 17815:     //    |         ***                        ***|                               ***     |
 17816:     //    |           ***                    ***  |                                 ****  |
 17817:     //    |             ***               ****    |                                    ***|
 17818:     //    |               *****        ****       |                                      **
 17819:     //    +                   **********          +                                       +
 17820:     //    |                                       |                                       |
 17821:     //    |                                       |                                       |
 17822:     //    |                                       |                                       |
 17823:     //    |                                       |                                       |
 17824:     //    +                                       +                                       +
 17825:     //    |                                       |                                       |
 17826:     //    |                                       |                                       |
 17827:     //    |                                       |                                       |
 17828:     //    |                                       |                                       |
 17829:     //    +                                       +                                       +
 17830:     //    |                                       |                                       |
 17831:     //    |                                       |                                       |
 17832:     //    |                                       |                                       |
 17833:     //    |                                       |                                       |
 17834:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
 17835:     //
 17836:     //  定義域
 17837:     //    -inf<=x<=inf
 17838:     //
 17839:     //  値域
 17840:     //    -1<=sin(x)<=1
 17841:     //
 17842:     //  三角関数のとの関係
 17843:     //    sin(x)=2*tan(x/2)/(1+tan(x/2)^2)
 17844:     //
 17845:     //  変数変換
 17846:     //    収束を速くするために|x|<=pi/4にする
 17847:     //    sin(x)=cos(x-pi/2)
 17848:     //          =-sin(x-pi)
 17849:     //          =-cos(x-3*pi/2)
 17850:     //          =sin(x-2*pi)
 17851:     //                  cos(x-pi/2)
 17852:     //                             k=1
 17853:     //                       │    ←
 17854:     //            k=2↓\    │    /
 17855:     //                   \  │  /
 17856:     //                     \│/
 17857:     //    -sin(x-pi) ────・──── sin(x)
 17858:     //                     /│\
 17859:     //                   /  │  \
 17860:     //                 /    │    \↑k=0
 17861:     //                 →    │
 17862:     //                k=3
 17863:     //                -cos(x-3*pi/2)
 17864:     //
 17865:     //  テイラー展開
 17866:     //    sin(x)=x-x^3/3!+x^5/5!-x^7/7!...
 17867:     //    f(n,x)=sum(k=0,n,(-1)^k*x^(2*k+1)/(2*k+1)!)
 17868:     //    除算は不要
 17869:     //
 17870:     //  チェビシェフ展開
 17871:     //    テイラー展開よりも収束が速い
 17872:     //    除算は不要
 17873:     //
 17874:     //  CORDIC
 17875:     //    固定小数点演算用
 17876:     //    浮動小数点演算では結果の指数部が小さいとき有効桁数が不足する
 17877:     //    桁数の少ない浮動小数点演算では加減算と乗算のコストがあまり変わらないので乗算が減っても加減算が増え過ぎるとかえって遅くなる
 17878:     //    参考
 17879:     //      サルでも分かるCORDICアルゴリズム
 17880:     //      http://teamcoil.sp.u-tokai.ac.jp/calculator/100224/
 17881:     //
 17882:     //  sin(x)
 17883:     //    echo read("../misc/efp.gp");eval("f(n,x)=sum(k=0,n,(-1)^k/(2*k+1)!*x^(2*k+1))");for(n=0,26,printf("%4d",floor(closeness(sin,f(n,x),-Pi/4,Pi/4,10000)))) | gp -q
 17884:     //    echo read("../misc/efp.gp");eval("f(x)=sin(x)");a=-Pi/4;b=-a;forstep(n=1,27,2,printf("%4d",floor(closeness(f,chebyshev(f,a,b,n),a,b,10000)))) | gp -q
 17885:     //                次数   1   3   5   7   9  11  13  15  17  19  21  23  25  27  29  31  33  35  37  39  41  43  45  47  49  51  53
 17886:     //        テイラー展開   3   8  14  21  28  36  44  53  62  72  81  91 102 112 122 133 144 155 166 178 189 201 213 225 237 249 261
 17887:     //    チェビシェフ展開
 17888:     //        [-pi/4,pi/4]   3  10  17  26  35  45  55  65  76  88  99 111 123 135
 17889:     //
 17890:     public final EFP sin () {
 17891:       return this.sin (this);
 17892:     }  //efp.sin()
 17893:     public final EFP sin (EFP x) {
 17894:       int xf = x.flg;
 17895:       if (xf << 1 != 0) {  //±0,±Inf,NaN
 17896:         if (xf << 1 < 0) {  //±0
 17897:           this.flg = xf;  //sin(±0)=±0
 17898:         } else if (xf << 2 < 0) {  //±Inf
 17899:           epbFpsr |= EPB_FPSR_OE;
 17900:           epbExceptionOperandExponent = xf & M | 0x7fff << 16;
 17901:           epbExceptionOperandMantissa = 0x0000000000000000L;
 17902:           this.flg = N;  //sin(±Inf)=NaN
 17903:         } else {  //NaN
 17904:           this.flg = N;  //sin(NaN)=NaN
 17905:         }
 17906:         return this;
 17907:       }
 17908:       //±0,±Inf,NaN以外
 17909:       int savedFpsr = epbFpsr;
 17910:       this.inner ();
 17911:       if (this == x) {
 17912:         x = new EFP (x);
 17913:       }
 17914:       EFP u = new EFP ();
 17915:       EFP u2 = new EFP ();
 17916:       int k = u.ieeerempi2 (x);  //-pi/2<=u<=pi/2。kはx-uの象限
 17917:       if (false) {  //テイラー展開
 17918:         EFP s = new EFP ();
 17919:         EFP t = new EFP ();
 17920:         u2.isqu (u);  //u^2
 17921:         if ((k & 1) == 0) {  //sin
 17922:           //s.sete (u);  //(-1)^k*x^(2*k+1)/(2*k+1)!
 17923:           s.flg = u.flg;
 17924:           s.epp = u.epp;
 17925:           s.dvl = u.dvl;
 17926:           s.cvl = u.cvl;
 17927:           //t.set0 ();
 17928:           t.flg = P | Z;
 17929:           //this.sete (s);
 17930:           this.flg = s.flg;
 17931:           this.epp = s.epp;
 17932:           this.dvl = s.dvl;
 17933:           this.cvl = s.cvl;
 17934:           for (int twok1 = 3; this.ne (t); twok1 += 2) {  //2*k+1
 17935:             s.imul (u2).divi ((1 - twok1) * twok1);  //(-1)^k*x^(2*k+1)/(2*k+1)!
 17936:             //t.sete (this);
 17937:             t.flg = this.flg;
 17938:             t.epp = this.epp;
 17939:             t.dvl = this.dvl;
 17940:             t.cvl = this.cvl;
 17941:             this.iadd (s);
 17942:           }
 17943:         } else {  //cos
 17944:           //s.set1 ();  //(-1)^k*x^(2*k)/(2*k)!
 17945:           s.flg = P;
 17946:           s.epp = 0;
 17947:           s.dvl = MSB;
 17948:           s.cvl = 0L;
 17949:           //t.set0 ();
 17950:           t.flg = P | Z;
 17951:           //this.sete (s);
 17952:           this.flg = s.flg;
 17953:           this.epp = s.epp;
 17954:           this.dvl = s.dvl;
 17955:           this.cvl = s.cvl;
 17956:           for (int twok = 2; this.ne (t); twok += 2) {  //2*k
 17957:             s.imul (u2).divi ((1 - twok) * twok);  //(-1)^k*x^(2*k)/(2*k)!
 17958:             //t.sete (this);
 17959:             t.flg = this.flg;
 17960:             t.epp = this.epp;
 17961:             t.dvl = this.dvl;
 17962:             t.cvl = this.cvl;
 17963:             this.iadd (s);
 17964:           }
 17965:         }
 17966:       } else {  //チェビシェフ展開
 17967:         if ((k & 1) == 0) {  //sin
 17968:           u2.isqu (u);  //u^2
 17969:           this.imul (SIN_C21, u2)
 17970:             .iadd (SIN_C19).imul (u2)
 17971:               .iadd (SIN_C17).imul (u2)
 17972:                 .iadd (SIN_C15).imul (u2)
 17973:                   .iadd (SIN_C13).imul (u2)
 17974:                     .iadd (SIN_C11).imul (u2)
 17975:                       .iadd (SIN_C9).imul (u2)
 17976:                         .iadd (SIN_C7).imul (u2)
 17977:                           .iadd (SIN_C5).imul (u2)
 17978:                             .iadd (SIN_C3).imul (u2)
 17979:                               .iadd (SIN_C1).imul (u);
 17980:         } else {  //cos
 17981:           u2.isqu (u);  //u^2
 17982:           this.imul (COS_C20, u2)
 17983:             .iadd (COS_C18).imul (u2)
 17984:               .iadd (COS_C16).imul (u2)
 17985:                 .iadd (COS_C14).imul (u2)
 17986:                   .iadd (COS_C12).imul (u2)
 17987:                     .iadd (COS_C10).imul (u2)
 17988:                       .iadd (COS_C8).imul (u2)
 17989:                         .iadd (COS_C6).imul (u2)
 17990:                           .iadd (COS_C4).imul (u2)
 17991:                             .iadd (COS_C2).imul (u2)
 17992:                               .iadd (COS_C0);
 17993:         }
 17994:       }
 17995:       this.outer ().neg (k << 30 < 0);
 17996:       //  n*pi/2はn==0を除いて正確に表現できないので、
 17997:       //    RZまたはRPでsin(x)およびcos(x)が-1になることはあり得ない
 17998:       //    RZまたはRMでsin(x)およびcos(x)がcos(0)以外で+1になることはあり得ない
 17999:       if (this.flg << 1 == 0 && this.epp == 0) {  //結果が±1
 18000:         if (this.flg < 0) {  //結果が-1
 18001:           if (epbRoundingMode == EPB_MODE_RZ || epbRoundingMode == EPB_MODE_RP) {  //RZまたはRPで結果が-1
 18002:             this.sete (NEXTUP_MINUSONE[epbRoundingPrec]);
 18003:           }
 18004:         } else {  //結果が+1
 18005:           if (epbRoundingMode == EPB_MODE_RZ || epbRoundingMode == EPB_MODE_RM) {  //RZまたはRMで結果が+1
 18006:             this.sete (NEXTDOWN_PLUSONE[epbRoundingPrec]);
 18007:           }
 18008:         }
 18009:       }
 18010:       return this.originUpperLower (x).correctUnderflow (savedFpsr);
 18011:     }  //efp.sin(EFP)
 18012: 
 18013:     //------------------------------------------------------------------------
 18014:     //x = x.sinh ()
 18015:     //  x=sinh(x)
 18016:     //y = y.sinh (x)
 18017:     //  y=sinh(x)
 18018:     //  双曲線正弦 hyperbolic sine ハイパボリックサイン
 18019:     //
 18020:     //  グラフ
 18021:     //    perl -e "use Math::Trig;use Graph;$g=new Graph();$g->grid();$g->func(sub{sinh($_[0])});print$g"
 18022:     //    echo read("../misc/efp.gp");graph(sinh) | gp -q
 18023:     //    +---------+---------+---------+---------+---------+---------+*--------+---------+
 18024:     //    |                                       |                   **                  |
 18025:     //    |                                       |                   *                   |
 18026:     //    |                                       |                  **                   |
 18027:     //    |                                       |                 **                    |
 18028:     //    +                                       +                 *                     +
 18029:     //    |                                       |                **                     |
 18030:     //    |                                       |               **                      |
 18031:     //    |                                       |               *                       |
 18032:     //    |                                       |              **                       |
 18033:     //    +                                       +             **                        +
 18034:     //    |                                       |            **                         |
 18035:     //    |                                       |           **                          |
 18036:     //    |                                       |          **                           |
 18037:     //    |                                       |         **                            |
 18038:     //    +                                       +       ***                             +
 18039:     //    |                                       |      **                               |
 18040:     //    |                                       |    ***                                |
 18041:     //    |                                       |  ***                                  |
 18042:     //    |                                       |***                                    |
 18043:     //    +---------+---------+---------+--------***--------+---------+---------+---------+
 18044:     //    |                                    ***|                                       |
 18045:     //    |                                  ***  |                                       |
 18046:     //    |                                ***    |                                       |
 18047:     //    |                               **      |                                       |
 18048:     //    +                             ***       +                                       +
 18049:     //    |                            **         |                                       |
 18050:     //    |                           **          |                                       |
 18051:     //    |                          **           |                                       |
 18052:     //    |                         **            |                                       |
 18053:     //    +                        **             +                                       +
 18054:     //    |                       **              |                                       |
 18055:     //    |                       *               |                                       |
 18056:     //    |                      **               |                                       |
 18057:     //    |                     **                |                                       |
 18058:     //    +                     *                 +                                       +
 18059:     //    |                    **                 |                                       |
 18060:     //    |                   **                  |                                       |
 18061:     //    |                   *                   |                                       |
 18062:     //    |                  **                   |                                       |
 18063:     //    +---------+--------*+---------+---------+---------+---------+---------+---------+
 18064:     //
 18065:     //  定義域
 18066:     //    -inf<=x<=inf
 18067:     //
 18068:     //  値域
 18069:     //    -inf<=sinh(x)<=inf
 18070:     //
 18071:     //  指数関数との関係
 18072:     //    sinh(x)=(e^x-e^-x)/2
 18073:     //           =((e^x)^2-1)/(2*e^x)
 18074:     //
 18075:     //  テイラー展開
 18076:     //    sinh(x)=x+x^3/3!+x^5/5!+x^7/7!+...
 18077:     //    f(n,x)=sum(k=0,n,x^(2*k+1)/(2*k+1)!)
 18078:     //    echo read("../misc/efp.gp");eval("f(n,x)=sum(k=0,n,1/(2*k+1)!*x^(2*k+1))");a=-0.0625;b=0.0625;for(n=0,12,printf("%4d",floor(closeness(sinh,f(n,x),a,b,10000)))) | gp -q
 18079:     //       1   3   5   7   9  11  13  15  17  19  21  23  25
 18080:     //      10  22  36  50  65  80  96 112 128 145 162 179 197
 18081:     //
 18082:     //  チェビシェフ展開
 18083:     //    0の近くだけチェビシェフ展開を使う
 18084:     //    echo read("../misc/efp.gp");eval("f(x)=sinh(x)");a=-0.0625;b=0.0625;forstep(n=1,25,2,printf("%4d",floor(closeness(f,chebyshev(f,a,b,n),a,b,10000)))) | gp -q
 18085:     //       1   3   5   7   9  11  13  15  17  19  21  23  25
 18086:     //      10  24  39  55  71  88 106 124 142 161 179 199 218
 18087:     //    echo read("../misc/efp.gp");eval("f(x)=sinh(x)");a=-0.125;b=0.125;forstep(n=1,25,2,printf("%4d",floor(closeness(f,chebyshev(f,a,b,n),a,b,10000)))) | gp -q
 18088:     //       1   3   5   7   9  11  13  15  17  19  21  23  25
 18089:     //       8  20  33  47  61  76  92 108 124 141 157 175 192
 18090:     //
 18091:     public final EFP sinh () {
 18092:       return this.sinh (this);
 18093:     }  //efp.sinh()
 18094:     public final EFP sinh (EFP x) {
 18095:       int xf = x.flg;
 18096:       if (xf << 1 != 0) {  //±0,±Inf,NaN
 18097:         this.flg = xf;
 18098:         return this;
 18099:       }
 18100:       //±0,±Inf,NaN以外
 18101:       epbFpsr |= EPB_FPSR_X2;  //不正確な結果。オーバーフローまたはアンダーフローのときもセットされる
 18102:       epbExceptionOperandExponent = xf | 0x3fff + x.epp << 16;
 18103:       epbExceptionOperandMantissa = x.dvl;
 18104:       if (15 <= x.epp) {  //x<=-32768||32768<=x。sinh(-big)=-Inf,sinh(+big)=+Inf
 18105:         epbFpsr |= EPB_FPSR_OF;  //オーバーフロー
 18106:         return this.sete (OVFL_RESULTS[epbRoundingPrec << 3 | epbRoundingMode << 1 | xf >>> 31]).finish ();  //±Inf
 18107:       }
 18108:       if (x.epp < -3) {  //|x|<0.125
 18109:         int savedFpsr = epbFpsr;
 18110:         this.inner ();
 18111:         if (this == x) {
 18112:           x = new EFP (x);
 18113:         }
 18114:         EFP x2 = new EFP ().isqu (x);  //x^2
 18115:         this.imul (SINH_C13, x2)
 18116:           .iadd (SINH_C11).imul (x2)
 18117:             .iadd (SINH_C9).imul (x2)
 18118:               .iadd (SINH_C7).imul (x2)
 18119:                 .iadd (SINH_C5).imul (x2)
 18120:                   .iadd (SINH_C3).imul (x2)
 18121:                     .iadd (SINH_C1).outer ().mul (x);
 18122:         return this.originLowerUpper (x).correctUnderflow (savedFpsr);
 18123:       }
 18124:       //0.125<=|x|
 18125:       //  xが絶対値の大きい負数のときそのままe^xを計算するとアンダーフローして0になりさらに1/e^xがゼロ除算になる
 18126:       //  オーバーフローだけセットさせるためにxの符号を取ってからe^xを計算する
 18127:       //  丸める前に符号を付けないとRMとRPが逆になってしまうことに注意する
 18128:       this.inner ().abs (x).exp ();  //e^|x|
 18129:       this.sub (new EFP ().rcp (this)).div2 ().outer ().neg (xf < 0);  //(e^|x|-e^-|x|)/2
 18130:       if (this.flg << 2 < 0) {
 18131:         epbFpsr |= EPB_FPSR_OF;  //オーバーフロー
 18132:         return this.sete (OVFL_RESULTS[epbRoundingPrec << 3 | epbRoundingMode << 1 | this.flg >>> 31]).finish ();  //±Inf
 18133:       }
 18134:       return this;
 18135:     }  //efp.sinh(EFP)
 18136: 
 18137:     //------------------------------------------------------------------------
 18138:     //x = x.sqrt ()
 18139:     //  x=sqrt(x)
 18140:     //y = y.sqrt (x)
 18141:     //  y=sqrt(x)
 18142:     //  1/2乗(平方根)
 18143:     //
 18144:     //  グラフ
 18145:     //    perl -e "use Graph;$g=new Graph();$g->grid();$g->func(sub{sqrt($_[0])});print$g"
 18146:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
 18147:     //    |                                       |                                       |
 18148:     //    |                                       |                                       |
 18149:     //    |                                       |                                       |
 18150:     //    |                                       |                                       |
 18151:     //    +                                       +                                       +
 18152:     //    |                                       |                                       |
 18153:     //    |                                       |                                       |
 18154:     //    |                                       |                                       |
 18155:     //    |                                       |                                       |
 18156:     //    +                                       +                                   *****
 18157:     //    |                                       |                            ********   |
 18158:     //    |                                       |                      *******          |
 18159:     //    |                                       |                *******                |
 18160:     //    |                                       |           ******                      |
 18161:     //    +                                       +       *****                           +
 18162:     //    |                                       |    ****                               |
 18163:     //    |                                       |  ***                                  |
 18164:     //    |                                       |***                                    |
 18165:     //    |                                       **                                      |
 18166:     //    +---------+---------+---------+---------*---------+---------+---------+---------+
 18167:     //    |                                       |                                       |
 18168:     //    |                                       |                                       |
 18169:     //    |                                       |                                       |
 18170:     //    |                                       |                                       |
 18171:     //    +                                       +                                       +
 18172:     //    |                                       |                                       |
 18173:     //    |                                       |                                       |
 18174:     //    |                                       |                                       |
 18175:     //    |                                       |                                       |
 18176:     //    +                                       +                                       +
 18177:     //    |                                       |                                       |
 18178:     //    |                                       |                                       |
 18179:     //    |                                       |                                       |
 18180:     //    |                                       |                                       |
 18181:     //    +                                       +                                       +
 18182:     //    |                                       |                                       |
 18183:     //    |                                       |                                       |
 18184:     //    |                                       |                                       |
 18185:     //    |                                       |                                       |
 18186:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
 18187:     //    echo read("../misc/efp.gp");graph(sqrt) | gp -q
 18188:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
 18189:     //    |                                       |                                       |
 18190:     //    |                                       |                                       |
 18191:     //    |                                       |                                       |
 18192:     //    |                                       |                                       |
 18193:     //    +                                       +                                       +
 18194:     //    |                                       |                                       |
 18195:     //    |                                       |                                       |
 18196:     //    |                                       |                                       |
 18197:     //    |                                       |                                       |
 18198:     //    +                                       +                                   *****
 18199:     //    |                                       |                            ********   |
 18200:     //    |                                       |                      *******          |
 18201:     //    |                                       |                ******                 |
 18202:     //    |                                       |           ******                      |
 18203:     //    +                                       +       *****                           +
 18204:     //    |                                       |    ****                               |
 18205:     //    |                                       |  ***                                  |
 18206:     //    |                                       |**                                     |
 18207:     //    |                                       **                                      |
 18208:     //    +---------+---------+---------+---------*---------+---------+---------+---------+
 18209:     //    |                                       |                                       |
 18210:     //    |                                       |                                       |
 18211:     //    |                                       |                                       |
 18212:     //    |                                       |                                       |
 18213:     //    +                                       +                                       +
 18214:     //    |                                       |                                       |
 18215:     //    |                                       |                                       |
 18216:     //    |                                       |                                       |
 18217:     //    |                                       |                                       |
 18218:     //    +                                       +                                       +
 18219:     //    |                                       |                                       |
 18220:     //    |                                       |                                       |
 18221:     //    |                                       |                                       |
 18222:     //    |                                       |                                       |
 18223:     //    +                                       +                                       +
 18224:     //    |                                       |                                       |
 18225:     //    |                                       |                                       |
 18226:     //    |                                       |                                       |
 18227:     //    |                                       |                                       |
 18228:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
 18229:     //
 18230:     //  変数変換
 18231:     //    EFPの指数部はdoubleに収まらない
 18232:     //    x=x'*2^(2*k)  2^0<=x'<2^2
 18233:     //    sqrt(x)=sqrt(x'*2^(2*k))
 18234:     //           =sqrt(x')*2^k
 18235:     //
 18236:     //  ニュートン法1
 18237:     //    Math.sqrt()を使ってt=sqrt(x)をdoubleの精度で求めてからニュートン法の反復を1回行う
 18238:     //    f(t)=t^2-x
 18239:     //    f'(t)=2*t
 18240:     //    t'=t-f(t)/f'(t)
 18241:     //      =t-(t^2-x)/(2*t)
 18242:     //      =(2*t^2-(t^2-x))/(2*t)
 18243:     //      =(t^2+x)/(2*t)
 18244:     //      =(t+x/t)/2
 18245:     //    除算が必要
 18246:     //
 18247:     //  ニュートン法2
 18248:     //    Math.sqrt()を使ってt=1/sqrt(x)をdoubleの精度で求めてからニュートン法の反復を1回行ってxを掛ける
 18249:     //    f(t)=1/t^2-x
 18250:     //    f'(t)=-2/t^3
 18251:     //    t1=t-f(t)/f'(t)
 18252:     //      =t-(1/t^2-x)/(-2/t^3)
 18253:     //      =t+t/2-x*t^3/2
 18254:     //      =(3*t-x*t^3)/2
 18255:     //    sqrt(x)=x*t1
 18256:     //           =x*(3*t-x*t^3)/2
 18257:     //    除算は不要
 18258:     //
 18259:     //  整数の平方根
 18260:     //    floor(sqrt(x))
 18261:     //    範囲
 18262:     //      xがs>0桁のときfloor(sqrt(x))はs+1>>1桁
 18263:     //      1<<(s-1>>1) <= floor(sqrt(x)) <= (s&1)!=0?x>>(s>>1):(1<<(s>>1))-1
 18264:     //    ニュートン法
 18265:     //      初期値
 18266:     //        t=(s&1)!=0?x>>(s>>1):(1<<(s>>1))-1
 18267:     //      反復
 18268:     //        t=floor(x/t)+t>>1
 18269:     //      tが減らなくなるまで繰り返す。最後から2番目のtがfloor(sqrt(x))
 18270:     //
 18271:     //  Math.sqrt(-0.0)はNaNにならず-0.0が返るのでこれに合わせる
 18272:     //
 18273:     //  テイラー展開
 18274:     //    x=2^(2*n)の近くはsqrt(1+x)-1のテイラー展開を使う
 18275:     //      coeff(sub(a=0,for n:=0:7 sum sub(x=a,df(sqrt(1+x)-1,x,n))/factorial(n)*(x-a)^n),x);
 18276:     //          1    - 1   1     - 5    7     - 21    33
 18277:     //      {0,---,------,----,------,-----,-------,------}
 18278:     //          2    8     16   128    256   1024    2048
 18279:     //      for n:=0:7 collect (if n=0 then 0 else (-1)^(n-1)/2^(2*n-1)*factorial(2*n-2)/factorial(n-1)/factorial(n));
 18280:     //          1    - 1   1     - 5    7     - 21    33
 18281:     //      {0,---,------,----,------,-----,-------,------}
 18282:     //          2    8     16   128    256   1024    2048
 18283:     //
 18284:     public final EFP sqrt () {
 18285:       return this.sqrt (this);
 18286:     }  //efp.sqrt()
 18287:     public final EFP sqrt (EFP x) {
 18288:       int xf = x.flg;
 18289:       if (xf != 0) {  //-x,±0,±Inf,NaN
 18290:         if (xf == M || xf == (M | I)) {  //sqrt(-x)=NaN, sqrt(-Inf)=NaN
 18291:           epbFpsr |= EPB_FPSR_OE;
 18292:           if (xf << 2 < 0) {  //-Inf
 18293:             epbExceptionOperandExponent = xf & M | 0x7fff << 16;
 18294:             epbExceptionOperandMantissa = 0x0000000000000000L;
 18295:           } else {  //-x
 18296:             epbExceptionOperandExponent = xf & M | 0x3fff + x.epp << 16;
 18297:             epbExceptionOperandMantissa = x.dvl;
 18298:           }
 18299:           this.flg = N;
 18300:         } else {
 18301:           this.flg = xf;  //sqrt(±0)=±0, sqrt(+Inf)=+Inf, sqrt(NaN)=NaN
 18302:         }
 18303:         return this;
 18304:       }
 18305:       //+x
 18306:       if (false) {  //ニュートン法。[92] 535ns
 18307:         this.inner ();
 18308:         EFP t = new EFP (ONE).max (x);
 18309:         EFP u = new EFP (x);  //thisが破壊されるのでxをコピーしておく
 18310:         EFP w = new EFP ();
 18311:         do {
 18312:           //this.sete (t);
 18313:           this.flg = t.flg;
 18314:           this.epp = t.epp;
 18315:           this.dvl = t.dvl;
 18316:           this.cvl = t.cvl;
 18317:           t.iadd (w.sete (u).div (t)).idiv2 ();  //t=(t+x/t)/2
 18318:         } while (this.gt (t));
 18319:         return this.outer ().finish ();
 18320:       } else {  //Math.sqrtを使う。[92] 70.5ns
 18321:         if (this == x) {
 18322:           x = new EFP (x);
 18323:         }
 18324:         int xe = x.epp;
 18325:         if ((xe & 1) != 0 ? (x.dvl >>> -8) == 0xFF : (x.dvl >>> -9) == 0x100) {  //仮数部が1-1/256..1+1/256のとき
 18326:           //  1-1/256=2^-1*0xFF/2^7
 18327:           //  1+1/256=2^0*0x101/2^8
 18328:           this.inner ();
 18329:           x.epp = -(xe & 1);  //指数部を-1または0にする
 18330:           x.dec ();  //1を引く
 18331:           this.imul (x, SQRT1PM1_C11).
 18332:             iadd (SQRT1PM1_C10).imul (x).
 18333:               iadd (SQRT1PM1_C9).imul (x).
 18334:                 iadd (SQRT1PM1_C8).imul (x).
 18335:                   iadd (SQRT1PM1_C7).imul (x).
 18336:                     iadd (SQRT1PM1_C6).imul (x).
 18337:                       iadd (SQRT1PM1_C5).imul (x).
 18338:                         iadd (SQRT1PM1_C4).imul (x).
 18339:                           iadd (SQRT1PM1_C3).imul (x).
 18340:                             iadd (SQRT1PM1_C2).imul (x).
 18341:                               iadd (SQRT1PM1_C1).imul (x);  //テイラー展開
 18342:           this.outer ().inc ();  //1を加えながら丸める
 18343:           if (this.flg << 1 == 0) {
 18344:             //指数部を補正する
 18345:             //  分かりやすいように10進数で書く
 18346:             //         xの範囲      xの指数  sqrt(x)の範囲   sqrt(x)の指数  dec前とinc後の指数  補正値
 18347:             //    0.0099<=x<0.0100    -3     0.099<=x<0.1          -2               -1            -1
 18348:             //    0.0100<=x<0.0101    -2     0.100<=x<0.101        -1                0            -1
 18349:             //     0.099<=x<0.100     -2
 18350:             //     0.100<=x<0.101     -1
 18351:             //      0.99<=x<1         -1      0.99<=x<1            -1               -1             0
 18352:             //         1<=x<1.01       0         1<=x<1.01          0                0             0
 18353:             //       9.9<=x<10         0
 18354:             //        10<=x<10.1       1
 18355:             //        99<=x<100        1       9.9<=x<10            0               -1             1
 18356:             //       100<=x<101        2        10<=x<10.1          1                0             1
 18357:             //       990<=x<1000       2
 18358:             //      1000<=x<1010       3
 18359:             //      9900<=x<10000      3        99<=x<100           1               -1             2
 18360:             //     10000<=x<10100      4       100<=x<101           2                0             2
 18361:             this.epp += xe + 1 >> 1;  //指数部を復元する。負数の右シフトの挙動に注意。ここで指数部が範囲外になることがある
 18362:             this.finish ();
 18363:           }
 18364:           return this;
 18365:         }
 18366:         //  EFPをdoubleに変換する
 18367:         //    EFPの指数部はdoubleの指数部に収まらないので下位1bitだけ使う
 18368:         //    仮数部は上位53bitを使う
 18369:         //  Math.sqrtで53bitの平方根を求める
 18370:         //  doubleをEFPに変換する
 18371:         //    指数部に元の指数部の下位1bitを除いた残りの1/2を加える
 18372:         //  ニュートン法の反復を1回行う
 18373:         //  sqrtでは指数部が正でも負でも半分になるので丸めで制限されるまでオーバーフローもアンダーフローも発生しない
 18374:         //  丸める
 18375:         //  結果を2乗する
 18376:         //  結果の2乗を正確に表現できない場合と結果の2乗と元の値が一致しない場合はX2をセットする
 18377:         long s = Double.doubleToLongBits (Math.sqrt (Double.longBitsToDouble ((long) (1023 + (xe & 1)) << 52 | x.dvl << 1 >>> 12)));
 18378:         EFP t = new EFP (P, (int) (s >>> 52) - 1023 + (xe >> 1), MSB | s << 12 >>> 1, 0L);
 18379:         int savedFpsr = epbFpsr;
 18380:         this.inner ().div (x, t).iadd (t).outer ();
 18381:         this.epp--;  //(t+x/t)/2
 18382:         epbFpsr = 0;
 18383:         this.finish ();
 18384:         savedFpsr |= epbFpsr & (EPB_FPSR_OF | EPB_FPSR_UF);
 18385:         this.inner ();
 18386:         t.squ (this);
 18387:         this.outer ();
 18388:         if ((epbFpsr & EPB_FPSR_X2) != 0 || !t.eq (x)) {
 18389:           savedFpsr |= EPB_FPSR_X2;  //不正確な結果
 18390:           epbExceptionOperandExponent = xf | 0x3fff + x.epp << 16;
 18391:           epbExceptionOperandMantissa = x.dvl;
 18392:         }
 18393:         epbFpsr = savedFpsr;
 18394:         return this;
 18395:       }
 18396:     }  //efp.sqrt(EFP)
 18397: 
 18398:     //------------------------------------------------------------------------
 18399:     //x = x.squ ()
 18400:     //  x*=x
 18401:     //y = y.squ (x)
 18402:     //  y=x^2
 18403:     //  2乗
 18404:     //
 18405:     //  グラフ
 18406:     //    perl -e "use Graph;$g=new Graph();$g->grid();$g->func(sub{$_[0]**2});print$g"
 18407:     //    echo read("../misc/efp.gp");eval("squ(x)=x^2");graph(squ) | gp -q
 18408:     //    +---------+---------*---------+---------+---------+---------*---------+---------+
 18409:     //    |                   **                  |                  **                   |
 18410:     //    |                    *                  |                  *                    |
 18411:     //    |                    **                 |                 **                    |
 18412:     //    |                     *                 |                 *                     |
 18413:     //    +                     **                +                **                     +
 18414:     //    |                      **               |               **                      |
 18415:     //    |                       *               |               *                       |
 18416:     //    |                       **              |              **                       |
 18417:     //    |                        **             |             **                        |
 18418:     //    +                         *             +             *                         +
 18419:     //    |                         **            |            **                         |
 18420:     //    |                          **           |           **                          |
 18421:     //    |                           **          |          **                           |
 18422:     //    |                            **         |         **                            |
 18423:     //    +                             **        +        **                             +
 18424:     //    |                              **       |       **                              |
 18425:     //    |                               **      |      **                               |
 18426:     //    |                                ***    |    ***                                |
 18427:     //    |                                  ***  |  ***                                  |
 18428:     //    +---------+---------+---------+------*******------+---------+---------+---------+
 18429:     //    |                                       |                                       |
 18430:     //    |                                       |                                       |
 18431:     //    |                                       |                                       |
 18432:     //    |                                       |                                       |
 18433:     //    +                                       +                                       +
 18434:     //    |                                       |                                       |
 18435:     //    |                                       |                                       |
 18436:     //    |                                       |                                       |
 18437:     //    |                                       |                                       |
 18438:     //    +                                       +                                       +
 18439:     //    |                                       |                                       |
 18440:     //    |                                       |                                       |
 18441:     //    |                                       |                                       |
 18442:     //    |                                       |                                       |
 18443:     //    +                                       +                                       +
 18444:     //    |                                       |                                       |
 18445:     //    |                                       |                                       |
 18446:     //    |                                       |                                       |
 18447:     //    |                                       |                                       |
 18448:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
 18449:     //
 18450:     public final EFP squ () {
 18451:       int xf = this.flg;
 18452:       if (xf << 1 != 0) {  //±0,±Inf,NaN
 18453:         this.flg = xf << 3 < 0 ? N : xf & ~M;  //(±0)^2=+0, (±Inf)^2=+Inf, NaN^2=NaN
 18454:         return this;
 18455:       }
 18456:       //3分割する
 18457:       //  92bitの仮数部を32bit,30bit,30bitに分割する
 18458:       long zd = this.dvl;
 18459:       long zc = this.cvl;
 18460:       long zb = (zd << -2 | zc >>> 2) >>> -30;  //下位30bit
 18461:       zc = zd << 32 >>> -30;  //中位30bit
 18462:       zd >>>= 32;  //上位32bit
 18463:       //2乗する
 18464:       //  (zd*2^60+zc*2^30+zb)^2=zd^2*2^120+2*zd*zc*2^90+(2*zd*zb+zc^2)*2^60+2*zc*zb*2^30+zb^2
 18465:       long t = zb * zb;  //2^0
 18466:       long s = t & 0xffffffffL;  //sticky bit
 18467:       t = (t >>> 30) + (zc * zb << 1);  //2^30
 18468:       s |= t & 0xffffffffL;
 18469:       t = (t >>> 30) + (zd * zb << 1) + zc * zc;  //2^60
 18470:       s |= t & 0xffffffffL;
 18471:       t = (t >>> 30) + (zd * zc << 1);  //2^90
 18472:       zd = (t >>> 30) + zd * zd;  //2^120
 18473:       zc = t << -30 | s;
 18474:       int ze = this.epp << 1;
 18475:       if (zd < 0L) {
 18476:         ze++;
 18477:       } else {
 18478:         zd = zd << 1 | zc >>> -1;
 18479:         zc <<= 1;
 18480:       }
 18481:       return this.finish (P, ze, zd, zc, 0L);
 18482:     }  //efp.squ()
 18483:     public final EFP isqu () {
 18484:       int xf = this.flg;
 18485:       if (xf << 1 != 0) {  //±0,±Inf,NaN
 18486:         this.flg = xf << 3 < 0 ? N : xf & ~M;  //(±0)^2=+0, (±Inf)^2=+Inf, NaN^2=NaN
 18487:         return this;
 18488:       }
 18489:       //3分割する
 18490:       //  92bitの仮数部を32bit,30bit,30bitに分割する
 18491:       long zd = this.dvl;
 18492:       long zc = this.cvl;
 18493:       long zb = (zd << -2 | zc >>> 2) >>> -30;  //下位30bit
 18494:       zc = zd << 32 >>> -30;  //中位30bit
 18495:       zd >>>= 32;  //上位32bit
 18496:       //2乗する
 18497:       //  (zd*2^60+zc*2^30+zb)^2=zd^2*2^120+2*zd*zc*2^90+(2*zd*zb+zc^2)*2^60+2*zc*zb*2^30+zb^2
 18498:       long t = zb * zb;  //2^0
 18499:       long s = t & 0xffffffffL;  //sticky bit
 18500:       t = (t >>> 30) + (zc * zb << 1);  //2^30
 18501:       s |= t & 0xffffffffL;
 18502:       t = (t >>> 30) + (zd * zb << 1) + zc * zc;  //2^60
 18503:       s |= t & 0xffffffffL;
 18504:       t = (t >>> 30) + (zd * zc << 1);  //2^90
 18505:       zd = (t >>> 30) + zd * zd;  //2^120
 18506:       zc = t << -30 | s;
 18507:       int ze = this.epp << 1;
 18508:       if (zd < 0L) {
 18509:         ze++;
 18510:       } else {
 18511:         zd = zd << 1 | zc >>> -1;
 18512:         zc <<= 1;
 18513:       }
 18514:       return this.ifinish (P, ze, zd, zc, 0L);
 18515:     }  //efp.isqu()
 18516:     public final EFP squ (EFP x) {
 18517:       //return this.mul (x, x);  //11.8ns
 18518:       //8.4ns
 18519:       int xf = x.flg;
 18520:       if (xf << 1 != 0) {  //±0,±Inf,NaN
 18521:         this.flg = xf << 3 < 0 ? N : xf & ~M;  //(±0)^2=+0, (±Inf)^2=+Inf, NaN^2=NaN
 18522:         return this;
 18523:       }
 18524:       //3分割する
 18525:       //  92bitの仮数部を32bit,30bit,30bitに分割する
 18526:       long zd = x.dvl;
 18527:       long zc = x.cvl;
 18528:       long zb = (zd << -2 | zc >>> 2) >>> -30;  //下位30bit
 18529:       zc = zd << 32 >>> -30;  //中位30bit
 18530:       zd >>>= 32;  //上位32bit
 18531:       //2乗する
 18532:       //  (zd*2^60+zc*2^30+zb)^2=zd^2*2^120+2*zd*zc*2^90+(2*zd*zb+zc^2)*2^60+2*zc*zb*2^30+zb^2
 18533:       long t = zb * zb;  //2^0
 18534:       long s = t & 0xffffffffL;  //sticky bit
 18535:       t = (t >>> 30) + (zc * zb << 1);  //2^30
 18536:       s |= t & 0xffffffffL;
 18537:       t = (t >>> 30) + (zd * zb << 1) + zc * zc;  //2^60
 18538:       s |= t & 0xffffffffL;
 18539:       t = (t >>> 30) + (zd * zc << 1);  //2^90
 18540:       zd = (t >>> 30) + zd * zd;  //2^120
 18541:       zc = t << -30 | s;
 18542:       int ze = x.epp << 1;
 18543:       if (zd < 0L) {
 18544:         ze++;
 18545:       } else {
 18546:         zd = zd << 1 | zc >>> -1;
 18547:         zc <<= 1;
 18548:       }
 18549:       return this.finish (P, ze, zd, zc, 0L);
 18550:     }  //efp.squ(EFP)
 18551:     public final EFP isqu (EFP x) {
 18552:       //return this.mul (x, x);  //11.8ns
 18553:       //8.4ns
 18554:       int xf = x.flg;
 18555:       if (xf << 1 != 0) {  //±0,±Inf,NaN
 18556:         this.flg = xf << 3 < 0 ? N : xf & ~M;  //(±0)^2=+0, (±Inf)^2=+Inf, NaN^2=NaN
 18557:         return this;
 18558:       }
 18559:       //3分割する
 18560:       //  92bitの仮数部を32bit,30bit,30bitに分割する
 18561:       long zd = x.dvl;
 18562:       long zc = x.cvl;
 18563:       long zb = (zd << -2 | zc >>> 2) >>> -30;  //下位30bit
 18564:       zc = zd << 32 >>> -30;  //中位30bit
 18565:       zd >>>= 32;  //上位32bit
 18566:       //2乗する
 18567:       //  (zd*2^60+zc*2^30+zb)^2=zd^2*2^120+2*zd*zc*2^90+(2*zd*zb+zc^2)*2^60+2*zc*zb*2^30+zb^2
 18568:       long t = zb * zb;  //2^0
 18569:       long s = t & 0xffffffffL;  //sticky bit
 18570:       t = (t >>> 30) + (zc * zb << 1);  //2^30
 18571:       s |= t & 0xffffffffL;
 18572:       t = (t >>> 30) + (zd * zb << 1) + zc * zc;  //2^60
 18573:       s |= t & 0xffffffffL;
 18574:       t = (t >>> 30) + (zd * zc << 1);  //2^90
 18575:       zd = (t >>> 30) + zd * zd;  //2^120
 18576:       zc = t << -30 | s;
 18577:       int ze = x.epp << 1;
 18578:       if (zd < 0L) {
 18579:         ze++;
 18580:       } else {
 18581:         zd = zd << 1 | zc >>> -1;
 18582:         zc <<= 1;
 18583:       }
 18584:       return this.ifinish (P, ze, zd, zc, 0L);
 18585:     }  //efp.isqu(EFP)
 18586: 
 18587:     //------------------------------------------------------------------------
 18588:     //x = x.sub (y)
 18589:     //  x-=y
 18590:     //z = z.sub (x, y)
 18591:     //  z=x-y
 18592:     //  減算
 18593:     //
 18594:     //  (xn/xd)-(yn/yd)
 18595:     //    =((xn*yd)/(xd*yd))-((xd*yn)/(xd*yd))
 18596:     //    =(xn*yd-xd*yn)/(xd*yd)
 18597:     //
 18598:     public final EFP sub (EFP y) {
 18599:       int xf = this.flg;
 18600:       int xe = this.epp;
 18601:       long xd = this.dvl;
 18602:       long xc = this.cvl;
 18603:       long xb = 0L;
 18604:       int yf = y.flg;
 18605:       if ((xf | yf) << 1 != 0) {  //どちらかが±0,±Inf,NaN
 18606:         if ((xf | yf) << 3 < 0) {  //どちらかがNaNのときNaN
 18607:           this.flg = N;
 18608:           return this;
 18609:         }
 18610:         if ((xf & yf) << 2 < 0 && xf == yf) {  //両方±Infで符号が同じときNaN
 18611:           epbFpsr |= EPB_FPSR_OE;
 18612:           epbExceptionOperandExponent = yf & M | 0x7fff << 16;
 18613:           epbExceptionOperandMantissa = 0x0000000000000000L;
 18614:           this.flg = N;
 18615:           return this;
 18616:         }
 18617:         if ((xf & yf) << 1 < 0 && xf == yf) {  //両方±0で符号が同じとき
 18618:           this.flg = epbRoundingMode == EPB_MODE_RM ? M | Z : P | Z;  //RMのとき-0,それ以外は+0
 18619:           return this;
 18620:         }
 18621:         if (xf << 1 < 0 || yf << 2 < 0) {  //xが±0またはyが±Infのとき-y
 18622:           xf = yf ^ M;
 18623:           xe = y.epp;
 18624:           xd = y.dvl;
 18625:           xc = y.cvl;
 18626:         }
 18627:         //xが±Infまたはyが±0のときx
 18628:       } else {  //両方±0,±Inf,NaN以外
 18629:         //減算なのでyの符号を反転して加算する
 18630:         yf ^= M;
 18631:         long yd = y.dvl;
 18632:         long yc = y.cvl;
 18633:         int o = xe - y.epp;
 18634:         if (o < 0 || o == 0 && (xd < yd || xd == yd && xc >>> 1 < yc >>> 1)) {  //yの方が絶対値が大きい
 18635:           //xとyを入れ換える
 18636:           xf = yf;
 18637:           xe += o = -o;  //xe=y.epp
 18638:           xd = yd;
 18639:           xc = yc;
 18640:           yf = this.flg;  //後で符号を比較するときに使う
 18641:           yd = this.dvl;
 18642:           yc = this.cvl;
 18643:         }
 18644:         //xの方が絶対値が大きいか等しい
 18645:         //yを右にずらして小数点の位置を合わせる
 18646:         if (0 < o) {
 18647:           if (o <= 63) {
 18648:             xb = yc << -o;
 18649:             yc = yd << -o | yc >>> o;
 18650:             yd >>>= o;
 18651:           } else if (o == 64) {
 18652:             xb = yc;
 18653:             yc = yd;
 18654:             yd = 0L;
 18655:           } else if (o <= 127) {
 18656:             xb = yd << -o | yc;
 18657:             yc = yd >>> o;
 18658:             yd = 0L;
 18659:           } else {
 18660:             xb = yd | yc;  //絶対値減算を行うとき下位からのボローとして必要
 18661:             yc = 0L;
 18662:             yd = 0L;
 18663:           }
 18664:         }
 18665:         //絶対値加算または絶対値減算を行う
 18666:         if (xf == yf) {  //符号が同じなので絶対値加算を行う
 18667:           //yc[1]とyc[0]をsticky bitに押し出す
 18668:           xb |= yc << 62;
 18669:           //右にずらしてxd[63]を空ける
 18670:           xc = xd << 63 | xc >>> 1;
 18671:           xd >>>= 1;
 18672:           yc = yd << 63 | yc >>> 1;
 18673:           yd >>>= 1;
 18674:           //下位を右にずらしてxc[63]を空ける
 18675:           yc >>>= 1;
 18676:           xc >>>= 1;
 18677:           //足す
 18678:           xc += yc;
 18679:           xd += yd + (xc >>> 63);
 18680:           //下位を左にずらしてxc[63]を詰める
 18681:           xc <<= 1;
 18682:           //溢れの処理
 18683:           if (xd < 0L) {  //溢れたとき
 18684:             xe++;
 18685:           } else {  //溢れなかったとき
 18686:             xd = xd << 1 | xc >>> 63;  //左にずらしてxd[63]を詰める
 18687:             xc <<= 1;
 18688:           }
 18689:         } else {  //符号が異なるので絶対値減算を行う
 18690:           //yc[0]をsticky bitに押し出す
 18691:           xb |= yc << 63;
 18692:           //下位を右にずらしてxc[63]を空ける
 18693:           yc >>>= 1;
 18694:           xc >>>= 1;
 18695:           //引く
 18696:           //  xの方が絶対値が大きいか等しいので負になることはないが0になることがある
 18697:           if (xb != 0L) {
 18698:             xc--;
 18699:           }
 18700:           xc -= yc;
 18701:           xd -= yd + (xc >>> 63);
 18702:           //下位を左にずらしてxc[63]を詰める
 18703:           xc <<= 1;
 18704:           //正規化する
 18705:           if (0L <= xd) {
 18706:             if (xd != 0L) {
 18707:               xe -= o = Long.numberOfLeadingZeros (xd);
 18708:               xd = xd << o | xc >>> -o;
 18709:               xc <<= o;
 18710:             } else if (xc != 0L) {
 18711:               xe -= o = 64 + Long.numberOfLeadingZeros (xc);
 18712:               xd = xc << o;
 18713:               xc = 0L;
 18714:             } else {  //0になった
 18715:               xf = epbRoundingMode == EPB_MODE_RM ? M | Z : P | Z;  //RMのとき-0,それ以外は+0
 18716:             }
 18717:           }
 18718:         }  //if 符号が同じなので絶対値加算を行う/符号が異なるので絶対値減算を行う
 18719:       }  //if どちらかが±0,±Inf,NaN/両方±0,±Inf,NaN以外
 18720:       return this.finish (xf, xe, xd, xc, xb);
 18721:     }  //efp.sub(EFP)
 18722:     public final EFP sub (EFP x, EFP y) {
 18723:       int xf = x.flg;
 18724:       int xe = x.epp;
 18725:       long xd = x.dvl;
 18726:       long xc = x.cvl;
 18727:       long xb = 0L;
 18728:       int yf = y.flg;
 18729:       if ((xf | yf) << 1 != 0) {  //どちらかが±0,±Inf,NaN
 18730:         if ((xf | yf) << 3 < 0) {  //どちらかがNaNのときNaN
 18731:           this.flg = N;
 18732:           return this;
 18733:         }
 18734:         if ((xf & yf) << 2 < 0 && xf == yf) {  //両方±Infで符号が同じときNaN
 18735:           epbFpsr |= EPB_FPSR_OE;
 18736:           epbExceptionOperandExponent = yf & M | 0x7fff << 16;
 18737:           epbExceptionOperandMantissa = 0x0000000000000000L;
 18738:           this.flg = N;
 18739:           return this;
 18740:         }
 18741:         if ((xf & yf) << 1 < 0 && xf == yf) {  //両方±0で符号が同じとき
 18742:           this.flg = epbRoundingMode == EPB_MODE_RM ? M | Z : P | Z;  //RMのとき-0,それ以外は+0
 18743:           return this;
 18744:         }
 18745:         if (xf << 1 < 0 || yf << 2 < 0) {  //xが±0またはyが±Infのとき-y
 18746:           xf = yf ^ M;
 18747:           xe = y.epp;
 18748:           xd = y.dvl;
 18749:           xc = y.cvl;
 18750:         }
 18751:         //xが±Infまたはyが±0のときx
 18752:       } else {  //両方±0,±Inf,NaN以外
 18753:         //減算なのでyの符号を反転して加算する
 18754:         yf ^= M;
 18755:         long yd = y.dvl;
 18756:         long yc = y.cvl;
 18757:         int o = xe - y.epp;
 18758:         if (o < 0 || o == 0 && (xd < yd || xd == yd && xc >>> 1 < yc >>> 1)) {  //yの方が絶対値が大きい
 18759:           //xとyを入れ換える
 18760:           xf = yf;
 18761:           xe += o = -o;  //xe=y.epp
 18762:           xd = yd;
 18763:           xc = yc;
 18764:           yf = x.flg;  //後で符号を比較するときに使う
 18765:           yd = x.dvl;
 18766:           yc = x.cvl;
 18767:         }
 18768:         //xの方が絶対値が大きいか等しい
 18769:         //yを右にずらして小数点の位置を合わせる
 18770:         if (0 < o) {
 18771:           if (o <= 63) {
 18772:             xb = yc << -o;
 18773:             yc = yd << -o | yc >>> o;
 18774:             yd >>>= o;
 18775:           } else if (o == 64) {
 18776:             xb = yc;
 18777:             yc = yd;
 18778:             yd = 0L;
 18779:           } else if (o <= 127) {
 18780:             xb = yd << -o | yc;
 18781:             yc = yd >>> o;
 18782:             yd = 0L;
 18783:           } else {
 18784:             xb = yd | yc;  //絶対値減算を行うとき下位からのボローとして必要
 18785:             yc = 0L;
 18786:             yd = 0L;
 18787:           }
 18788:         }
 18789:         //絶対値加算または絶対値減算を行う
 18790:         if (xf == yf) {  //符号が同じなので絶対値加算を行う
 18791:           //yc[1]とyc[0]をsticky bitに押し出す
 18792:           xb |= yc << 62;
 18793:           //右にずらしてxd[63]を空ける
 18794:           xc = xd << 63 | xc >>> 1;
 18795:           xd >>>= 1;
 18796:           yc = yd << 63 | yc >>> 1;
 18797:           yd >>>= 1;
 18798:           //下位を右にずらしてxc[63]を空ける
 18799:           yc >>>= 1;
 18800:           xc >>>= 1;
 18801:           //足す
 18802:           xc += yc;
 18803:           xd += yd + (xc >>> 63);
 18804:           //下位を左にずらしてxc[63]を詰める
 18805:           xc <<= 1;
 18806:           //溢れの処理
 18807:           if (xd < 0L) {  //溢れたとき
 18808:             xe++;
 18809:           } else {  //溢れなかったとき
 18810:             xd = xd << 1 | xc >>> 63;  //左にずらしてxd[63]を詰める
 18811:             xc <<= 1;
 18812:           }
 18813:         } else {  //符号が異なるので絶対値減算を行う
 18814:           //yc[0]をsticky bitに押し出す
 18815:           xb |= yc << 63;
 18816:           //下位を右にずらしてxc[63]を空ける
 18817:           yc >>>= 1;
 18818:           xc >>>= 1;
 18819:           //引く
 18820:           //  xの方が絶対値が大きいか等しいので負になることはないが0になることがある
 18821:           if (xb != 0L) {
 18822:             xc--;
 18823:           }
 18824:           xc -= yc;
 18825:           xd -= yd + (xc >>> 63);
 18826:           //下位を左にずらしてxc[63]を詰める
 18827:           xc <<= 1;
 18828:           //正規化する
 18829:           if (0L <= xd) {
 18830:             if (xd != 0L) {
 18831:               xe -= o = Long.numberOfLeadingZeros (xd);
 18832:               xd = xd << o | xc >>> -o;
 18833:               xc <<= o;
 18834:             } else if (xc != 0L) {
 18835:               xe -= o = 64 + Long.numberOfLeadingZeros (xc);
 18836:               xd = xc << o;
 18837:               xc = 0L;
 18838:             } else {  //0になった
 18839:               xf = epbRoundingMode == EPB_MODE_RM ? M | Z : P | Z;  //RMのとき-0,それ以外は+0
 18840:             }
 18841:           }
 18842:         }  //if 符号が同じなので絶対値加算を行う/符号が異なるので絶対値減算を行う
 18843:       }  //if どちらかが±0,±Inf,NaN/両方±0,±Inf,NaN以外
 18844:       return this.finish (xf, xe, xd, xc, xb);
 18845:     }  //efp.sub(EFP,EFP)
 18846: 
 18847:     //------------------------------------------------------------------------
 18848:     //x = x.tan ()
 18849:     //  x=tan(x)
 18850:     //y = y.tan (x)
 18851:     //  y=tan(x)
 18852:     //  正接 tangent タンジェント
 18853:     //
 18854:     //  グラフ
 18855:     //    perl -e "use Math::Trig;use Graph;$g=new Graph();$g->grid();$g->func(sub{tan($_[0])});print$g"
 18856:     //    echo read("../misc/efp.gp");graph(tan) | gp -q
 18857:     //    +---------+---------+-*-------+---------+---------+--*------+---------+---------+
 18858:     //    |                     *                 |            *                          |
 18859:     //    |                     *                 |            *                          |
 18860:     //    |                    **                 |            *                          |
 18861:     //    |                    *                  |            *                          |
 18862:     //    +                    *                  +           **                          +
 18863:     //    |                    *                  |           *                           |
 18864:     //    |                   **                  |           *                           |
 18865:     //    |                   *                   |           *                           |
 18866:     //    |                   *                   |          **                           |
 18867:     //    +                  **                   +          *                            +
 18868:     //    |                  *                    |         **                            |
 18869:     //    |                 **                    |         *                             |
 18870:     //    |                 *                     |        **                             |
 18871:     //    |                **                     |       **                              *
 18872:     //    +               **                      +      **                              **
 18873:     //    |              **                       |     **                              **|
 18874:     //    |            ***                        |    **                             *** |
 18875:     //    |          ***                          |  ***                            ***   |
 18876:     //    |         **                            |***                            ***     |
 18877:     //    +-------***---------+---------+--------***--------+---------+---------***-------+
 18878:     //    |     ***                            ***|                            **         |
 18879:     //    |   ***                            ***  |                          ***          |
 18880:     //    | ***                             **    |                        ***            |
 18881:     //    |**                              **     |                       **              |
 18882:     //    **                              **      +                      **               +
 18883:     //    *                              **       |                     **                |
 18884:     //    |                             **        |                     *                 |
 18885:     //    |                             *         |                    **                 |
 18886:     //    |                            **         |                    *                  |
 18887:     //    +                            *          +                   **                  +
 18888:     //    |                           **          |                   *                   |
 18889:     //    |                           *           |                   *                   |
 18890:     //    |                           *           |                  **                   |
 18891:     //    |                           *           |                  *                    |
 18892:     //    +                          **           +                  *                    +
 18893:     //    |                          *            |                  *                    |
 18894:     //    |                          *            |                 **                    |
 18895:     //    |                          *            |                 *                     |
 18896:     //    |                          *            |                 *                     |
 18897:     //    +---------+---------+------*--+---------+---------+-------*-+---------+---------+
 18898:     //
 18899:     //  定義域
 18900:     //    -inf<=x<=inf
 18901:     //
 18902:     //  値域
 18903:     //    -inf<=tan(x)<=inf
 18904:     //
 18905:     //  三角関数のとの関係
 18906:     //    tan(x)=sin(x)/cos(x)
 18907:     //
 18908:     //  加法定理
 18909:     //    tan(x+y)=(tan(x)+tan(y))/(1-tan(x)*tan(y))
 18910:     //
 18911:     //  倍角と半角
 18912:     //    tan(2*x)=tan(x+x)
 18913:     //            =(tan(x)+tan(x))/(1-tan(x)*tan(x))
 18914:     //            =2*tan(x)/(1-tan(x)^2)
 18915:     //    tan(3*x)=tan(2*x+x)
 18916:     //            =(tan(2*x)+tan(x))/(1-tan(2*x)*tan(x))
 18917:     //            =(2*tan(x)/(1-tan(x)^2)+tan(x))/(1-2*tan(x)/(1-tan(x)^2)*tan(x))
 18918:     //            =(tan(x)^3-3*tan(x))/(3*tan(x)^2-1)
 18919:     //    tan(x)=2*tan(x/2)/(1-tan(x/2)^2)
 18920:     //    tan(x/2)=(+/-sqrt(tan(x)^2+1)-1)/tan(x)
 18921:     //
 18922:     //  変数変換1
 18923:     //    収束を速くするために|x|<=pi/8にする
 18924:     //    tan(pi/4)=1
 18925:     //    tan(x+pi/4)=(tan(x)+tan(pi/4))/(1-tan(x)*tan(pi/4))
 18926:     //               =(tan(x)+1)/(1-tan(x))
 18927:     //    tan(3*pi/4)=-1
 18928:     //    tan(x+3*pi/4)=(tan(x)+tan(3*pi/4))/(1-tan(x)*tan(3*pi/4))
 18929:     //                 =(tan(x)-1)/(1+tan(x))
 18930:     //    tan(x)=(tan(x-pi/4)+1)/(1-tan(x-pi/4))
 18931:     //          =-1/tan(x-pi/2)
 18932:     //          =(tan(x-3*pi/4)-1)/(1+tan(x-3*pi/4))
 18933:     //          =tan(x-pi)
 18934:     //                -1/tan(x-pi/2)
 18935:     //                  k=3     k=2
 18936:     //                  ←      ←
 18937:     //                    \  │  /   (tan(x-pi/4)+1)/(1-tan(x-pi/4))
 18938:     //                 \  \ │ /  /
 18939:     //                   \ \│/ /   ↑k=1
 18940:     //           k=0↓~~-- \│/ --~~
 18941:     //     tan(x-pi) ────・──── tan(x)
 18942:     //                __-- /│\ --__↑k=0
 18943:     //           k=1↓   / /│\ \
 18944:     //                 /  / │ \  \
 18945:     //                    /  │  \
 18946:     //                    →      →
 18947:     //                    k=2     k=3
 18948:     //
 18949:     //  変数変換2
 18950:     //    場合分けを増やせばチェビシェフ展開の多項式を短くすることができる
 18951:     //    tan(pi/8)=(sqrt(tan(pi/4)^2+1)-1)/tan(pi/4)
 18952:     //             =(sqrt(1^2+1)-1)/1
 18953:     //             =sqrt(2)-1
 18954:     //    tan(3*pi/8)=(tan(pi/8)^3-3*tan(pi/8))/(3*tan(pi/8)^2-1)
 18955:     //               =((sqrt(2)-1)^3-3*(sqrt(2)-1))/(3*(sqrt(2)-1)^2-1)
 18956:     //               =(2-sqrt(2))/(3*sqrt(2)-4)
 18957:     //               =(2-sqrt(2))*(3*sqrt(2)+4)/(3*sqrt(2)-4)/(3*sqrt(2)+4)
 18958:     //               =(8-6+(6-4)*sqrt(2))/2
 18959:     //               =sqrt(2)+1
 18960:     //    tan(x)=(tan(x-pi/8)+sqrt(2)-1)/(1-tan(x-pi/8)*(sqrt(2)-1))
 18961:     //          =(tan(x-3*pi/8)+sqrt(2)+1)/(1-tan(x-3*pi/8)*(sqrt(2)+1))
 18962:     //          =(tan(x-5*pi/8)-(sqrt(2)+1))/(1+tan(x-3*pi/8)*(sqrt(2)+1))
 18963:     //          =(tan(x-7*pi/8)-(sqrt(2)-1))/(1+tan(x-3*pi/8)*(sqrt(2)-1))
 18964:     //
 18965:     //  ローラン級数展開
 18966:     //    tan(x)=x-x^3/3+2*x^5/15-17*x^7/315+...
 18967:     //          =sum[n=1..inf]{(-1)^n*4^n*(1-4^n)*B(2*n)*x^(2*n-1)/(2*n)!}  |x|<pi/2
 18968:     //    f(n,x)=sum(k=1,n,(-1)^k*4^k*(1-4^k)*bernreal(2*k)*x^(2*k-1)/(2*k)!)
 18969:     //
 18970:     //  チェビシェフ展開
 18971:     //    echo read("../misc/efp.gp");eval("f(x)=tan(x)");a=-Pi/8;b=Pi/8;forstep(n=1,35,2,printf("%4d",floor(closeness(f,chebyshev(f,a,b,n),a,b,10000)))) | gp -q
 18972:     //    echo read("../misc/efp.gp");eval("f(x)=tan(x)");a=-Pi/16;b=Pi/16;forstep(n=1,35,2,printf("%4d",floor(closeness(f,chebyshev(f,a,b,n),a,b,10000)))) | gp -q
 18973:     //    echo read("../misc/efp.gp");eval("f(x)=tan(x)");a=-Pi/32;b=Pi/32;forstep(n=1,35,2,printf("%4d",floor(closeness(f,chebyshev(f,a,b,n),a,b,10000)))) | gp -q
 18974:     //    echo read("../misc/efp.gp");eval("f(x)=tan(x)");a=-Pi/64;b=Pi/64;forstep(n=1,21,2,printf("%4d",floor(closeness(f,chebyshev(f,a,b,n),a,b,10000)))) | gp -q
 18975:     //    echo read("../misc/efp.gp");eval("f(x)=tan(x)");a=-Pi/128;b=Pi/128;forstep(n=1,21,2,printf("%4d",floor(closeness(f,chebyshev(f,a,b,n),a,b,10000)))) | gp -q
 18976:     //    echo read("../misc/efp.gp");eval("f(x)=tan(x)");a=-Pi/256;b=Pi/256;forstep(n=1,15,2,printf("%4d",floor(closeness(f,chebyshev(f,a,b,n),a,b,10000)))) | gp -q
 18977:     //       1   3   5   7   9  11  13  15  17  19  21  23  25  27  29  31  33  35
 18978:     //       4   9  15  20  26  32  38  43  49  55  61  67  72  78  84  90  96 102  |x|<=pi/8
 18979:     //       6  13  21  29  36  44  52  60  67  75  83  91  99 107 115 123 130 138  |x|<=pi/16  pi/8  4要素
 18980:     //       8  17  27  37  46  56  66  76  86  95 105 115 125 135 145 155 165 175  |x|<=pi/32  pi/16  8要素
 18981:     //      10  21  33  45  56  68  80  92 104 115 127  |x|<=pi/64  pi/32  16要素
 18982:     //      12  25  39  53  66  80  94 108 122 135 149  |x|<=pi/128  pi/64  32要素
 18983:     //      14  29  45  61  76  92 108 124  |x|<=pi/256  pi/128  64要素
 18984:     //
 18985:     public final EFP tan () {
 18986:       return this.tan (this);
 18987:     }  //efp.tan()
 18988:     public final EFP tan (EFP x) {
 18989:       int xf = x.flg;
 18990:       if (xf << 1 != 0) {  //±0,±Inf,NaN
 18991:         if (xf << 1 < 0) {  //±0
 18992:           this.flg = xf;  //tan(±0)=±0
 18993:         } else if (xf << 2 < 0) {  //±Inf
 18994:           epbFpsr |= EPB_FPSR_OE;
 18995:           epbExceptionOperandExponent = xf & M | 0x7fff << 16;
 18996:           epbExceptionOperandMantissa = 0x0000000000000000L;
 18997:           this.flg = N;  //tan(±Inf)=NaN
 18998:         } else {  //NaN
 18999:           this.flg = N;  //tan(NaN)=NaN
 19000:         }
 19001:         return this;
 19002:       }
 19003:       //±0,±Inf,NaN以外
 19004:       if (false) {  //sin/cos。[90] 800ns
 19005:         EFP c = new EFP ().inner ().cos (x);  //cos(x)
 19006:         return this.sin (x).outer ().div (c);  //sin(x)/cos(x)
 19007:       } else if (false) {  //4分割。[90] 600ns
 19008:         this.inner ();
 19009:         EFP s = new EFP ();
 19010:         EFP t = new EFP ();
 19011:         EFP u = new EFP ().iabs (x);  //|x|
 19012:         EFP u2 = new EFP ();
 19013:         int k = 0;  //|x|+pi/8の8分象限
 19014:         //if (u.gt (PI_8)) {  //|x|>pi/8
 19015:         if (u.epp >= -1 || (u.epp == -2 && u.dvl >= 0xc90fdaa22168c234L)) {  //|x|>=pi/8。下位の比較は省略する
 19016:           //s.iadd (u, PI_8).quo (PI_4);  //|x|+pi/8をpi/4で割った商
 19017:           s.iadd (u, PI_8).imul (FOUR_PI).trunc ();  //|x|+pi/8をpi/4で割った商
 19018:           //  |x|をpi/4で割った余りを求めるとき|x|がpi/4の整数倍に近いと桁落ちが発生するので倍精度で計算する
 19019:           u.sub (t.imulw (u2, s, PI_4)).sub (u2).sub (t.imul (s, PI_4A));  //|x|をpi/4で割った余り。[-pi/8,pi/8]
 19020:           k = s.geti () & 3;  //|x|+pi/8の8分象限
 19021:         }
 19022:         u2.isqu (u);  //u^2
 19023:         this.imul (TAN_C33, u2)
 19024:           .iadd (TAN_C31).imul (u2)
 19025:             .iadd (TAN_C29).imul (u2)
 19026:               .iadd (TAN_C27).imul (u2)
 19027:                 .iadd (TAN_C25).imul (u2)
 19028:                   .iadd (TAN_C23).imul (u2)
 19029:                     .iadd (TAN_C21).imul (u2)
 19030:                       .iadd (TAN_C19).imul (u2)
 19031:                         .iadd (TAN_C17).imul (u2)
 19032:                           .iadd (TAN_C15).imul (u2)
 19033:                             .iadd (TAN_C13).imul (u2)
 19034:                               .iadd (TAN_C11).imul (u2)
 19035:                                 .iadd (TAN_C9).imul (u2)
 19036:                                   .iadd (TAN_C7).imul (u2)
 19037:                                     .iadd (TAN_C5).imul (u2)
 19038:                                       .iadd (TAN_C3).imul (u2)
 19039:                                         .iadd (TAN_C1).imul (u);
 19040:         if (k == 1) {
 19041:           t.negdec (this);  //1-tan(x-pi/4)
 19042:           this.inc ().div (t);  //(1+tan(x-pi/4))/(1-tan(x-pi/4))
 19043:         } else if (k == 2) {
 19044:           this.rcp ().ineg ();  //-1/tan(x-pi/2)
 19045:         } else if (k == 3) {
 19046:           t.inc (this);  //tan(x-3*pi/4)+1
 19047:           this.dec ().div (t);  //(tan(x-3*pi/4)-1)/(tan(x-3*pi/4)+1)
 19048:         }
 19049:         return this.outer ().neg (xf < 0);  //tanは奇関数なのでxの符号を掛ける
 19050:       } else {  //128分割。[90] 350ns
 19051:         if (x.epp >= 16) {  //|x|が大きすぎる
 19052:           EFP c = new EFP ().inner ().cos (x);  //cos(x)
 19053:           return this.sin (x).outer ().div (c);  //sin(x)/cos(x)
 19054:         }
 19055:         int savedFpsr = epbFpsr;
 19056:         this.inner ();
 19057:         if (this == x) {
 19058:           x = new EFP (x);
 19059:         }
 19060:         if (x.epp < -3) {  //|x|<1/8
 19061:           EFP x2 = new EFP ().isqu (x);  //x^2
 19062:           this.imul (TAN8_C21, x2)
 19063:             .iadd (TAN8_C19).imul (x2)
 19064:               .iadd (TAN8_C17).imul (x2)
 19065:                 .iadd (TAN8_C15).imul (x2)
 19066:                   .iadd (TAN8_C13).imul (x2)
 19067:                     .iadd (TAN8_C11).imul (x2)
 19068:                       .iadd (TAN8_C9).imul (x2)
 19069:                         .iadd (TAN8_C7).imul (x2)
 19070:                           .iadd (TAN8_C5).imul (x2)
 19071:                             .iadd (TAN8_C3).imul (x2)
 19072:                               .iadd (TAN8_C1).outer ().mul (x);
 19073:           return this.originLowerUpper (x).correctUnderflow (savedFpsr);
 19074:         }
 19075:         EFP s = new EFP ();
 19076:         EFP t = new EFP ();
 19077:         EFP u = new EFP ().iabs (x);  //|x|
 19078:         EFP u2 = new EFP ();
 19079:         s.iadd (u, TAN7_X).imul (TAN7_Y).trunc ();  //|x|+pi/256をpi/128で割った商
 19080:         //  |x|をpi/128で割った余りを求めるとき|x|がpi/128の整数倍に近いと桁落ちが発生するので倍精度で計算する
 19081:         u.sub (t.imulw (u2, s, TAN7_Z)).sub (u2).sub (t.imul (s, TAN7_ZA));  //|x|をpi/128で割った余り。[-pi/256,pi/256]
 19082:         int k = s.geti () & 127;  //|x|+pi/256をpi/128で割った商の下位7bit
 19083:         u2.isqu (u);  //u^2
 19084:         this.imul (TAN7_C11, u2)
 19085:           .iadd (TAN7_C9).imul (u2)
 19086:             .iadd (TAN7_C7).imul (u2)
 19087:               .iadd (TAN7_C5).imul (u2)
 19088:                 .iadd (TAN7_C3).imul (u2)
 19089:                   .iadd (TAN7_C1).imul (u);
 19090:         if (k != 0) {
 19091:           if (k <= 63) {
 19092:             t = TAN7_T[k];
 19093:             s.imul (this, t).negdec ();
 19094:             this.iadd (t).div (s);  //(tan(x-k*pi/128)+t)/(1-tan(k*pi/128)*t)
 19095:           } else if (k == 64) {
 19096:             this.rcp ().ineg ();  //-1/tan(x-pi/2)
 19097:           } else {
 19098:             t = TAN7_T[128 - k];
 19099:             s.imul (this, t).inc ();
 19100:             this.sub (t).div (s);  //(tan(x-(128-k)*pi/128)-t)/(1+tan((128-k)*pi/128)*t)
 19101:           }
 19102:         }
 19103:         return this.outer ().neg (xf < 0);  //tanは奇関数なのでxの符号を掛ける
 19104:       }
 19105:     }  //efp.tan(EFP)
 19106: 
 19107:     //------------------------------------------------------------------------
 19108:     //x = x.tanh ()
 19109:     //  x=tanh(x)
 19110:     //y = y.tanh (x)
 19111:     //  y=tanh(x)
 19112:     //  双曲線正接 hyperbolic tangent ハイパボリックタンジェント
 19113:     //
 19114:     //  グラフ
 19115:     //    perl -e "use Math::Trig;use Graph;$g=new Graph();$g->grid();$g->func(sub{tanh($_[0])});print$g"
 19116:     //    echo read("../misc/efp.gp");graph(tanh) | gp -q
 19117:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
 19118:     //    |                                       |                                       |
 19119:     //    |                                       |                                       |
 19120:     //    |                                       |                                       |
 19121:     //    |                                       |                                       |
 19122:     //    +                                       +                                       +
 19123:     //    |                                       |                                       |
 19124:     //    |                                       |                                       |
 19125:     //    |                                       |                                       |
 19126:     //    |                                       |                                       |
 19127:     //    +                                       +                                       +
 19128:     //    |                                       |                                       |
 19129:     //    |                                       |                                       |
 19130:     //    |                                       |                                       |
 19131:     //    |                                       |                                       |
 19132:     //    +                                       +              **************************
 19133:     //    |                                       |        *******                        |
 19134:     //    |                                       |    *****                              |
 19135:     //    |                                       |  ***                                  |
 19136:     //    |                                       |***                                    |
 19137:     //    +---------+---------+---------+--------***--------+---------+---------+---------+
 19138:     //    |                                    ***|                                       |
 19139:     //    |                                  ***  |                                       |
 19140:     //    |                              *****    |                                       |
 19141:     //    |                        *******        |                                       |
 19142:     //    **************************              +                                       +
 19143:     //    |                                       |                                       |
 19144:     //    |                                       |                                       |
 19145:     //    |                                       |                                       |
 19146:     //    |                                       |                                       |
 19147:     //    +                                       +                                       +
 19148:     //    |                                       |                                       |
 19149:     //    |                                       |                                       |
 19150:     //    |                                       |                                       |
 19151:     //    |                                       |                                       |
 19152:     //    +                                       +                                       +
 19153:     //    |                                       |                                       |
 19154:     //    |                                       |                                       |
 19155:     //    |                                       |                                       |
 19156:     //    |                                       |                                       |
 19157:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
 19158:     //
 19159:     //  定義域
 19160:     //    -inf<=x<=inf
 19161:     //
 19162:     //  値域
 19163:     //    -1<=tanh(x)<=1
 19164:     //
 19165:     //  双曲線関数との関係
 19166:     //    tanh(x)=sinh(x)/cosh(x)
 19167:     //
 19168:     //  指数関数との関係
 19169:     //    tanh(x)=(e^x-e^(-x))/(e^x+e^(-x))
 19170:     //           =(e^(2*x)-1)/(e^(2*x)+1)
 19171:     //    1-tanh(x)=2*e^-x/(e^x+e^-x)
 19172:     //
 19173:     //  微分
 19174:     //    df{tanh(x)}=1-tanh(x)^2
 19175:     //               =sech(x)^2
 19176:     //               =1/cosh(x)^2
 19177:     //
 19178:     //  加法定理
 19179:     //    tanh(x+y)=(tanh(x)+tanh(y))/(1+tanh(x)*tanh(y))
 19180:     //
 19181:     //  定義域の制限
 19182:     //    仮数部がLENbitのとき|x|<=atanh(1-2^-LEN)でなければtanh(x)とsgn(x)を区別できない
 19183:     //    92bitならば
 19184:     //    > atanh(1-2^-92);
 19185:     //    32.231343896037456887901293647754723317576611492206
 19186:     //
 19187:     //  変数変換1
 19188:     //    tanh(x+log((c+1)/(c-1))/2)=tanh(x+log((1+1/c)/(1-1/c))/2)
 19189:     //                              =tanh(x+atanh(1/c))
 19190:     //                              =(tanh(x)+tanh(atanh(1/c)))/(1+tanh(x)*tanh(atanh(1/c)))
 19191:     //                              =(tanh(x)+1/c)/(1+tanh(x)*1/c)
 19192:     //                              =(c*tanh(x)+1)/(c+tanh(x))
 19193:     //                              =(c^2+c*tanh(x)-c^2+1)/(c+tanh(x))
 19194:     //                              =c-(c^2-1)/(c+tanh(x))
 19195:     //    tanh(x+1*log((c+1)/(c-1))/2)=(c*tanh(x)+1)/(c+tanh(x))
 19196:     //    tanh(x+2*log((c+1)/(c-1))/2)=(c^2*tanh(x)+2*c+tanh(x))/(c^2+2*c*tanh(x)+1)
 19197:     //    tanh(x+3*log((c+1)/(c-1))/2)=(c^3*tanh(x)+3*c^2+3*c*tanh(x)+1)/(c^3+3*c^2*tanh(x)+3*c+tanh(x))
 19198:     //    tanh(x+4*log((c+1)/(c-1))/2)=(c^4*tanh(x)+4*c^3+6*c^2*tanh(x)+4*c+tanh(x))/(c^4+4*c^3*tanh(x)+6*c^2+4*c*tanh(x)+1)
 19199:     //    tanh(x+5*log((c+1)/(c-1))/2)=(c^5*tanh(x)+5*c^4+10*c^3*tanh(x)+10*c^2+5*c*tanh(x)+1)/(c^5+5*c^4*tanh(x)+10*c^3+10*c^2*tanh(x)+5*c+tanh(x))
 19200:     //    tanh(x+k*log((c+1)/(c-1))/2)は(c+1)^kを二項展開してkと奇偶が同じ項にtanh(x)を掛けたものをkと奇偶が異なる項にtanh(x)を掛けたもので割ったものになっている
 19201:     //    cが定数でkが大きすぎなければすべてのkについてc0+1/(c1+c2*tanh(x))の形に整理して係数をテーブルに列挙しておくことができる
 19202:     //    log((c+1)/(c-1))/2が2の累乗になるようにcを定めれば分割に除算はいらない
 19203:     //    例えば、|x|<=1/4の範囲をチェビシェフ展開する場合、幅が1/2なので
 19204:     //      log((c+1)/(c-1))/2=1/2
 19205:     //      log((c+1)/(c-1))=1
 19206:     //      (c+1)/(c-1)=e
 19207:     //      c=(e+1)/(e-1)
 19208:     //    を使ってテーブルを作ればよい
 19209:     //    しかし、チェビシェフ展開の項数を減らそうとして幅を狭くするとテーブルが巨大化してしまう
 19210:     //    実用的な範囲ではtanh(x)=(e^(2*x)-1)/(e^(2*x)+1)より速くならないかも知れない
 19211:     //
 19212:     //  変数変換2
 19213:     //    tanh(x+k*log((c+1)/(c-1))/2)でk=2^jの式だけテーブルに展開しておいて平行移動の式を動的に作る
 19214:     //    分子と分母を分けておけば除算は最後の1回だけで済む
 19215:     //
 19216:     //  変数変換3
 19217:     //    xの指数部を見て開始範囲を選択する
 19218:     //    テーブルを参照してxが範囲の中央の1/3に含まれているか確認する
 19219:     //    中央の1/3に含まれていない場合は中央の1/3まで平行移動するための式を分子と分母に分けて作る
 19220:     //    xが十分に小さくなるまで繰り返す
 19221:     //    チェビシェフ展開で計算する
 19222:     //    平行移動の式で元の位置に戻す。最後に1回だけ除算が必要になる
 19223:     //
 19224:     //  ローラン級数展開
 19225:     //    tanh(x)=x+x^3/3+2*x^5/15+17*x^7/315+...
 19226:     //           =sum[n=1..inf]{4^n*(4^n-1)*B(2*n)*x^(2*n-1)/(2*n)!}  |x|<pi/2
 19227:     //    f(n,x)=sum(k=1,n,4^k*(4^k-1)*bernreal(2*k)*x^(2*k-1)/(2*k)!)
 19228:     //    echo for(k=1,10,x=eval("4^k*(4^k-1)*bernfrac(2*k)/(2*k)!");print("    //    ",x,"*x^",2*k-1)) | gp -q
 19229:     //    1*x^1
 19230:     //    -1/3*x^3
 19231:     //    2/15*x^5
 19232:     //    -17/315*x^7
 19233:     //    62/2835*x^9
 19234:     //    -1382/155925*x^11
 19235:     //    21844/6081075*x^13
 19236:     //    -929569/638512875*x^15
 19237:     //    6404582/10854718875*x^17
 19238:     //    -443861162/1856156927625*x^19
 19239:     //
 19240:     //  チェビシェフ展開
 19241:     //    0の近くだけチェビシェフ展開を使う
 19242:     //    echo read("../misc/efp.gp");eval("f(x)=tanh(x)");a=-0.25;b=0.25;forstep(n=1,31,2,printf("%4d",floor(closeness(f,chebyshev(f,a,b,n),a,b,10000)))) | gp -q
 19243:     //    echo read("../misc/efp.gp");eval("f(x)=tanh(x)");a=-0.125;b=0.125;forstep(n=1,31,2,printf("%4d",floor(closeness(f,chebyshev(f,a,b,n),a,b,10000)))) | gp -q
 19244:     //    echo read("../misc/efp.gp");eval("f(x)=tanh(x)");a=-0.0625;b=0.0625;forstep(n=1,31,2,printf("%4d",floor(closeness(f,chebyshev(f,a,b,n),a,b,10000)))) | gp -q
 19245:     //       1   3   5   7   9  11  13  15  17  19  21  23  25  27  29  31
 19246:     //       6  12  19  26  33  40  47  54  61  69  76  83  90  97 105 112
 19247:     //       8  16  25  34  43  52  61  70  79  88  98 107 116 125 134 144
 19248:     //      10  20  31  42  53  64  75  86  97 108 120 131 142 153 164 176
 19249:     //
 19250:     public final EFP tanh () {
 19251:       return this.tanh (this);
 19252:     }  //efp.tanh()
 19253:     public final EFP tanh (EFP x) {
 19254:       int xf = x.flg;
 19255:       if (xf << 1 != 0) {  //±0,±Inf,NaN
 19256:         if (xf << 2 < 0) {  //tanh(±Inf)=±1
 19257:           this.flg = xf & M;
 19258:           this.epp = 0;
 19259:           this.dvl = MSB;
 19260:           this.cvl = 0L;
 19261:         } else {  //tanh(±0)=±0, tanh(NaN)=NaN
 19262:           this.flg = xf;
 19263:         }
 19264:         return this;
 19265:       }
 19266:       //±0,±Inf,NaN以外
 19267:       //  e^xを経由する方法はオーバーフローを発生させずに計算できる範囲が狭いので|x|が大きい場合を分ける必要がある
 19268:       int xe = x.epp;
 19269:       if (xe < -2) {  //|x|<0.25
 19270:         int savedFpsr = epbFpsr;
 19271:         this.inner ();
 19272:         if (this == x) {
 19273:           x = new EFP (x);
 19274:         }
 19275:         EFP x2 = new EFP ().isqu (x);  //x^2
 19276:         this.imul (TANH_C27, x2)
 19277:           .iadd (TANH_C25).imul (x2)
 19278:             .iadd (TANH_C23).imul (x2)
 19279:               .iadd (TANH_C21).imul (x2)
 19280:                 .iadd (TANH_C19).imul (x2)
 19281:                   .iadd (TANH_C17).imul (x2)
 19282:                     .iadd (TANH_C15).imul (x2)
 19283:                       .iadd (TANH_C13).imul (x2)
 19284:                         .iadd (TANH_C11).imul (x2)
 19285:                           .iadd (TANH_C9).imul (x2)
 19286:                             .iadd (TANH_C7).imul (x2)
 19287:                               .iadd (TANH_C5).imul (x2)
 19288:                                 .iadd (TANH_C3).imul (x2)
 19289:                                   .iadd (TANH_C1).outer ().mul (x);
 19290:         return this.originUpperLower (x).correctUnderflow (savedFpsr);
 19291:       }
 19292:       //0.25<=|x|
 19293:       if (false) {
 19294:         EFP c = new EFP ().inner ().cosh (x);  //cosh(x)
 19295:         return this.sinh (x).outer ().div (c);  //sinh(x)/cosh(x) [90]
 19296:       } else if (6 <= xe) {  //2^6<=|x|
 19297:         //  x=2^6のとき
 19298:         //  1-tanh(x)=1-(e^x-e^(-x))/(e^x+e^(-x))
 19299:         //           =2*e^(-x)/(e^x+e^(-x))
 19300:         //  の値は
 19301:         //  echo x=eval("2^6");log(2*exp(-x)/(exp(x)+exp(-x)))/log(2) | gp -q
 19302:         //  -183.66496523378731614207035916824219359
 19303:         //  であるから2^6<=xのときtanh(x)と1を区別できない
 19304:         //  tanh(x)は奇関数なのでx<=-2^6の場合も同様にtanh(x)と-1を区別できない
 19305:         epbFpsr |= EPB_FPSR_X2;  //不正確な結果
 19306:         this.flg = xf & M;  //±1
 19307:         this.epp = 0;
 19308:         this.dvl = MSB;
 19309:         this.cvl = 0L;
 19310:         if (xf < 0) {
 19311:           if (epbRoundingMode == EPB_MODE_RZ || epbRoundingMode == EPB_MODE_RP) {
 19312:             this.nextup (epbRoundingPrec);
 19313:           }
 19314:         } else {
 19315:           if (epbRoundingMode == EPB_MODE_RZ || epbRoundingMode == EPB_MODE_RM) {
 19316:             this.nextdown (epbRoundingPrec);
 19317:           }
 19318:         }
 19319:         return this;
 19320:       } else {
 19321:         EFP t = new EFP ().inner ().imul2 (x).exp ();  //e^(2*x)
 19322:         this.dec (t);
 19323:         t.inc ();
 19324:         return this.outer ().div (t);  //(e^(2*x)-1)/(e^(2*x)+1) [90]
 19325:       }
 19326:     }  //efp.tanh(EFP)
 19327: 
 19328:     //------------------------------------------------------------------------
 19329:     //x = x.tgamma ()
 19330:     //  x=Γ(x)
 19331:     //y = y.tgamma (x)
 19332:     //  y=Γ(x)
 19333:     //  ガンマ関数
 19334:     //
 19335:     //  グラフ
 19336:     //    echo read("../misc/efp.gp");graph(gamma) | gp -q
 19337:     //    *---------*---------+**----**-+---------+-*-------+---------+---------+-----**--+
 19338:     //    *         *           *    *            | *                                 *   |
 19339:     //    *         *           *    *            | **                               **   |
 19340:     //    *         *           *    *            |  *                               *    |
 19341:     //    *        **           *    *            |  *                              **    |
 19342:     //    *        *            *   **            +  *                              *     +
 19343:     //    *        *            **  *             |  *                             **     |
 19344:     //    *        *             *  *             |  **                           **      |
 19345:     //    *        *             ****             |   *                          **       |
 19346:     //    *        *                              |   *                          *        |
 19347:     //    *        *                              +   **                       ***        +
 19348:     //    *        *                              |    *                      **          |
 19349:     //    *        *                              |    **                    **           |
 19350:     //    *        *                              |     **                 ***            |
 19351:     //    *        *                              |      ***            ****              |
 19352:     //    **      **                              +        *****  *******                 +
 19353:     //    |*      *                               |            ****                       |
 19354:     //    |*     **                               |                                       |
 19355:     //    |**   **                                |                                       |
 19356:     //    | *****                                 |                                       |
 19357:     //    +---------+---------+---------+---------+---------+---------+---------+---------+
 19358:     //    |                                       |                                       |
 19359:     //    |                                       |                                       |
 19360:     //    |                                       |                                       |
 19361:     //    |            **                         |                                       |
 19362:     //    +           *****                       +                                       +
 19363:     //    |           *   **                      |                                       |
 19364:     //    |          **    *                      |                                       |
 19365:     //    |          *     *                      |                                       |
 19366:     //    |          *     **                     |                                       |
 19367:     //    +          *      *                     +                                       +
 19368:     //    |          *      *                     |                                       |
 19369:     //    |          *      *                     |                                       |
 19370:     //    |          *      *                     |                                       |
 19371:     //    |          *      *                     |                                       |
 19372:     //    +          *      **                    +                                       +
 19373:     //    |          *       *                    |                                       |
 19374:     //    |          *       *                    |                                       |
 19375:     //    |         **       *              ***   |                                       |
 19376:     //    |         *        *              * *   |                                       |
 19377:     //    +---------*--------*+---------+--**-**--+---------+---------+---------+---------+
 19378:     //
 19379:     //  Γ(x)=int[t=0..∞]{e^-t*t^(x-1)*dt}
 19380:     //  Γ(n)=(n-1)!
 19381:     //  Γ(n+1)=n!
 19382:     //        =n*Γ(n)
 19383:     //
 19384:     //  x<0のとき
 19385:     //    Γ(x)*Γ(1-x)=π/sin(π*x)
 19386:     //    で1<xにする
 19387:     //    Γ(x)=π/sin(π*x)/Γ(1-x)
 19388:     //        =π/sin(π*x)/e^lgamma(1-x)
 19389:     //
 19390:     //  x==-0のとき
 19391:     //    -∞
 19392:     //
 19393:     //  x==+0のとき
 19394:     //    +∞
 19395:     //
 19396:     //  0<xのとき
 19397:     //    Γ(x)=e^lgamma(x)
 19398:     //
 19399:     public final EFP tgamma () {
 19400:       return this.tgamma (this);
 19401:     }  //efp.tgamma()
 19402:     public final EFP tgamma (EFP x) {
 19403:       int xf = x.flg;
 19404:       if (xf << 1 != 0) {  //±0,±Inf,NaN
 19405:         this.flg = (xf == (P | Z) || xf == (P | I) ? P | I :  //tgamma(+0)=tgamma(+Inf)=+Inf
 19406:                     xf == (M | Z) ? M | I :  //tgamma(-0)=-Inf
 19407:                     N);  //tgamma(NaN)=tgamma(-Inf)=NaN
 19408:         return this;
 19409:       }
 19410:       //±0,±Inf,NaN以外
 19411:       this.inner ();
 19412:       if (xf < 0) {  //x<0
 19413:         EFP t = new EFP ().mul (PI, x).sin ();  //sin(π*x)
 19414:         this.negdec (x).lgamma ().exp ().mul (t).rcpdiv (PI);  //π/(e^lgamma(1-x)*sin(π*x))
 19415:       } else {  //0<x
 19416:         this.lgamma (x).exp ();  //e^lgamma(x)
 19417:       }
 19418:       return this.outer ().finish ();
 19419:     }  //efp.tgamma(EFP)
 19420: 
 19421:     //------------------------------------------------------------------------
 19422:     //s = x.toString ()
 19423:     //  10進数文字列化
 19424:     //
 19425:     //  絶対値が1以上で整数部が有効bit数を表現するのに十分な桁数に収まるとき
 19426:     //    指数部を付けずに出力する
 19427:     //    小数部の末尾の0を省略する
 19428:     //    小数部がすべて省略されたときは小数点も省略する
 19429:     //  絶対値が1未満で整数部の0と小数部を合わせて有効bit数を表現するのに十分な桁数+3桁に収まるとき
 19430:     //    指数部を付けずに出力する
 19431:     //    小数部の末尾の0を省略する
 19432:     //  それ以外
 19433:     //    整数部が1~9の浮動小数点形式で出力する
 19434:     //
 19435:     @Override public String toString () {
 19436:       int xf = this.flg;
 19437:       if (xf << 1 != 0) {  //±0,±Inf,NaN
 19438:         return (xf == (P | Z) ? "0" :
 19439:                 xf == (M | Z) ? "-0" :
 19440:                 xf == (P | I) ? "Infinity" :
 19441:                 xf == (M | I) ? "-Infinity" :
 19442:                 xf << 3 < 0 ? "NaN" : "???");
 19443:       }
 19444:       //±0,±Inf,NaN以外
 19445:       this.inner ();
 19446:       EFP x = new EFP ().iabs (this);  //絶対値
 19447:       //10進数で表現したときの指数部を求める
 19448:       //  10^e<=x<10^(e+1)となるeを求める
 19449:       int e = (int) Math.floor ((double) x.epp * 0.30102999566398119521373889472);  //log10(2)
 19450:       //10^-eを掛けて1<=x<10にする
 19451:       //  非正規化数の最小値から正規化数の最大値まで処理できなければならない
 19452:       //  10^-eを計算してからまとめて掛ける方法は10^-eがオーバーフローするおそれがあるので不可
 19453:       if (0 < e) {  //10<=x
 19454:         x.imul (EFP_TEN_M16QR[e & 15]);
 19455:         if (16 <= e) {
 19456:           x.imul (EFP_TEN_M16QR[16 + (e >> 4 & 15)]);
 19457:           if (256 <= e) {
 19458:             x.imul (EFP_TEN_M16QR[32 + (e >> 8 & 15)]);
 19459:             if (4096 <= e) {
 19460:               x.imul (EFP_TEN_M16QR[48 + (e >> 12)]);
 19461:             }
 19462:           }
 19463:         }
 19464:       } else if (e < 0) {  //x<1
 19465:         x.imul (EFP_TEN_P16QR[-e & 15]);
 19466:         if (e <= -16) {
 19467:           x.imul (EFP_TEN_P16QR[16 + (-e >> 4 & 15)]);
 19468:           if (e <= -256) {
 19469:             x.imul (EFP_TEN_P16QR[32 + (-e >> 8 & 15)]);
 19470:             if (e <= -4096) {
 19471:               x.imul (EFP_TEN_P16QR[48 + (-e >> 12)]);
 19472:             }
 19473:           }
 19474:         }
 19475:       }
 19476:       this.outer ();
 19477:       //整数部2桁、小数部EFP_DECIMAL_PREC+4&-4桁の10進数に変換する
 19478:       //  1<=x<10なのでw[1]が先頭になるはずだが誤差で前後にずれる可能性がある
 19479:       //  小数部を10000倍して整数部を引くことを繰り返すため、桁数に余裕のない浮動小数点数のまま行うと情報落ちが発生して誤差が蓄積する
 19480:       //  固定小数点に切り替えて誤差なしで計算する
 19481:       int[] w = new int[2 + (EFP_DECIMAL_PREC + 4 & -4)];
 19482:       {
 19483:         int t = 31 - x.epp;
 19484:         long x1 = x.dvl >>> t;  //上位32bitが整数部、下位32bitが小数部
 19485:         long x2 = x.dvl << -t | x.cvl >>> t;  //tは誤差を考慮しても最大32、x.cvlは下位32bitが0なのではみ出さない
 19486:         long x3 = x2 & 0xffffffffL;
 19487:         x2 >>>= 32;
 19488:         t = XEiJ.FMT_BCD4[(int) (x1 >>> 32)];  //整数部
 19489:         w[0] = t >>  4;
 19490:         w[1] = t       & 15;
 19491:         for (int i = 2; i < 2 + (EFP_DECIMAL_PREC + 4 & -4); i += 4) {
 19492:           x3 *= 10000L;
 19493:           x2 = x2 * 10000L + (x3 >>> 32);
 19494:           x3 &= 0xffffffffL;
 19495:           x1 = (x1 & 0xffffffffL) * 10000L + (x2 >>> 32);
 19496:           x2 &= 0xffffffffL;
 19497:           t = XEiJ.FMT_BCD4[(int) (x1 >>> 32)];  //整数部
 19498:           w[i    ] = t >> 12;
 19499:           w[i + 1] = t >>  8 & 15;
 19500:           w[i + 2] = t >>  4 & 15;
 19501:           w[i + 3] = t       & 15;
 19502:         }
 19503:       }
 19504:       //先頭の位置を確認する
 19505:       //  w[h]が先頭(0でない最初の数字)の位置
 19506:       int h = w[0] != 0 ? 0 : w[1] != 0 ? 1 : 2;
 19507:       //EFP_DECIMAL_PREC+1桁目を四捨五入する
 19508:       int o = h + EFP_DECIMAL_PREC;  //w[o]は四捨五入する桁の位置。w[]の範囲内
 19509:       if (5 <= w[o]) {
 19510:         int i = o;
 19511:         while (10 <= ++w[--i]) {
 19512:           w[i] = 0;
 19513:         }
 19514:         if (i < h) {  //先頭から繰り上がった。このとき新しい先頭は1でそれ以外はすべて0
 19515:           h--;  //先頭を左にずらす
 19516:           o--;  //末尾を左にずらす
 19517:         }
 19518:       }
 19519:       //先頭の位置に応じて指数部を更新する
 19520:       //  w[h]が整数部、w[h+1..o-1]が小数部。10^eの小数点はw[h]の右側。整数部の桁数はe+1桁
 19521:       e -= h - 1;
 19522:       //末尾の位置を確認する
 19523:       //  w[o-1]が末尾(0でない最後の数字)の位置
 19524:       while (w[o - 1] == 0) {  //全体は0ではないので必ず止まる。小数点よりも左側で止まる場合があることに注意
 19525:         o--;
 19526:       }
 19527:       //文字列に変換する
 19528:       StringBuilder sb = new StringBuilder ();
 19529:       //符号を付ける
 19530:       if (xf < 0) {
 19531:         sb.append ('-');
 19532:       }
 19533:       //指数形式にするかどうか選択する
 19534:       if (0 <= e && e < EFP_DECIMAL_PREC) {  //1<=x<10^EFP_DECIMAL_PREC。指数形式にしない
 19535:         do {
 19536:           sb.append ((char) ('0' + w[h++]));  //整数部。末尾の位置に関係なく1の位まで書く
 19537:         } while (0 <= --e);
 19538:         if (h < o) {  //小数部がある
 19539:           sb.append ('.');  //小数部があるときだけ小数点を書く
 19540:           do {
 19541:             sb.append ((char) ('0' + w[h++]));  //小数部
 19542:           } while (h < o);
 19543:         }
 19544:       } else if (-4 <= e && e < 0) {  //10^-4<=x<1。指数形式にしない
 19545:         sb.append ('0');  //整数部の0
 19546:         sb.append ('.');  //小数点
 19547:         while (++e < 0) {
 19548:           sb.append ('0');  //小数部の先頭の0の並び
 19549:         }
 19550:         do {
 19551:           sb.append ((char) ('0' + w[h++]));  //小数部
 19552:         } while (h < o);
 19553:       } else {  //x<10^-4または10^EFP_DECIMAL_PREC<=x。指数形式にする
 19554:         sb.append ((char) ('0' + w[h++]));  //整数部
 19555:         if (h < o) {  //小数部がある
 19556:           sb.append ('.');  //小数部があるときだけ小数点を書く
 19557:           do {
 19558:             sb.append ((char) ('0' + w[h++]));  //小数部
 19559:           } while (h < o);
 19560:         }
 19561:         sb.append ('e');  //指数部の始まり
 19562:         if (false) {
 19563:           sb.append (e);
 19564:         } else {
 19565:           if (e < 0) {
 19566:             sb.append ('-');  //指数部の負符号
 19567:             e = -e;
 19568:           } else {
 19569:             sb.append ('+');  //指数部の正符号
 19570:           }
 19571:           e = XEiJ.fmtBcd8 (e);
 19572:           int t = Integer.numberOfLeadingZeros (e);
 19573:           if (t <= 27) {
 19574:             if (t <= 23) {
 19575:               if (t <= 19) {
 19576:                 if (t <= 15) {
 19577:                   sb.append ((char) ('0' + (e >>> 16 & 15)));
 19578:                 }
 19579:                 sb.append ((char) ('0' + (e >>> 12 & 15)));
 19580:               }
 19581:               sb.append ((char) ('0' + (e >>>  8 & 15)));
 19582:             }
 19583:             sb.append ((char) ('0' + (e >>>  4 & 15)));
 19584:           }
 19585:           sb.append ((char) ('0' + (e        & 15)));
 19586:         }
 19587:       }
 19588:       return sb.toString ();
 19589:     }  //efp.toString()
 19590: 
 19591:     //------------------------------------------------------------------------
 19592:     //x = x.trunc ()
 19593:     //  x=trunc(x)
 19594:     //y = y.trunc (x)
 19595:     //  y=trunc(x)
 19596:     //  切り落とし truncate
 19597:     //
 19598:     //  グラフ
 19599:     //    perl -e "use Graph;$g=new Graph();$g->grid();$g->func(sub{int($_[0])});print$g"
 19600:     //    echo read("../misc/efp.gp");graph(truncate) | gp -q
 19601:     //    +---------+---------+---------+---------+---------+---------+---------+---------*
 19602:     //    |                                       |                                       |
 19603:     //    |                                       |                                       |
 19604:     //    |                                       |                                       |
 19605:     //    |                                       |                                       |
 19606:     //    +                                       +                             ***********
 19607:     //    |                                       |                                       |
 19608:     //    |                                       |                                       |
 19609:     //    |                                       |                                       |
 19610:     //    |                                       |                                       |
 19611:     //    +                                       +                   ***********         +
 19612:     //    |                                       |                                       |
 19613:     //    |                                       |                                       |
 19614:     //    |                                       |                                       |
 19615:     //    |                                       |                                       |
 19616:     //    +                                       +         ***********                   +
 19617:     //    |                                       |                                       |
 19618:     //    |                                       |                                       |
 19619:     //    |                                       |                                       |
 19620:     //    |                                       |                                       |
 19621:     //    +---------+---------+---------*********************---------+---------+---------+
 19622:     //    |                                       |                                       |
 19623:     //    |                                       |                                       |
 19624:     //    |                                       |                                       |
 19625:     //    |                                       |                                       |
 19626:     //    +                   ***********         +                                       +
 19627:     //    |                                       |                                       |
 19628:     //    |                                       |                                       |
 19629:     //    |                                       |                                       |
 19630:     //    |                                       |                                       |
 19631:     //    +         ***********                   +                                       +
 19632:     //    |                                       |                                       |
 19633:     //    |                                       |                                       |
 19634:     //    |                                       |                                       |
 19635:     //    |                                       |                                       |
 19636:     //    ***********                             +                                       +
 19637:     //    |                                       |                                       |
 19638:     //    |                                       |                                       |
 19639:     //    |                                       |                                       |
 19640:     //    |                                       |                                       |
 19641:     //    *---------+---------+---------+---------+---------+---------+---------+---------+
 19642:     //
 19643:     //    ±0,±Inf,NaN    そのまま
 19644:     //    e<=-1          すべて小数部なので±0
 19645:     //    0<=e&&e<LEN-1  整数部と小数部が両方あるので小数部を消す
 19646:     //    LEN-1<=e       すべて整数部なのでそのまま
 19647:     //
 19648:     public final EFP trunc () {
 19649:       return trunc (this);
 19650:     }  //efp.trunc()
 19651:     public final EFP trunc (EFP x) {  //1.6ns
 19652:       int xf = x.flg;
 19653:       if (xf << 1 != 0) {  //±0,±Inf,NaN
 19654:         this.flg = xf;
 19655:         return this;
 19656:       }
 19657:       //±0,±Inf,NaN以外
 19658:       int xe = x.epp;
 19659:       if (xe < 0) {  //すべて小数部
 19660:         epbFpsr |= EPB_FPSR_X2;  //不正確な結果
 19661:         this.flg = xf | Z;  //±0
 19662:         return this;
 19663:       }
 19664:       long xd = x.dvl;
 19665:       long xc = x.cvl;
 19666:       if (xe <= 63) {  //0..63。dの途中または末尾まで整数部
 19667:         long m = MSB >> xe;  //整数部のマスク。符号に注意
 19668:         if ((xd & ~m | xc) != 0L) {  //小数部が0ではない
 19669:           epbFpsr |= EPB_FPSR_X2;  //不正確な結果
 19670:           xd &= m;  //小数部を切り捨てる
 19671:           xc = 0L;
 19672:         }
 19673:       } else if (xe <= LEN - 2) {  //64..90。cの途中まで整数部
 19674:         long m = MSB >> xe;  //整数部のマスク。符号に注意
 19675:         if ((xc & ~m) != 0L) {  //小数部が0ではない
 19676:           epbFpsr |= EPB_FPSR_X2;  //不正確な結果
 19677:           xc &= m;  //小数部を切り捨てる
 19678:         }
 19679:       }
 19680:       //すべて整数部のときはそのまま
 19681:       return this.finish (xf, xe, xd, xc, 0L);
 19682:     }  //efp.trunc(EFP)
 19683: 
 19684:     //------------------------------------------------------------------------
 19685:     //x = x.ulp ()
 19686:     //  x=ulp(x)
 19687:     //y = y.ulp (x)
 19688:     //  y=ulp(x)
 19689:     //  ulp
 19690:     //
 19691:     //  最下位bitの単位(ulp;unit last place)
 19692:     //  nextup(abs(x))-abs(x)
 19693:     //  ulp(±0)=指数部が最小の値, ulp(±Inf)=±Inf, ulp(NaN)=NaN
 19694:     //
 19695:     public final EFP ulp () {
 19696:       return this.ulp (this);
 19697:     };  //efp.ulp()
 19698:     public final EFP ulp (EFP x) {
 19699:       int xf = x.flg;
 19700:       if (xf << 1 != 0) {  //±0,±Inf,NaN
 19701:         if (xf << 1 < 0) {  //±0
 19702:           this.flg = P;
 19703:           this.epp = -32768;
 19704:           this.dvl = MSB;
 19705:           this.cvl = 0L;
 19706:         } else {
 19707:           this.flg = xf & ~M;
 19708:         }
 19709:         return this;
 19710:       }
 19711:       //±0,±Inf,NaN以外
 19712:       this.flg = P;
 19713:       this.epp = x.epp - (LEN - 1);
 19714:       this.dvl = MSB;
 19715:       this.cvl = 0L;
 19716:       return this;
 19717:     };  //efp.ulp(EFP)
 19718: 
 19719:   }  //class EFP
 19720: 
 19721: 
 19722: 
 19723:   //------------------------------------------------------------------------
 19724:   //コプロセッサインタフェイス
 19725:   //
 19726:   //  CIR(コプロセッサインタフェイスレジスタ)を介して浮動小数点命令を対話形式で実行する
 19727:   //  on-chip FPUとやることは同じだが、命令の中断、保存、復元、再開ができる
 19728:   //  浮動小数点命令をコマンドワードで分類するところまではon-chip FPUと同じ
 19729:   //  そこからさらに命令の処理段階で分類する
 19730:   //
 19731:   //  CPU空間(FC=7)
 19732:   //    0x...0....  Breakpoint Acknowledge
 19733:   //    0x...1....  Access Level Control
 19734:   //    0x...2....  Coprocessor Communications
 19735:   //    0x00020000  id=0
 19736:   //    0x00022000  id=1  MC68881/MC68882
 19737:   //    0x00024000  id=2
 19738:   //    0x00026000  id=3
 19739:   //    0x00028000  id=4
 19740:   //    0x0002a000  id=5
 19741:   //    0x0002c000  id=6
 19742:   //    0x0002e000  id=7
 19743:   //    0x...f....  Interrupt Acknowledge
 19744:   //
 19745:   //  拡張ボード
 19746:   //    0x00e9e000  JP1  数値演算プロセッサボード(CZ-6BP1/CZ-6BP1A)
 19747:   //    0x00e9e080  JP2  数値演算プロセッサボード(CZ-6BP1/CZ-6BP1A)
 19748:   //
 19749:   //  FSAVE
 19750:   //    $04 save CIRから1ワードのフォーマットワードを読み出す
 19751:   //    $01xxが返ったときはカムアゲインなので読み直す
 19752:   //    MC68882のフォーマットワードは$00xx、$1F38、$1FD4のいずれか
 19753:   //      $00xxはヌルステート。xxは無効。ヌルステートフレームのサイズは0バイト
 19754:   //      $1F38はアイドルステート。アイドルステートフレームのサイズは$38=56バイト
 19755:   //      $1FD4はビジーステート。ビジーステートフレームのサイズは$D4=212バイト
 19756:   //    ヌルステートのときはここで終わり
 19757:   //    $10 operand CIRからステートフレームを読み出す
 19758:   //    FSAVEはプレデクリメントが前提なのでロング単位で逆順に読み出される
 19759:   //    スタックにステートフレームをプッシュする
 19760:   //    スタックにフォーマットワード<<16をプッシュする
 19761:   //  FRESTORE
 19762:   //    スタックからフォーマットワード<<16をポップする
 19763:   //    $06 restore CIRにフォーマットワードを書き込む
 19764:   //    $06 restore CIRからフォーマットワードを読み出す
 19765:   //    書き込んだフォーマットワードがそのまま返ればよい。$02xxが返ったときは不正なフォーマットワードなのでここで失敗
 19766:   //    スタックからステートフレームをポップする
 19767:   //    $10 operand CIRにステートフレームを書き込む
 19768:   //    FRESTOREはポストインクリメントが前提なのでロング単位で正順に書き込む
 19769:   //    異常なステートフレームをリストアすると、マニュアルにないレスポンスが返ったり、オペランドCIRのアクセスがプロトコル違反ではなくてバスエラーになったり、かなりおかしなことになる
 19770:   //    $06 restore CIRにヌルステートの$0000を書き込むとリセットされる
 19771:   //    fp0-fp7はすべてNon-signaling NaNになり、FPCRとFPSRはゼロクリアされる
 19772:   //    --------------------------------
 19773:   //    > cir 00 .
 19774:   //    0802 
 19775:   //    > cir 0a 4000               fmove.l <ea>,fp0
 19776:   //    > cir 00 ....
 19777:   //    9504 8900 8900 8900 
 19778:   //    > cir 10 00000001
 19779:   //    > cir 00 ....
 19780:   //    0802 0802 0802 0802 
 19781:   //    > cir 0a 6000               fmove.l fp0,<ea>
 19782:   //    > cir 00 ....
 19783:   //    8900 B104 0802 0802 
 19784:   //    > cir 10 .
 19785:   //    00000001 
 19786:   //    > cir 00 ....
 19787:   //    0802 0802 0802 0802 
 19788:   //    > cir 0a 6000               fmove.l fp0,<ea>
 19789:   //    > cir 04 .                  fsave
 19790:   //    1F38 
 19791:   //    > cir 10 ..............
 19792:   //    3C0EFFFF 00000001 00000000 00000002 FFFF0000 3FFF0000 20000000 00000000 00000000 00000000 00000200 60000000 0F800000 60006000 
 19793:   //    > cir 00 ....
 19794:   //    0802 0802 0802 0802 
 19795:   //    > cir 06 1F38               frestore
 19796:   //    > cir 06 .
 19797:   //    1F38 
 19798:   //    > cir 10 60006000 0F800000 60000000 00000200 00000000 00000000 00000000 20000000 3FFF0000 FFFF0000 00000002 00000000 00000001 3C0EFFFF
 19799:   //    > cir 00 ....
 19800:   //    8900 B104 0802 0802         fmove.l fp0,<ea>の続き
 19801:   //    > cir 10 .
 19802:   //    00000001 
 19803:   //    > cir 00 ....
 19804:   //    0802 0802 0802 0802 
 19805:   //    --------------------------------
 19806: 
 19807:   public static final boolean CIR_DEBUG_TRACE = false;
 19808: 
 19809:   //CIR
 19810:   //    0x00  word  read         response CIR
 19811:   //    0x02  word        write  control CIR
 19812:   //    0x04  word  read         save CIR
 19813:   //    0x06  word  read  write  restore CIR
 19814:   //    0x08  word  read  write  operation word CIR       MC68882のみ。MC68881ではwriteは無視、readは-1
 19815:   //    0x0a  word        write  command CIR
 19816:   //    0x0c  word  read  write  (reserved)               reserved CIRのアクセスはプロトコル違反にならない
 19817:   //    0x0e  word        write  condition CIR
 19818:   //    0x10  long  read  write  operand CIR
 19819:   //    0x14  word  read         register select CIR
 19820:   //    0x16  word  read  write  (reserved)               reserved CIRのアクセスはプロトコル違反にならない
 19821:   //    0x18  long        write  instruction address CIR
 19822:   //    0x1c  long  read  write  operand address CIR      MC68882のみ。MC68881ではwriteは無視、readは-1
 19823:   public int cirResponse;  //0x00 response CIRのレスポンス。上位ワードが0でないとき下位ワードを1回だけ出力して次回から上位ワードを出力する
 19824:   public int cirFormatWord;  //0x02 save CIRのフォーマットワード
 19825:   public int cirOperationWord;  //0x08 operation word CIR
 19826:   public int cirCommand;  //0x0a command CIR
 19827:   public int cirRegisterList;  //0x14 register select CIRの上位バイト
 19828:   public int cirOperandAddress;  //0x1c operand address CIR
 19829: 
 19830:   //オペランド
 19831:   public final int[] cirOperandBuffer = new int[212];  //ロング単位のオペランドバッファ
 19832:   public int cirOperandLength;  //転送中のオペランドのロング数
 19833:   public int cirOperandIndex;  //転送中のオペランドの次に転送するロング位置
 19834: 
 19835:   //命令の処理段階
 19836:   //  MC68882はデスティネーションオペランドの転送が終わる前にレスポンスプリミティブが0x0802になって次のコマンドを受け付けることができる
 19837:   //  ここではデスティネーションオペランドの転送が終わるまで次のコマンドを受け付けないことにする
 19838:   //  オペランドバッファは転送する直前に構築すること
 19839:   //    オペランドバッファを使わない段階ではFSAVEでオペランドバッファを保存しない
 19840:   public static final int CIR_INPUT_MASK            =                   16;  //オペランドバッファへ入力中
 19841:   public static final int CIR_OUTPUT_MASK           =                   32;  //オペランドバッファから出力中
 19842:   public static final int CIR_IDLE                  =                    0;  //アイドル
 19843:   public static final int CIR_PROGRAM_COUNTER       =                    1;  //プログラムカウンタをinstruction address CIRへ入力中
 19844:   public static final int CIR_DYNAMIC_K_FACTOR      = CIR_INPUT_MASK  |  2;  //動的k-factorをoperand CIRへ入力中
 19845:   public static final int CIR_DYNAMIC_REGISTER_LIST = CIR_INPUT_MASK  |  3;  //動的レジスタリストをoperand CIRへ入力中
 19846:   public static final int CIR_REGISTER_SELECT       =                    4;  //レジスタセレクトをregister select CIRから出力中
 19847:   public static final int CIR_SOURCE_OPERAND        = CIR_INPUT_MASK  |  5;  //ソースオペランドをoperand CIRへ入力中
 19848:   public static final int CIR_DESTINATION_OPERAND   = CIR_OUTPUT_MASK |  6;  //デスティネーションオペランドをoperand CIRから出力中
 19849:   public static final int CIR_FSAVE_STATE_FRAME     = CIR_OUTPUT_MASK |  7;  //FSAVEのステートフレームをoperand CIRから出力中
 19850:   public static final int CIR_FRESTORE_STATE_FRAME  = CIR_INPUT_MASK  |  8;  //FRESTOREのステートフレームをoperand CIRへ入力中
 19851:   public static final int CIR_EXCEPTION_PROCESSING  =                    9;  //例外処理中
 19852:   public static final String[] cirNameOfStage = {
 19853:     "idle",  //0
 19854:     "input program counter into the instruction address CIR",  //1
 19855:     "input dynamic k-factor into the operand CIR",  //2
 19856:     "input dynamic register list into the operand CIR",  //3
 19857:     "output register select from the register select CIR",  //4
 19858:     "input source operand into the operand CIR",  //5
 19859:     "output destination operand from the operand CIR",  //6
 19860:     "output FSAVE state frame from the operand CIR",  //7
 19861:     "input FRESTORE state from into the operand CIR",  //8
 19862:     "exception processing",  //9
 19863:   };
 19864:   public int cirStage;
 19865: 
 19866:   //cirInit ()
 19867:   //  初期化
 19868:   public final void cirInit () {
 19869:     //cirOperandBuffer = new int[212];
 19870:     Arrays.fill (cirOperandBuffer, 0);
 19871:     cirReset ();
 19872:   }  //cirInit()
 19873: 
 19874:   //cirReset ()
 19875:   //  リセット
 19876:   public final void cirReset () {
 19877:     cirIdle (0x0802);
 19878:   }  //cirReset()
 19879: 
 19880:   //cirIdle ()
 19881:   //  アイドルに戻す
 19882:   public final void cirIdle (int response) {
 19883:     if (CIR_DEBUG_TRACE) {
 19884:       System.out.printf ("%08x cirIdle(0x%08x)\n", XEiJ.regPC0, response);
 19885:     }
 19886:     cirResponse = response;
 19887:     cirOperationWord = 0;
 19888:     cirCommand = 0;
 19889:     cirRegisterList = 0;
 19890:     cirOperandAddress = 0;
 19891:     Arrays.fill (cirOperandBuffer, 0);
 19892:     cirOperandLength = 0;
 19893:     cirOperandIndex = 0;
 19894:     cirStage = CIR_IDLE;
 19895:   }  //cirIdle(int)
 19896: 
 19897:   //cirException (response)
 19898:   //  例外発生
 19899:   //  プロトコル違反以外はsave CIRをリードしてアイドルステートフレームを保存するとヌルプリミティブに戻る
 19900:   //  プロトコル違反はcontrol CIRに書き込んで復帰させる
 19901:   //  response CIRに$0000を書き込む方法でも復帰できる
 19902:   //    --------------------------------
 19903:   //    オペランドエラーは次のコマンドをフェッチしたとき発生する
 19904:   //    > cir 00 .
 19905:   //    0802 
 19906:   //    > cir 0a 9800
 19907:   //    > cir 00 ....
 19908:   //    8900 9608 8900 8900 
 19909:   //    > cir 10 00002000 00000000
 19910:   //    > cir 00 ..
 19911:   //    0802 0802 
 19912:   //    > cir 0a 4000
 19913:   //    > cir 00 ..
 19914:   //    D504 8900 
 19915:   //    > cir 18 00000000
 19916:   //    > cir 00 ..
 19917:   //    8900 8900 
 19918:   //    > cir 10 00000000
 19919:   //    > cir 00 ..
 19920:   //    0802 0802 
 19921:   //    > cir 0a 4020
 19922:   //    > cir 00 ..
 19923:   //    D504 8900 
 19924:   //    > cir 18 00000000
 19925:   //    > cir 00 ..
 19926:   //    8900 8900 
 19927:   //    > cir 10 00000000
 19928:   //    > cir 00 .
 19929:   //    0802 
 19930:   //    > cir 00 .
 19931:   //    0802 
 19932:   //    > cir 00 .
 19933:   //    0802 
 19934:   //    > cir 0a 0000
 19935:   //    > cir 00 .
 19936:   //    1C34 
 19937:   //    > cir 06 0000
 19938:   //    > cir 00 ..
 19939:   //    0802 0802 
 19940:   //    --------------------------------
 19941:   //    ゼロ除算は次のコマンドをフェッチしたとき発生する
 19942:   //    fmovem.l #$00000400,#$00000000,fpcr/fpsr
 19943:   //    fmove.l #1,fp0
 19944:   //    fdiv.l #0,fp0
 19945:   //    fmove.x fp0,fp0
 19946:   //    > cir 00 .
 19947:   //    0802 
 19948:   //    > cir 0a 9800
 19949:   //    > cir 00 ....
 19950:   //    8900 9608 8900 8900 
 19951:   //    > cir 10 00000400 00000000
 19952:   //    > cir 00 ..
 19953:   //    0802 0802 
 19954:   //    > cir 0a 4000
 19955:   //    > cir 00 ..
 19956:   //    D504 8900 
 19957:   //    > cir 18 00000000
 19958:   //    > cir 00 ..
 19959:   //    8900 8900 
 19960:   //    > cir 10 00000001
 19961:   //    > cir 00 ..
 19962:   //    0802 0802 
 19963:   //    > cir 0a 4020
 19964:   //    > cir 00 ..
 19965:   //    D504 8900 
 19966:   //    > cir 18 00000000
 19967:   //    > cir 00 ..
 19968:   //    8900 8900 
 19969:   //    > cir 10 00000000
 19970:   //    > cir 00 .
 19971:   //    0802 
 19972:   //    > cir 00 .
 19973:   //    0802 
 19974:   //    > cir 00 .
 19975:   //    0802 
 19976:   //    > cir 0a 0000
 19977:   //    > cir 00 .
 19978:   //    1C32 
 19979:   //    > cir 06 0000
 19980:   //    > cir 00 ..
 19981:   //    0802 0802 
 19982:   //    --------------------------------
 19983:   //    プロトコル違反はFSAVEで復帰できない
 19984:   //    > cir 00 .
 19985:   //    0802 
 19986:   //    > cir 10 .
 19987:   //    9800FFFF 
 19988:   //    > cir 00 .
 19989:   //    1D0D 
 19990:   //    > cir 04 .
 19991:   //    0038 
 19992:   //    > cir 00 .
 19993:   //    1D0D 
 19994:   //    > cir 10 .
 19995:   //    9800FFFF 
 19996:   //    > cir 04 .
 19997:   //    0038 
 19998:   //    > cir 06 0000
 19999:   //    > cir 00 .
 20000:   //    0802 
 20001:   //    --------------------------------
 20002:   //    オペランドエラーはFSAVEで復帰できる
 20003:   //    fmovem.l #$00002000,#$00000000,fpcr/fpsr
 20004:   //    fmove.l #0,fp0
 20005:   //    fdiv.l fp0,fp0
 20006:   //    fmove.x fp0,fp0
 20007:   //    > cir 00 .
 20008:   //    0802 
 20009:   //    > cir 0a 9800
 20010:   //    > cir 00 ....
 20011:   //    8900 9608 8900 8900 
 20012:   //    > cir 10 00002000 00000000
 20013:   //    > cir 00 ..
 20014:   //    0802 0802 
 20015:   //    > cir 0a 4000
 20016:   //    > cir 00 ..
 20017:   //    D504 8900 
 20018:   //    > cir 18 00000000
 20019:   //    > cir 00 ..
 20020:   //    8900 8900 
 20021:   //    > cir 10 00000000
 20022:   //    > cir 00 ..
 20023:   //    0802 0802 
 20024:   //    > cir 0a 0020
 20025:   //    > cir 00 ..
 20026:   //    4900 8900 
 20027:   //    > cir 18 00000000
 20028:   //    > cir 00 ..
 20029:   //    0802 0802 
 20030:   //    > cir 0a 0000
 20031:   //    > cir 00 ..
 20032:   //    1C34 1C34 
 20033:   //    > cir 04 .
 20034:   //    1F38 
 20035:   //    > cir 00 ..
 20036:   //    1C34 1C34 
 20037:   //    > cir 10 ..............
 20038:   //    340EFFFF 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 0F000000 00200000 4F800000 00000020 
 20039:   //    > cir 00 ..
 20040:   //    0802 0802 
 20041:   //    > cir 04 .
 20042:   //    1F38 
 20043:   //    > cir 10 ..............
 20044:   //    7C0EFFFF 00000020 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 0F000000 00200000 00000000 00000020 
 20045:   //    > cir 00 ..
 20046:   //    0802 0802 
 20047:   //    --------------------------------
 20048:   //    FRESTOREに失敗したら$B704というマニュアルに書かれていないレスポンスプリミティブが出てきた
 20049:   //    > cir 00 .
 20050:   //    0802 
 20051:   //    > cir 0a 4000
 20052:   //    > cir 00 ....
 20053:   //    9504 8900 8900 8900 
 20054:   //    > cir 04 .
 20055:   //    1FD4 
 20056:   //    > cir 10 .....................................................
 20057:   //    4C0CFFFF 00000020 40000840 4FFFC000 40000000 3F800000 12C00000 12C00000 12C00000 12C00000 12C00000 00000800 00000000 00000000 00000000 00080000 00000000 00000000 0FFFC000 00000000 00000000 3243F6A8 885A308D 30000000 00080000 00000000 00000000 00010000 4FFFC000 3FFFFFFF FFFFFFFF C0000000 40034000 3D5C0000 00000000 00000000 BFFF4000 3243F6A8 885A308D 40000000 30000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 0F000000 40000000 0F800000 4000FFFF 
 20058:   //    > cir 00 ..
 20059:   //    0802 0802 
 20060:   //    > cir 0a 4080
 20061:   //    > cir 00 ....
 20062:   //    9504 8900 8900 8900 
 20063:   //    > cir 10 00000081
 20064:   //    > cir 00 ..
 20065:   //    0802 0802 
 20066:   //    > cir 06 1FD4
 20067:   //    > cir 00 ..
 20068:   //    0900 0900 
 20069:   //    > cir 10 4C0CFFFF 00000020 40000840 4FFFC000 40000000 3F800000 12C00000 12C00000 12C00000 12C00000 12C00000 00000800 00000000 00000000 00000000 00080000 00000000 00000000 0FFFC000 00000000 00000000 3243F6A8 885A308D 30000000 00080000 00000000 00000000 00010000 4FFFC000 3FFFFFFF FFFFFFFF C0000000 40034000 3D5C0000 00000000 00000000 BFFF4000 3243F6A8 885A308D 40000000 30000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 0F000000 40000000 0F800000 4000FFFF
 20070:   //    > cir 00 ..
 20071:   //    0900 0900 
 20072:   //    > cir 10 00000000
 20073:   //    > cir 00 ..
 20074:   //    0900 0900 
 20075:   //    > cir 10 00000000
 20076:   //    > cir 00 ..
 20077:   //    0900 0900 
 20078:   //    > cir 10 0 0 0 0 0 0 0 0 0 0
 20079:   //    > cir 00 ..
 20080:   //    0900 0900 
 20081:   //    > cir 10 0 0 0 0 0 0 0 0 0 0
 20082:   //    > cir 00 ..
 20083:   //    0900 0900 
 20084:   //    > cir 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 20085:   //    ここでバスエラーが出た
 20086:   //    > cir 00 ..
 20087:   //    B704 8900 
 20088:   //    --------------------------------
 20089:   public void cirException (int response) {
 20090:     if (CIR_DEBUG_TRACE) {
 20091:       System.out.printf ("%08x cirException(0x%08x)\n", XEiJ.regPC0, response);
 20092:     }
 20093:     cirResponse = response;
 20094:     cirOperationWord = 0;
 20095:     cirCommand = 0;
 20096:     cirRegisterList = 0;
 20097:     cirOperandAddress = 0;
 20098:     Arrays.fill (cirOperandBuffer, 0);
 20099:     cirOperandLength = 0;
 20100:     cirOperandIndex = 0;
 20101:     cirStage = CIR_EXCEPTION_PROCESSING;
 20102:   }  //cirException(int)
 20103: 
 20104:   //d = cirPeekByteZero (a)
 20105:   //  ピークバイトゼロ拡張
 20106:   public int cirPeekByteZero (int a) {
 20107:     return (a & 1) == 0 ? cirPeekWordZero (a) >>> 8 : cirPeekWordZero (a - 1) & 255;
 20108:   }  //cirPeekByteZero(int)
 20109: 
 20110:   //d = cirPeekWordZero (a)
 20111:   //  ピークワードゼロ拡張
 20112:   public int cirPeekWordZero (int a) {
 20113:     a &= 0x1e;  //bit0は無視される
 20114:     int d = 65535;
 20115:     switch (a) {
 20116:     case 0x00:  //response
 20117:       d = (char) cirResponse;  //下位ワードを出力する
 20118:       break;
 20119:       //case 0x02:  //control
 20120:     case 0x04:  //save
 20121:       if ((cirStage == CIR_EXCEPTION_PROCESSING && cirResponse == 0x1d0d) ||  //プロトコル違反はFSAVEで復帰できない
 20122:           cirStage == CIR_FSAVE_STATE_FRAME ||
 20123:           cirStage == CIR_FRESTORE_STATE_FRAME) {  //FSAVE/FRESTOREの動作中はFSAVE/FRESTOREできない
 20124:         d = 0x0200;
 20125:         //プロトコル違反
 20126:       } else {
 20127:         if ((cirStage & (CIR_INPUT_MASK | CIR_OUTPUT_MASK)) == 0) {  //オペランドバッファを使わない段階
 20128:           d = 0x1f38;  //アイドルステート。0x38/4=56バイト/4=14ロング
 20129:         } else {  //オペランドバッファを使う段階
 20130:           d = 0x1fd4;  //ビジーステート。0xd4/4=212バイト/4=53ロング
 20131:         }
 20132:       }
 20133:       break;
 20134:     case 0x06:  //restore
 20135:       d = (char) cirFormatWord;
 20136:       break;
 20137:     case 0x08:  //operation word
 20138:       d = (char) cirOperationWord;
 20139:       break;
 20140:       //case 0x0a:  //command
 20141:       //case 0x0c:  //(reserved)
 20142:       //reserved CIRのアクセスはプロトコル違反にならない
 20143:       //case 0x0e:  //condition
 20144:     case 0x10 + 0:  //operand CIRの上位ワード
 20145:       //fmove.w fp0,<ea>で使う
 20146:       d = cirPeekLong (a) >>> 16;
 20147:       break;
 20148:     case 0x10 + 2:  //operand CIRの下位ワード
 20149:       d = (char) cirPeekLong (a + 2);
 20150:       break;
 20151:     case 0x14:  //register select
 20152:       if (cirStage == CIR_REGISTER_SELECT) {
 20153:         //  複数レジスタ転送プリミティブの直後に1回だけ有効
 20154:         //  上位バイトにレジスタリストが示される
 20155:         //  MPUは1の数を数えて転送するデータの長さを確定する
 20156:         //  ビットの並び順(どのデータがどのレジスタに格納されるか)はMPUが把握する必要はない
 20157:         d = cirRegisterList << 8;
 20158:       } else {
 20159:         //プロトコル違反
 20160:       }
 20161:       break;
 20162:       //case 0x16:  //(reserved)
 20163:       //reserved CIRのアクセスはプロトコル違反にならない
 20164:       //case 0x18:  //instruction address
 20165:       //case 0x1c:  //operand address
 20166:     case 0x1c + 0:  //operand address CIRの上位ワード
 20167:       d = cirPeekLong (a) >>> 16;
 20168:       break;
 20169:     case 0x1c + 2:  //operand address CIRの下位ワード
 20170:       d = (char) cirPeekLong (a - 2);
 20171:       break;
 20172:     }
 20173:     return d;
 20174:   }  //cirPeekWordZero(int)
 20175: 
 20176:   //d = cirPeekLong (a)
 20177:   //  ピークロング
 20178:   public int cirPeekLong (int a) {
 20179:     a &= 0x1e;  //bit0は無視される
 20180:     int d = -1;
 20181:     switch (a) {
 20182:       //case 0x00:  //response
 20183:       //case 0x02:  //control
 20184:       //case 0x04:  //save
 20185:       //case 0x06:  //restore
 20186:       //case 0x08:  //operation word
 20187:       //case 0x0a:  //command
 20188:       //case 0x0c:  //(reserved)
 20189:       //reserved CIRのアクセスはプロトコル違反にならない
 20190:       //case 0x0e:  //condition
 20191:     case 0x10:  //operand
 20192:       if (cirStage == CIR_DESTINATION_OPERAND && cirOperandIndex < cirOperandLength) {  //デスティネーションオペランドの出力中
 20193:         d = cirOperandBuffer[cirOperandIndex];
 20194:       } else if (cirStage == CIR_FSAVE_STATE_FRAME && cirOperandIndex < cirOperandLength) {  //FSAVEのステートフレームの出力中
 20195:         d = cirOperandBuffer[cirOperandLength - cirOperandIndex - 1];  //FSAVEのステートフレームはロング単位で逆順に出力する
 20196:       } else {  //オペランドが準備されていないのに読み出そうとした
 20197:         //!!! プロトコル違反のとき最後に出力した値が返る
 20198:         //プロトコル違反
 20199:       }
 20200:       break;
 20201:       //case 0x14:  //register select
 20202:       //case 0x16:  //(reserved)
 20203:       //reserved CIRのアクセスはプロトコル違反にならない
 20204:       //case 0x18:  //instruction address
 20205:     case 0x1c:  //operand address
 20206:       d = cirOperandAddress;
 20207:       break;
 20208:     }
 20209:     return d;
 20210:   }  //cirPeekLong(int)
 20211: 
 20212:   //d = cirReadByteZero (a)
 20213:   //  リードバイトゼロ拡張
 20214:   public int cirReadByteZero (int a) {
 20215:     //リードすると状態が変化してしまうので半分だけリードできてもあまり意味がない
 20216:     return (a & 1) == 0 ? cirReadWordZero (a) >>> 8 : cirReadWordZero (a - 1) & 255;
 20217:   }  //cirReadByteZero(int)
 20218: 
 20219:   //d = cirReadWordZero (a)
 20220:   //  リードワードゼロ拡張
 20221:   public int cirReadWordZero (int a) {
 20222:     a &= 0x1e;  //bit0は無視される
 20223:     int d = 65535;
 20224:     switch (a) {
 20225:     case 0x00:  //response
 20226:       d = (char) cirResponse;  //下位ワードを出力する
 20227:       if (d != cirResponse) {  //上位ワードが0でないとき
 20228:         cirResponse >>>= 16;  //次回から上位ワードを出力する
 20229:         if (d == 0x0802) {  //null
 20230:           cirIdle (0x0802);
 20231:         }
 20232:       }
 20233:       break;
 20234:       //case 0x02:  //control
 20235:     case 0x04:  //save
 20236:       if ((cirStage == CIR_EXCEPTION_PROCESSING && cirResponse == 0x1d0d) ||  //プロトコル違反はFSAVEで復帰できない
 20237:           cirStage == CIR_FSAVE_STATE_FRAME ||
 20238:           cirStage == CIR_FRESTORE_STATE_FRAME) {  //FSAVE/FRESTOREの動作中はFSAVE/FRESTOREできない
 20239:         d = 0x0200;
 20240:         cirException (0x1d0d);  //プロトコル違反
 20241:       } else {
 20242:         int i;
 20243:         if ((cirStage & (CIR_INPUT_MASK | CIR_OUTPUT_MASK)) == 0) {  //オペランドバッファを使わない段階
 20244:           d = 0x1f38;  //アイドルステート。0x38/4=56バイト/4=14ロング
 20245:           i = 0;
 20246:         } else {  //オペランドバッファを使う段階
 20247:           d = 0x1fd4;  //ビジーステート。0xd4/4=212バイト/4=53ロング
 20248:           i = 3 * 8;  //オペランドが12バイト*8/4=24ロングあるのでその後
 20249:         }
 20250:         //FSAVEとFRESTOREのステートフレームの構造が同じになるように注意すること
 20251:         cirOperandBuffer[i++] = epbFpcr;
 20252:         cirOperandBuffer[i++] = epbFpsr;
 20253:         cirOperandBuffer[i++] = epbFpiar;
 20254:         cirOperandBuffer[i++] = epbQuotient;
 20255:         cirOperandBuffer[i++] = epbRoundingPrec;
 20256:         cirOperandBuffer[i++] = epbRoundingMode;
 20257:         cirOperandBuffer[i++] = cirResponse;
 20258:         cirOperandBuffer[i++] = cirFormatWord;
 20259:         cirOperandBuffer[i++] = cirOperationWord;
 20260:         cirOperandBuffer[i++] = cirCommand;
 20261:         cirOperandBuffer[i++] = cirRegisterList;
 20262:         cirOperandBuffer[i++] = cirOperandAddress;
 20263:         cirOperandBuffer[i++] = cirOperandLength;
 20264:         cirOperandBuffer[i++] = cirOperandIndex;
 20265:         cirOperandBuffer[i++] = cirStage;
 20266:         cirFormatWord = d;
 20267:         cirOperandLength = (d & 255) >>> 2;
 20268:         cirOperandIndex = 0;
 20269:         cirStage = CIR_FSAVE_STATE_FRAME;
 20270:         cirResponse = 0x0900;
 20271:       }
 20272:       break;
 20273:     case 0x06:  //restore
 20274:       d = (char) cirFormatWord;
 20275:       break;
 20276:     case 0x08:  //operation word
 20277:       d = (char) cirOperationWord;
 20278:       break;
 20279:       //case 0x0a:  //command
 20280:       //case 0x0c:  //(reserved)
 20281:       //reserved CIRのアクセスはプロトコル違反にならない
 20282:       //case 0x0e:  //condition
 20283:     case 0x10 + 0:  //operand CIRの上位ワード
 20284:       //fmove.w fp0,<ea>で使う
 20285:       d = cirReadLong (a) >>> 16;
 20286:       break;
 20287:     case 0x10 + 2:  //operand CIRの下位ワード
 20288:       d = (char) cirReadLong (a + 2);
 20289:       break;
 20290:     case 0x14:  //register select
 20291:       if (cirStage == CIR_REGISTER_SELECT) {
 20292:         //  複数レジスタ転送プリミティブの直後に1回だけ有効
 20293:         //  上位バイトにレジスタリストが示される
 20294:         //  MPUは1の数を数えて転送するデータの長さを確定する
 20295:         //  ビットの並び順(どのデータがどのレジスタに格納されるか)はMPUが把握する必要はない
 20296:         d = cirRegisterList << 8;
 20297:         cirGen ();
 20298:       } else {
 20299:         cirException (0x1d0d);  //プロトコル違反
 20300:       }
 20301:       break;
 20302:       //case 0x16:  //(reserved)
 20303:       //reserved CIRのアクセスはプロトコル違反にならない
 20304:       //case 0x18:  //instruction address
 20305:       //case 0x1c:  //operand address
 20306:     case 0x1c + 0:  //operand address CIRの上位ワード
 20307:       d = cirReadLong (a) >>> 16;
 20308:       break;
 20309:     case 0x1c + 2:  //operand address CIRの下位ワード
 20310:       d = (char) cirReadLong (a - 2);
 20311:       break;
 20312:     }
 20313:     if (CIR_DEBUG_TRACE) {
 20314:       System.out.printf ("%08x cirReadWordZero(0x%08x,0x%04x)\n", XEiJ.regPC0, a, d);
 20315:     }
 20316:     return d;
 20317:   }  //cirReadWordZero(int)
 20318: 
 20319:   //d = cirReadLong (a)
 20320:   //  リードロング
 20321:   public int cirReadLong (int a) {
 20322:     a &= 0x1e;  //bit0は無視される
 20323:     int d = -1;
 20324:     switch (a) {
 20325:       //case 0x00:  //response
 20326:       //case 0x02:  //control
 20327:       //case 0x04:  //save
 20328:       //case 0x06:  //restore
 20329:       //case 0x08:  //operation word
 20330:       //case 0x0a:  //command
 20331:       //case 0x0c:  //(reserved)
 20332:       //reserved CIRのアクセスはプロトコル違反にならない
 20333:       //case 0x0e:  //condition
 20334:     case 0x10:  //operand
 20335:       if (cirStage == CIR_DESTINATION_OPERAND && cirOperandIndex < cirOperandLength) {  //デスティネーションオペランドの出力中
 20336:         d = cirOperandBuffer[cirOperandIndex];
 20337:         cirOperandIndex++;
 20338:         if (cirOperandIndex == cirOperandLength) {  //転送終了
 20339:           cirGen ();
 20340:         }
 20341:       } else if (cirStage == CIR_FSAVE_STATE_FRAME && cirOperandIndex < cirOperandLength) {  //FSAVEのステートフレームの出力中
 20342:         d = cirOperandBuffer[cirOperandLength - cirOperandIndex - 1];  //FSAVEのステートフレームはロング単位で逆順に出力する
 20343:         cirOperandIndex++;
 20344:         if (cirOperandIndex == cirOperandLength) {  //転送終了
 20345:           cirIdle (0x0802);
 20346:         }
 20347:       } else {  //オペランドが準備されていないのに読み出そうとした
 20348:         //!!! プロトコル違反のとき最後に出力した値が返る
 20349:         cirException (0x1d0d);  //プロトコル違反
 20350:       }
 20351:       break;
 20352:       //case 0x14:  //register select
 20353:       //case 0x16:  //(reserved)
 20354:       //reserved CIRのアクセスはプロトコル違反にならない
 20355:       //case 0x18:  //instruction address
 20356:       //case 0x1c:  //operand address
 20357:     case 0x1c:  //operand address
 20358:       d = cirOperandAddress;
 20359:       break;
 20360:     }
 20361:     if (CIR_DEBUG_TRACE) {
 20362:       System.out.printf ("%08x cirReadLong(0x%08x,0x%08x)\n", XEiJ.regPC0, a, d);
 20363:     }
 20364:     return d;
 20365:   }  //cirReadLong(int)
 20366: 
 20367:   //cirWriteByte (a, d)
 20368:   //  ライトバイト
 20369:   public void cirWriteByte (int a, int d) {
 20370:   }  //cirWriteByte(int,int)
 20371: 
 20372:   //cirWriteWord (a, d)
 20373:   //  ライドワード
 20374:   public void cirWriteWord (int a, int d) {
 20375:     if (CIR_DEBUG_TRACE) {
 20376:       System.out.printf ("%08x cirWriteWordZero(0x%08x,0x%04x)\n", XEiJ.regPC0, a, d);
 20377:     }
 20378:     d &= 65535;
 20379:     switch (a & 0x1e) {  //bit0は無視される
 20380:       //case 0x00:  //response
 20381:     case 0x02:  //control
 20382:       //MC68881はデータに関係なくアボート
 20383:       //MC68882はbit0(AB abort)に1を書き込むとアボート、bit1(XA exception acknowledge)に1を書き込むと例外クリア
 20384:       //ここでは例外が発生していればデータに関係なく例外クリア、さもなくばbit0に1を書き込んだときアボートとする
 20385:       if (cirStage == CIR_EXCEPTION_PROCESSING) {  //例外が発生している
 20386:         cirIdle (0x0802);  //例外クリア
 20387:         return;
 20388:       } else if ((d & 1) != 0) {  //bit0に1を書き込んだ
 20389:         cirIdle (0x0802);  //アボート
 20390:         return;
 20391:       }
 20392:       break;
 20393:       //case 0x04:  //save
 20394:     case 0x06:  //restore
 20395:       if (d >>> 8 == 0) {  //ヌルステート
 20396:         cirFormatWord = d;
 20397:         //fp0-fp7はすべてNon-signaling NaNになる
 20398:         for (int n = 0; n < 8; n++) {
 20399:           epbFPn[n].setnan ();
 20400:         }
 20401:         //FPCRとFPSRはゼロクリアされる
 20402:         epbFpcr = 0;
 20403:         epbFpsr = 0;
 20404:         cirIdle (0x0802);
 20405:       } else if (d == 0x1f38 || d == 0x1fd4) {
 20406:         cirFormatWord = d;
 20407:         cirOperandLength = (d & 255) >>> 2;
 20408:         cirOperandIndex = 0;
 20409:         cirStage = CIR_FRESTORE_STATE_FRAME;
 20410:         cirResponse = 0x0900;
 20411:       } else {
 20412:         cirFormatWord = 0x0200;
 20413:       }
 20414:       return;
 20415:     case 0x08:  //operation word
 20416:       //MC68881のときwriteは無視、readは-1
 20417:       //MC68882のときF-line命令を書き込む。FPCPは使わない
 20418:       cirOperationWord = d;
 20419:       return;
 20420:     case 0x0a:  //command
 20421:       if (cirStage == CIR_IDLE) {
 20422:         cirCommand = d;
 20423:         cirGen ();
 20424:         return;
 20425:       }
 20426:       break;
 20427:     case 0x0c:  //(reserved)
 20428:       //reserved CIRのアクセスはプロトコル違反にならない
 20429:       return;
 20430:     case 0x0e:  //condition
 20431:       //!!! 命令の実行中に条件判断を要求されたときは命令の処理が終わってから条件判断を行う
 20432:       if (cirStage == CIR_IDLE) {
 20433:         d &= 0x3f;
 20434:         if ((d & 0x20) != 0 && (epbFpsr & XEiJ.FPU_FPSR_NAN) != 0) {  //IEEEノンアウェアテストでNANがセットされているとき
 20435:           epbFpsr |= XEiJ.FPU_FPSR_EXC_BSUN;  //BSUNをセット
 20436:           epbFpsr |= XEiJ.FPU_FPSR_EXC_TO_AEXC[epbFpsr >> 8 & 255];
 20437:           if ((epbFpcr & XEiJ.FPU_FPCR_BSUN) != 0) {  //BSUN例外許可
 20438:             cirException (0x5c30);  //BSUN
 20439:             return;
 20440:           }
 20441:         }
 20442:         cirResponse = XEiJ.FPU_CCMAP_882[d << 4 | epbFpsr >> 24 & 15] ? 0x0802_0801 : 0x0802_0800;
 20443:         return;
 20444:       }
 20445:       break;
 20446:       //case 0x10:  //operand
 20447:       //case 0x14:  //register select
 20448:     case 0x16:  //(reserved)
 20449:       //reserved CIRのアクセスはプロトコル違反にならない
 20450:       return;
 20451:       //case 0x18:  //instruction address
 20452:       //case 0x1c:  //operand address
 20453:     }
 20454:     cirException (0x1d0d);  //プロトコル違反
 20455:   }  //cirWriteWord(int,int)
 20456: 
 20457:   //cirWriteLong (a, d)
 20458:   //  ライドロング
 20459:   public void cirWriteLong (int a, int d) {
 20460:     if (CIR_DEBUG_TRACE) {
 20461:       System.out.printf ("%08x cirWriteLongZero(0x%08x,0x%08x)\n", XEiJ.regPC0, a, d);
 20462:     }
 20463:     switch (a & 0x1e) {  //bit0は無視される
 20464:       //case 0x00:  //response
 20465:       //case 0x02:  //control
 20466:       //case 0x04:  //save
 20467:       //case 0x06:  //restore
 20468:       //case 0x08:  //operation word
 20469:       //case 0x0a:  //command
 20470:     case 0x0c:  //(reserved)
 20471:       //reserved CIRのアクセスはプロトコル違反にならない
 20472:       return;
 20473:       //case 0x0e:  //condition
 20474:     case 0x10:  //operand
 20475:       if ((cirStage & CIR_INPUT_MASK) != 0 && cirOperandIndex < cirOperandLength) {
 20476:         cirOperandBuffer[cirOperandIndex++] = d;
 20477:         if (cirOperandIndex == cirOperandLength) {  //転送終了
 20478:           if (cirStage == CIR_DYNAMIC_K_FACTOR ||
 20479:               cirStage == CIR_DYNAMIC_REGISTER_LIST ||
 20480:               cirStage == CIR_SOURCE_OPERAND) {
 20481:             cirGen ();
 20482:           } else if (cirStage == CIR_FRESTORE_STATE_FRAME) {
 20483:             int i = cirFormatWord == 0x1f38 ? 0 : 3 * 8;
 20484:             //FSAVEとFRESTOREのステートフレームの構造が同じになるように注意すること
 20485:             epbFpcr = cirOperandBuffer[i++] & EPB_FPCR_ALL;
 20486:             epbFpsr = cirOperandBuffer[i++] & EPB_FPSR_ALL;
 20487:             epbFpiar = cirOperandBuffer[i++];
 20488:             epbQuotient = cirOperandBuffer[i++];
 20489:             epbRoundingPrec = cirOperandBuffer[i++];
 20490:             epbRoundingMode = cirOperandBuffer[i++];
 20491:             cirResponse = cirOperandBuffer[i++];
 20492:             cirFormatWord = cirOperandBuffer[i++];
 20493:             cirOperationWord = cirOperandBuffer[i++];
 20494:             cirCommand = cirOperandBuffer[i++];
 20495:             cirRegisterList = cirOperandBuffer[i++];
 20496:             cirOperandAddress = cirOperandBuffer[i++];
 20497:             cirOperandLength = cirOperandBuffer[i++];
 20498:             cirOperandIndex = cirOperandBuffer[i++];
 20499:             cirStage = cirOperandBuffer[i++];
 20500:           }
 20501:         }
 20502:         return;
 20503:       }
 20504:       break;
 20505:       //case 0x14:  //register select
 20506:     case 0x16:  //(reserved)
 20507:       //reserved CIRのアクセスはプロトコル違反にならない
 20508:       return;
 20509:     case 0x18:  //instruction address
 20510:       if (cirStage == CIR_PROGRAM_COUNTER) {
 20511:         //FMOVEM/FMOVE FPcr/FSAVE/FRESTORE以外の命令でFPCRのException Enable Byte(bit15-8)が0でないときデータ転送プリミティブのPC(bit14)がセットされる
 20512:         //データ転送プリミティブのPC(bit14)がセットされているときデータ転送の前にinstruction address CIRにPCを書き込まないとプロトコル違反になる
 20513:         epbFpiar = d;
 20514:         cirGen ();
 20515:         return;
 20516:       }
 20517:       break;
 20518:     case 0x1c:  //operand address
 20519:       cirOperandAddress = d;
 20520:       break;
 20521:     }
 20522:     cirException (0x1d0d);  //プロトコル違反
 20523:   }  //cirWriteLong(int,int)
 20524: 
 20525: 
 20526:   //cirGen ()
 20527:   //  一般命令の処理
 20528:   //  コマンドを開始するときと転送が終了したときに呼び出される
 20529:   //  cirStageがCIR_IDLEのときは最初から、それ以外は途中から処理する
 20530:   @SuppressWarnings ("fallthrough") public void cirGen () {
 20531:     if (CIR_DEBUG_TRACE) {
 20532:       System.out.printf ("%08x cirGen(command=0x%04x,stage=%d(%s))\n", XEiJ.regPC0, cirCommand, cirStage, cirNameOfStage[cirStage & 15]);
 20533:     }
 20534: 
 20535:     //  111111
 20536:     //  5432109876543210
 20537:     //  hhhmmmnnnccccccc
 20538:     int mmm = cirCommand >> 10 & 7;  //ソースオペランド
 20539:     int nnn = cirCommand >> 7 & 7;  //デスティネーションオペランド
 20540:     int ccccccc = cirCommand & 0x7f;
 20541: 
 20542: 
 20543:     switch (cirCommand >> 13) {
 20544: 
 20545: 
 20546:     case 0b010:  //$4xxx-$5xxx: Fop.* <ea>,FPn
 20547:       if (cirStage == CIR_IDLE) {  //開始
 20548:         epbFpsr &= 0x00ff00ff;
 20549:         epbSetRoundingPrec (epbFpcr >> 6 & 3);  //丸め桁数
 20550:         epbSetRoundingMode (epbFpcr >> 4 & 3);  //丸めモード
 20551:       }
 20552: 
 20553:       switch (mmm) {
 20554: 
 20555:       case 0b000:  //$40xx-$43xx: Fop.L <ea>,FPn
 20556:         //    --------------------------------
 20557:         //    > cir 00 .
 20558:         //    0802 
 20559:         //    > cir 0a 4000
 20560:         //    > cir 00 ...
 20561:         //    9504 8900 8900 
 20562:         //    > cir 10 00000001
 20563:         //    > cir 00 ..
 20564:         //    0802 0802 
 20565:         //    --------------------------------
 20566:         if (cirStage == CIR_IDLE) {  //開始
 20567:           if ((epbFpcr & 0x0000ff00) != 0) {  //例外処理あり
 20568:             cirResponse = 0x8900_d504;  //PCを入力する→ロングのデータを入力する→come-again
 20569:             cirStage = CIR_PROGRAM_COUNTER;  //PC転送開始
 20570:           } else {
 20571:             cirResponse = 0x8900_9504;  //ロングのデータを入力する→come-again
 20572:             cirOperandLength = 1;
 20573:             cirOperandIndex = 0;
 20574:             cirStage = CIR_SOURCE_OPERAND;  //ソースオペランド転送開始
 20575:           }
 20576:           return;
 20577:         }
 20578:         if (cirStage == CIR_PROGRAM_COUNTER) {  //PC転送終了
 20579:           cirOperandLength = 1;
 20580:           cirOperandIndex = 0;
 20581:           cirStage = CIR_SOURCE_OPERAND;  //ソースオペランド転送開始
 20582:           return;
 20583:         }
 20584:         if (cirStage == CIR_SOURCE_OPERAND) {  //ソースオペランド転送終了
 20585:           epbFPn[mmm = EPB_SRC_TMP].seti (cirOperandBuffer[0]);
 20586:           if (cirPreInstruction ()) {
 20587:             return;
 20588:           }
 20589:         }
 20590:         break;
 20591: 
 20592:       case 0b001:  //$44xx-$47xx: Fop.S <ea>,FPn
 20593:         //    --------------------------------
 20594:         //    > cir 00 .
 20595:         //    0802 
 20596:         //    > cir 0a 4400
 20597:         //    > cir 00 ...
 20598:         //    1504 8900 8900 
 20599:         //    > cir 10 00000000
 20600:         //    > cir 00 ..
 20601:         //    0802 0802 
 20602:         //    --------------------------------
 20603:         if (cirStage == CIR_IDLE) {  //開始
 20604:           if ((epbFpcr & 0x0000ff00) != 0) {  //例外処理あり
 20605:             if ((epbMode & EPB_MODE_MC68882) != 0) {  //MC68882
 20606:               cirResponse = 0x8900_5504;  //PCを入力する→シングルのデータを入力する→come-again
 20607:             } else {  //MC68881
 20608:               cirResponse = 0x8900_d504;  //PCを入力する→シングルのデータを入力する→come-again
 20609:             }
 20610:             cirStage = CIR_PROGRAM_COUNTER;  //PC転送開始
 20611:           } else {
 20612:             if ((epbMode & EPB_MODE_MC68882) != 0) {  //MC68882
 20613:               cirResponse = 0x8900_1504;  //シングルのデータを入力する→come-again
 20614:             } else {  //MC68881
 20615:               cirResponse = 0x8900_9504;  //シングルのデータを入力する→come-again
 20616:             }
 20617:             cirOperandLength = 1;
 20618:             cirOperandIndex = 0;
 20619:             cirStage = CIR_SOURCE_OPERAND;  //ソースオペランド転送開始
 20620:           }
 20621:           return;
 20622:         }
 20623:         if (cirStage == CIR_PROGRAM_COUNTER) {  //PC転送終了
 20624:           cirOperandLength = 1;
 20625:           cirOperandIndex = 0;
 20626:           cirStage = CIR_SOURCE_OPERAND;  //ソースオペランド転送開始
 20627:           return;
 20628:         }
 20629:         if (cirStage == CIR_SOURCE_OPERAND) {  //ソースオペランド転送終了
 20630:           epbFPn[mmm = EPB_SRC_TMP].setf0 (cirOperandBuffer[0]);
 20631:           if (cirPreInstruction ()) {
 20632:             return;
 20633:           }
 20634:         }
 20635:         break;
 20636: 
 20637:       case 0b010:  //$48xx-$4Bxx: Fop.X <ea>,FPn
 20638:         //    --------------------------------
 20639:         //    > cir 00 .
 20640:         //    0802 
 20641:         //    > cir 0a 4800
 20642:         //    > cir 00 ...
 20643:         //    160C 8900 8900 
 20644:         //    > cir 10 00000000
 20645:         //    > cir 00 ..
 20646:         //    8900 8900 
 20647:         //    > cir 10 00000000
 20648:         //    > cir 00 ..
 20649:         //    8900 8900 
 20650:         //    > cir 10 00000000
 20651:         //    > cir 00 ..
 20652:         //    0802 0802 
 20653:         //    --------------------------------
 20654:         if (cirStage == CIR_IDLE) {  //開始
 20655:           if ((epbFpcr & 0x0000ff00) != 0) {  //例外処理あり
 20656:             if ((epbMode & EPB_MODE_MC68882) != 0) {  //MC68882
 20657:               cirResponse = 0x8900_560c;  //PCを入力する→エクステンデッドのデータを入力する→come-again
 20658:             } else {  //MC68881
 20659:               cirResponse = 0x8900_d60c;  //PCを入力する→エクステンデッドのデータを入力する→come-again
 20660:             }
 20661:             cirStage = CIR_PROGRAM_COUNTER;  //PC転送開始
 20662:           } else {
 20663:             if ((epbMode & EPB_MODE_MC68882) != 0) {  //MC68882
 20664:               cirResponse = 0x8900_160c;  //エクステンデッドのデータを入力する→come-again
 20665:             } else {  //MC68881
 20666:               cirResponse = 0x8900_960c;  //エクステンデッドのデータを入力する→come-again
 20667:             }
 20668:             cirOperandLength = 3;
 20669:             cirOperandIndex = 0;
 20670:             cirStage = CIR_SOURCE_OPERAND;  //ソースオペランド転送開始
 20671:           }
 20672:           return;
 20673:         }
 20674:         if (cirStage == CIR_PROGRAM_COUNTER) {  //PC転送終了
 20675:           cirOperandLength = 3;
 20676:           cirOperandIndex = 0;
 20677:           cirStage = CIR_SOURCE_OPERAND;  //ソースオペランド転送開始
 20678:           return;
 20679:         }
 20680:         if (cirStage == CIR_SOURCE_OPERAND) {  //ソースオペランド転送終了
 20681:           if (epbIsTriple ()) {  //三倍精度
 20682:             epbFPn[mmm = EPB_SRC_TMP].sety012 (cirOperandBuffer[0], (long) cirOperandBuffer[1] << 32 | cirOperandBuffer[2] & 0xffffffffL);
 20683:           } else {  //拡張精度
 20684:             epbFPn[mmm = EPB_SRC_TMP].setx012 (cirOperandBuffer[0], (long) cirOperandBuffer[1] << 32 | cirOperandBuffer[2] & 0xffffffffL);
 20685:           }
 20686:           if (cirPreInstruction ()) {
 20687:             return;
 20688:           }
 20689:         }
 20690:         break;
 20691: 
 20692:       case 0b011:  //$4Cxx-$4Fxx: Fop.P <ea>,FPn
 20693:         //    --------------------------------
 20694:         //    > cir 00 .
 20695:         //    0802 
 20696:         //    > cir 0a 4c00
 20697:         //    > cir 00 ....
 20698:         //    8900 960C 8900 8900 
 20699:         //    > cir 10 00000000
 20700:         //    > cir 00 ..
 20701:         //    8900 8900 
 20702:         //    > cir 10 00000000
 20703:         //    > cir 00 ..
 20704:         //    8900 8900 
 20705:         //    > cir 10 00000000
 20706:         //    > cir 00 ..
 20707:         //    0802 0802 
 20708:         //    --------------------------------
 20709:         if (cirStage == CIR_IDLE) {  //開始
 20710:           if ((epbFpcr & 0x0000ff00) != 0) {  //例外処理あり
 20711:             cirResponse = 0x8900_d60c;  //PCを入力する→パックトのデータを入力する→come-again
 20712:             cirStage = CIR_PROGRAM_COUNTER;  //PC転送開始
 20713:           } else {
 20714:             cirResponse = 0x8900_960c;  //パックトのデータを入力する→come-again
 20715:             cirOperandLength = 3;
 20716:             cirOperandIndex = 0;
 20717:             cirStage = CIR_SOURCE_OPERAND;  //ソースオペランド転送開始
 20718:           }
 20719:           return;
 20720:         }
 20721:         if (cirStage == CIR_PROGRAM_COUNTER) {  //PC転送終了
 20722:           cirOperandLength = 3;
 20723:           cirOperandIndex = 0;
 20724:           cirStage = CIR_SOURCE_OPERAND;  //ソースオペランド転送開始
 20725:           return;
 20726:         }
 20727:         if (cirStage == CIR_SOURCE_OPERAND) {  //ソースオペランド転送終了
 20728:           epbFPn[mmm = EPB_SRC_TMP].setp012 (cirOperandBuffer[0], (long) cirOperandBuffer[1] << 32 | cirOperandBuffer[2] & 0xffffffffL);
 20729:           if (cirPreInstruction ()) {
 20730:             return;
 20731:           }
 20732:         }
 20733:         break;
 20734: 
 20735:       case 0b100:  //$50xx-$53xx: Fop.W <ea>,FPn
 20736:         //    --------------------------------
 20737:         //    > cir 00 .
 20738:         //    0802 
 20739:         //    > cir 0a 5000
 20740:         //    > cir 00 ...
 20741:         //    9502 8900 8900 
 20742:         //    > cir 10 00010002
 20743:         //    > cir 00 ..
 20744:         //    0802 0802 
 20745:         //    > cir 0a 6000
 20746:         //    > cir 00 ...
 20747:         //    8900 B104 0802 
 20748:         //    > cir 10 .
 20749:         //    00000001 
 20750:         //    > cir 00 ..
 20751:         //    0802 0802 
 20752:         //    --------------------------------
 20753:         if (cirStage == CIR_IDLE) {  //開始
 20754:           if ((epbFpcr & 0x0000ff00) != 0) {  //例外処理あり
 20755:             cirResponse = 0x8900_d502;  //PCを入力する→ワードのデータを入力する→come-again
 20756:             cirStage = CIR_PROGRAM_COUNTER;  //PC転送開始
 20757:           } else {
 20758:             cirResponse = 0x8900_9502;  //ワードのデータを入力する→come-again
 20759:             cirOperandLength = 1;
 20760:             cirOperandIndex = 0;
 20761:             cirStage = CIR_SOURCE_OPERAND;  //ソースオペランド転送開始
 20762:           }
 20763:           return;
 20764:         }
 20765:         if (cirStage == CIR_PROGRAM_COUNTER) {  //PC転送終了
 20766:           cirOperandLength = 1;
 20767:           cirOperandIndex = 0;
 20768:           cirStage = CIR_SOURCE_OPERAND;  //ソースオペランド転送開始
 20769:           return;
 20770:         }
 20771:         if (cirStage == CIR_SOURCE_OPERAND) {  //ソースオペランド転送終了
 20772:           epbFPn[mmm = EPB_SRC_TMP].seti (cirOperandBuffer[0] >> 16);  //左詰めになっている
 20773:           if (cirPreInstruction ()) {
 20774:             return;
 20775:           }
 20776:         }
 20777:         break;
 20778: 
 20779:       case 0b101:  //$54xx-$57xx: Fop.D <ea>,FPn
 20780:         //    --------------------------------
 20781:         //    > cir 00 .
 20782:         //    0802 
 20783:         //    > cir 0a 5400
 20784:         //    > cir 00 ...
 20785:         //    1608 8900 8900 
 20786:         //    > cir 10 00000000
 20787:         //    > cir 00 ..
 20788:         //    8900 8900 
 20789:         //    > cir 10 00000000
 20790:         //    > cir 00 ..
 20791:         //    0802 0802 
 20792:         //    --------------------------------
 20793:         if (cirStage == CIR_IDLE) {  //開始
 20794:           if ((epbFpcr & 0x0000ff00) != 0) {  //例外処理あり
 20795:             if ((epbMode & EPB_MODE_MC68882) != 0) {  //MC68882
 20796:               cirResponse = 0x8900_5608;  //PCを入力する→ダブルのデータを入力する→come-again
 20797:             } else {  //MC68881
 20798:               cirResponse = 0x8900_d608;  //PCを入力する→ダブルのデータを入力する→come-again
 20799:             }
 20800:             cirStage = CIR_PROGRAM_COUNTER;  //PC転送開始
 20801:           } else {
 20802:             if ((epbMode & EPB_MODE_MC68882) != 0) {  //MC68882
 20803:               cirResponse = 0x8900_1608;  //ダブルのデータを入力する→come-again
 20804:             } else {  //MC68881
 20805:               cirResponse = 0x8900_9608;  //ダブルのデータを入力する→come-again
 20806:             }
 20807:             cirOperandLength = 2;
 20808:             cirOperandIndex = 0;
 20809:             cirStage = CIR_SOURCE_OPERAND;  //ソースオペランド転送開始
 20810:           }
 20811:           return;
 20812:         }
 20813:         if (cirStage == CIR_PROGRAM_COUNTER) {  //PC転送終了
 20814:           cirOperandLength = 2;
 20815:           cirOperandIndex = 0;
 20816:           cirStage = CIR_SOURCE_OPERAND;  //ソースオペランド転送開始
 20817:           return;
 20818:         }
 20819:         if (cirStage == CIR_SOURCE_OPERAND) {  //ソースオペランド転送終了
 20820:           epbFPn[mmm = EPB_SRC_TMP].setd01 ((long) cirOperandBuffer[0] << 32 | cirOperandBuffer[1] & 0xffffffffL);
 20821:           if (cirPreInstruction ()) {
 20822:             return;
 20823:           }
 20824:         }
 20825:         break;
 20826: 
 20827:       case 0b110:  //$58xx-$5Bxx: Fop.B <ea>,FPn
 20828:         //    --------------------------------
 20829:         //    > cir 00 .
 20830:         //    0802 
 20831:         //    > cir 0a 5800
 20832:         //    > cir 00 ...
 20833:         //    9501 8900 8900 
 20834:         //    > cir 10 01020304
 20835:         //    > cir 00 ..
 20836:         //    0802 0802 
 20837:         //    > cir 0a 6000
 20838:         //    > cir 00 ...
 20839:         //    8900 B104 0802 
 20840:         //    > cir 10 .
 20841:         //    00000001 
 20842:         //    > cir 00 ..
 20843:         //    0802 0802 
 20844:         //    --------------------------------
 20845:         if (cirStage == CIR_IDLE) {  //開始
 20846:           if ((epbFpcr & 0x0000ff00) != 0) {  //例外処理あり
 20847:             cirResponse = 0x8900_d501;  //バイトのデータを入力する→come-again
 20848:             cirStage = CIR_PROGRAM_COUNTER;  //PC転送開始
 20849:           } else {
 20850:             cirResponse = 0x8900_9501;  //バイトのデータを入力する→come-again
 20851:             cirOperandLength = 1;
 20852:             cirOperandIndex = 0;
 20853:             cirStage = CIR_SOURCE_OPERAND;  //ソースオペランド転送開始
 20854:           }
 20855:           return;
 20856:         }
 20857:         if (cirStage == CIR_PROGRAM_COUNTER) {  //PC転送終了
 20858:           cirOperandLength = 1;
 20859:           cirOperandIndex = 0;
 20860:           cirStage = CIR_SOURCE_OPERAND;  //ソースオペランド転送開始
 20861:           return;
 20862:         }
 20863:         if (cirStage == CIR_SOURCE_OPERAND) {  //ソースオペランド転送終了
 20864:           epbFPn[mmm = EPB_SRC_TMP].seti (cirOperandBuffer[0] >> 24);  //左詰めになっている
 20865:           if (cirPreInstruction ()) {
 20866:             return;
 20867:           }
 20868:         }
 20869:         break;
 20870: 
 20871:       case 0b111:  //$5Cxx-$5Fxx: FMOVECR.X #ccc,FPn
 20872:         //    --------------------------------
 20873:         //    > cir 00 .
 20874:         //    0802 
 20875:         //    > cir 0a 5c00
 20876:         //    > cir 00 ..
 20877:         //    0900 0802 
 20878:         //    > cir 0a 6800
 20879:         //    > cir 00 ....
 20880:         //    8900 320C 8900 8900 
 20881:         //    > cir 10 .
 20882:         //    40000000 
 20883:         //    > cir 00 ..
 20884:         //    8900 8900 
 20885:         //    > cir 10 .
 20886:         //    C90FDAA2 
 20887:         //    > cir 00 ..
 20888:         //    0802 0802 
 20889:         //    > cir 10 .
 20890:         //    2168C235 
 20891:         //    > cir 00 ..
 20892:         //    0802 0802 
 20893:         //    --------------------------------
 20894:       default:
 20895:         if (0x40 <= ccccccc) {
 20896:           //マニュアルにはFMOVECRの命令フォーマットのROMオフセットが7bitあるように書かれているが実際は6bit
 20897:           //MC68882で0x40以上を指定すると命令実行前例外のF-line emulator(レスポンスプリミティブ0x1c0b)が返る
 20898:           cirException (0x1c0b);  //F-line emulator
 20899:           return;
 20900:         }
 20901:         if (false) {
 20902:           mmm = EPB_CONST_START + ccccccc;  //ソースオペランドをROMに変更する
 20903:           ccccccc = 0;  //命令をFMOVEに変更する
 20904:         } else {
 20905:           //FMOVECR
 20906:           epbFmovecr (epbFPn[nnn], ccccccc);
 20907:           if (cirMidInstruction ()) {
 20908:             return;
 20909:           }
 20910:           //終了
 20911:           cirIdle (0x0802);
 20912:           return;
 20913:         }
 20914: 
 20915:       }
 20916:       //Fop.X <ea>,FPn → Fop.X FP[EPB_SRC_TMP],FPn
 20917:       //FMOVECR.X #ccc,FPn → FMOVE.X FPc,FPn
 20918: 
 20919: 
 20920:       //fallthrough
 20921:     case 0b000:  //$0xxx-$1xxx: Fop.X FPm,FPn
 20922:       if (cirStage == CIR_IDLE) {  //開始
 20923:         epbFpsr &= 0x00ff00ff;
 20924:       }
 20925: 
 20926:       switch (ccccccc) {
 20927: 
 20928:       case 0b000_0000:  //$xx00: FMOVE.* *m,FPn
 20929:         //    --------------------------------
 20930:         //    > cir 00 .
 20931:         //    0802 
 20932:         //    > cir 0a 4000
 20933:         //    > cir 00 ...
 20934:         //    9504 8900 8900 
 20935:         //    > cir 10 00000001
 20936:         //    > cir 00 ..
 20937:         //    0802 0802 
 20938:         //    > cir 0a 0000
 20939:         //    > cir 00 ...
 20940:         //    0900 0802 0802 
 20941:         //    --------------------------------
 20942:         //  BSUN   常にクリア
 20943:         //  SNAN   引数がシグナリングNaNのときセット、それ以外はクリア
 20944:         //  OPERR  常にクリア
 20945:         //  OVFL   常にクリア
 20946:         //  UNFL   結果が非正規化数のときセット、それ以外はクリア
 20947:         //  DZ     常にクリア
 20948:         //  INEX2  結果に誤差があるときセット、それ以外はクリア
 20949:         //  INEX1  引数がpackedで正確に変換できないときセット、それ以外はクリア
 20950:         epbFPn[nnn].sete (epbFPn[mmm]).finish ();
 20951:         break;
 20952: 
 20953:       case 0b000_0001:  //$xx01: FINT.* *m,FPn
 20954:         //    --------------------------------
 20955:         //    > cir 00 .
 20956:         //    0802 
 20957:         //    > cir 0a 4000
 20958:         //    > cir 00 ...
 20959:         //    9504 8900 8900 
 20960:         //    > cir 10 00000001
 20961:         //    > cir 00 ..
 20962:         //    0802 0802 
 20963:         //    > cir 0a 0001
 20964:         //    > cir 00 ...
 20965:         //    0900 0802 0802 
 20966:         //    --------------------------------
 20967:         //  BSUN   常にクリア
 20968:         //  SNAN   引数がシグナリングNaNのときセット、それ以外はクリア
 20969:         //  OPERR  常にクリア
 20970:         //  OVFL   常にクリア
 20971:         //         正規化数の最大値は整数なので丸めても大きくなることはない
 20972:         //  UNFL   常にクリア
 20973:         //         結果は整数なので非正規化数にはならない
 20974:         //  DZ     常にクリア
 20975:         //  INEX2  結果に誤差があるときセット、それ以外はクリア
 20976:         //  INEX1  引数がpackedで正確に変換できないときセット、それ以外はクリア
 20977:         //  FINTはsingleとdoubleの丸め処理を行わない
 20978:         epbSetRoundingPrec (EPB_PREC_EXD);
 20979:         epbFPn[nnn].round (epbFPn[mmm], epbRoundingMode);
 20980:         break;
 20981: 
 20982:       case 0b000_0010:  //$xx02: FSINH.* *m,FPn
 20983:         //    --------------------------------
 20984:         //    > cir 00 .
 20985:         //    0802 
 20986:         //    > cir 0a 4000
 20987:         //    > cir 00 ...
 20988:         //    9504 8900 8900 
 20989:         //    > cir 10 00000001
 20990:         //    > cir 00 ..
 20991:         //    0802 0802 
 20992:         //    > cir 0a 0002
 20993:         //    > cir 00 ...
 20994:         //    0900 0802 0802 
 20995:         //    --------------------------------
 20996:         //  BSUN   常にクリア
 20997:         //  SNAN   引数がシグナリングNaNのときセット、それ以外はクリア
 20998:         //  OPERR  常にクリア
 20999:         //  OVFL   オーバーフローしたときセット、それ以外はクリア
 21000:         //  UNFL   結果が非正規化数のときセット、それ以外はクリア
 21001:         //  DZ     常にクリア
 21002:         //  INEX2  結果に誤差があるときセット、それ以外はクリア
 21003:         //  INEX1  引数がpackedで正確に変換できないときセット、それ以外はクリア
 21004:         epbFPn[nnn].sinh (epbFPn[mmm]);
 21005:         break;
 21006: 
 21007:       case 0b000_0011:  //$xx03: FINTRZ.* *m,FPn
 21008:         //  BSUN   常にクリア
 21009:         //  SNAN   引数がシグナリングNaNのときセット、それ以外はクリア
 21010:         //  OPERR  常にクリア
 21011:         //  OVFL   常にクリア
 21012:         //  UNFL   常にクリア
 21013:         //         結果は整数なので非正規化数にはならない
 21014:         //  DZ     常にクリア
 21015:         //  INEX2  結果に誤差があるときセット、それ以外はクリア
 21016:         //  INEX1  引数がpackedで正確に変換できないときセット、それ以外はクリア
 21017:         //  FINTRZはsingleとdoubleの丸め処理を行わない
 21018:         epbSetRoundingPrec (EPB_PREC_EXD);
 21019:         epbFPn[nnn].trunc (epbFPn[mmm]);
 21020:         break;
 21021: 
 21022:       case 0b000_0100:  //$xx04: FSQRT.* *m,FPn
 21023:       case 0b000_0101:  //$xx05: FSQRT.* *m,FPn (MC68882)
 21024:         //  BSUN   常にクリア
 21025:         //  SNAN   引数がシグナリングNaNのときセット、それ以外はクリア
 21026:         //  OPERR  引数が-0を除く負数のときセット、それ以外はクリア
 21027:         //  OVFL   常にクリア
 21028:         //         1よりも大きい数は小さくなるので溢れることはない
 21029:         //  UNFL   常にクリア
 21030:         //         非正規化数の平方根は正規化数なので結果が非正規化数になることはない
 21031:         //  DZ     常にクリア
 21032:         //  INEX2  結果に誤差があるときセット、それ以外はクリア
 21033:         //  INEX1  引数がpackedで正確に変換できないときセット、それ以外はクリア
 21034:         epbFPn[nnn].sqrt (epbFPn[mmm]);
 21035:         break;
 21036: 
 21037:       case 0b000_0110:  //$xx06: FLOGNP1.* *m,FPn
 21038:       case 0b000_0111:  //$xx07: FLOGNP1.* *m,FPn (MC68882)
 21039:         //  BSUN   常にクリア
 21040:         //  SNAN   引数がシグナリングNaNのときセット、それ以外はクリア
 21041:         //  OPERR  引数が-1よりも小さいときセット、それ以外はクリア
 21042:         //  OVFL   常にクリア
 21043:         //         log(1+0)=0,log(1+x)<=xなので結果が引数よりも大きくなることはない
 21044:         //  UNFL   結果が非正規化数のときセット、それ以外はクリア
 21045:         //  DZ     引数が-1のときセット、それ以外はクリア
 21046:         //  INEX2  結果に誤差があるときセット、それ以外はクリア
 21047:         //  INEX1  引数がpackedで正確に変換できないときセット、それ以外はクリア
 21048:         epbFPn[nnn].log1p (epbFPn[mmm]);
 21049:         break;
 21050: 
 21051:       case 0b000_1000:  //$xx08: FETOXM1.* *m,FPn
 21052:         //  BSUN   常にクリア
 21053:         //  SNAN   引数がシグナリングNaNのときセット、それ以外はクリア
 21054:         //  OPERR  常にクリア
 21055:         //  OVFL   オーバーフローしたときセット、それ以外はクリア
 21056:         //  UNFL   結果が非正規化数のときセット、それ以外はクリア
 21057:         //  DZ     常にクリア
 21058:         //  INEX2  結果に誤差があるときセット、それ以外はクリア
 21059:         //  INEX1  引数がpackedで正確に変換できないときセット、それ以外はクリア
 21060:         epbFPn[nnn].expm1 (epbFPn[mmm]);
 21061:         break;
 21062: 
 21063:       case 0b000_1001:  //$xx09: FTANH.* *m,FPn
 21064:         //  BSUN   常にクリア
 21065:         //  SNAN   引数がシグナリングNaNのときセット、それ以外はクリア
 21066:         //  OPERR  常にクリア
 21067:         //  OVFL   常にクリア
 21068:         //  UNFL   結果が非正規化数のときセット、それ以外はクリア
 21069:         //  DZ     常にクリア
 21070:         //  INEX2  結果に誤差があるときセット、それ以外はクリア
 21071:         //  INEX1  引数がpackedで正確に変換できないときセット、それ以外はクリア
 21072:         epbFPn[nnn].tanh (epbFPn[mmm]);
 21073:         break;
 21074: 
 21075:       case 0b000_1010:  //$xx0A: FATAN.* *m,FPn
 21076:       case 0b000_1011:  //$xx0B: FATAN.* *m,FPn (MC68882)
 21077:         //  BSUN   常にクリア
 21078:         //  SNAN   引数がシグナリングNaNのときセット、それ以外はクリア
 21079:         //  OPERR  常にクリア
 21080:         //  OVFL   常にクリア
 21081:         //  UNFL   結果が非正規化数のときセット、それ以外はクリア
 21082:         //  DZ     常にクリア
 21083:         //  INEX2  結果に誤差があるときセット、それ以外はクリア
 21084:         //  INEX1  引数がpackedで正確に変換できないときセット、それ以外はクリア
 21085:         epbFPn[nnn].atan (epbFPn[mmm]);
 21086:         break;
 21087: 
 21088:       case 0b000_1100:  //$xx0C: FASIN.* *m,FPn
 21089:         //  BSUN   常にクリア
 21090:         //  SNAN   引数がシグナリングNaNのときセット、それ以外はクリア
 21091:         //  OPERR  引数の絶対値が1よりも大きいときセット、それ以外はクリア
 21092:         //  OVFL   常にクリア
 21093:         //  UNFL   結果が非正規化数のときセット、それ以外はクリア
 21094:         //  DZ     常にクリア
 21095:         //  INEX2  結果に誤差があるときセット、それ以外はクリア
 21096:         //  INEX1  引数がpackedで正確に変換できないときセット、それ以外はクリア
 21097:         epbFPn[nnn].asin (epbFPn[mmm]);
 21098:         break;
 21099: 
 21100:       case 0b000_1101:  //$xx0D: FATANH.* *m,FPn
 21101:         //  BSUN   常にクリア
 21102:         //  SNAN   引数がシグナリングNaNのときセット、それ以外はクリア
 21103:         //  OPERR  引数の絶対値が1よりも大きいときセット、それ以外はクリア
 21104:         //  OVFL   常にクリア
 21105:         //         1のとき無限大なのだから1の近くでオーバーフローしそうに思えるがatanh(1-2^-80)≒28.07くらい
 21106:         //  UNFL   結果が非正規化数のときセット、それ以外はクリア
 21107:         //  DZ     引数の絶対値が1のときセット、それ以外はクリア
 21108:         //  INEX2  結果に誤差があるときセット、それ以外はクリア
 21109:         //  INEX1  引数がpackedで正確に変換できないときセット、それ以外はクリア
 21110:         epbFPn[nnn].atanh (epbFPn[mmm]);
 21111:         break;
 21112: 
 21113:       case 0b000_1110:  //$xx0E: FSIN.* *m,FPn
 21114:         //  BSUN   常にクリア
 21115:         //  SNAN   引数がシグナリングNaNのときセット、それ以外はクリア
 21116:         //  OPERR  引数が無限大のときセット、それ以外はクリア
 21117:         //  OVFL   常にクリア
 21118:         //  UNFL   結果が非正規化数のときセット、それ以外はクリア
 21119:         //  DZ     常にクリア
 21120:         //  INEX2  結果に誤差があるときセット、それ以外はクリア
 21121:         //  INEX1  引数がpackedで正確に変換できないときセット、それ以外はクリア
 21122:         epbFPn[nnn].sin (epbFPn[mmm]);
 21123:         break;
 21124: 
 21125:       case 0b000_1111:  //$xx0F: FTAN.* *m,FPn
 21126:         //  BSUN   常にクリア
 21127:         //  SNAN   引数がシグナリングNaNのときセット、それ以外はクリア
 21128:         //  OPERR  引数が無限大のときセット、それ以外はクリア
 21129:         //  OVFL   オーバーフローしたときセット、それ以外はクリア
 21130:         //  UNFL   結果が非正規化数のときセット、それ以外はクリア
 21131:         //  DZ     常にクリア
 21132:         //         cos(x)=0を満たすxは正確に表現できないのだからsin(x)/cos(x)がゼロ除算になるのはおかしい
 21133:         //  INEX2  結果に誤差があるときセット、それ以外はクリア
 21134:         //  INEX1  引数がpackedで正確に変換できないときセット、それ以外はクリア
 21135:         epbFPn[nnn].tan (epbFPn[mmm]);
 21136:         break;
 21137: 
 21138:       case 0b001_0000:  //$xx10: FETOX.* *m,FPn
 21139:         //  BSUN   常にクリア
 21140:         //  SNAN   引数がシグナリングNaNのときセット、それ以外はクリア
 21141:         //  OPERR  常にクリア
 21142:         //  OVFL   オーバーフローしたときセット、それ以外はクリア
 21143:         //  UNFL   結果が非正規化数のときセット、それ以外はクリア
 21144:         //  DZ     常にクリア
 21145:         //  INEX2  結果に誤差があるときセット、それ以外はクリア
 21146:         //  INEX1  引数がpackedで正確に変換できないときセット、それ以外はクリア
 21147:         epbFPn[nnn].exp (epbFPn[mmm]);
 21148:         break;
 21149: 
 21150:       case 0b001_0001:  //$xx11: FTWOTOX.* *m,FPn
 21151:         //  BSUN   常にクリア
 21152:         //  SNAN   引数がシグナリングNaNのときセット、それ以外はクリア
 21153:         //  OPERR  常にクリア
 21154:         //  OVFL   オーバーフローしたときセット、それ以外はクリア
 21155:         //  UNFL   結果が非正規化数のときセット、それ以外はクリア
 21156:         //  DZ     常にクリア
 21157:         //  INEX2  結果に誤差があるときセット、それ以外はクリア
 21158:         //  INEX1  引数がpackedで正確に変換できないときセット、それ以外はクリア
 21159:         epbFPn[nnn].exp2 (epbFPn[mmm]);
 21160:         break;
 21161: 
 21162:       case 0b001_0010:  //$xx12: FTENTOX.* *m,FPn
 21163:       case 0b001_0011:  //$xx13: FTENTOX.* *m,FPn (MC68882)
 21164:         //  BSUN   常にクリア
 21165:         //  SNAN   引数がシグナリングNaNのときセット、それ以外はクリア
 21166:         //  OPERR  常にクリア
 21167:         //  OVFL   オーバーフローしたときセット、それ以外はクリア
 21168:         //  UNFL   結果が非正規化数のときセット、それ以外はクリア
 21169:         //  DZ     常にクリア
 21170:         //  INEX2  結果に誤差があるときセット、それ以外はクリア
 21171:         //  INEX1  引数がpackedで正確に変換できないときセット、それ以外はクリア
 21172:         epbFPn[nnn].exp10 (epbFPn[mmm]);
 21173:         break;
 21174: 
 21175:       case 0b001_0100:  //$xx14: FLOGN.* *m,FPn
 21176:         //  BSUN   常にクリア
 21177:         //  SNAN   引数がシグナリングNaNのときセット、それ以外はクリア
 21178:         //  OPERR  引数が0よりも小さいときセット、それ以外はクリア
 21179:         //  OVFL   常にクリア
 21180:         //         log(1)=0,log(x)<=x-1なので結果が引数よりも大きくなることはない
 21181:         //  UNFL   常にクリア
 21182:         //         log(1+2^-80)≒2^-80
 21183:         //  DZ     引数がゼロのときセット、それ以外はクリア
 21184:         //  INEX2  結果に誤差があるときセット、それ以外はクリア
 21185:         //  INEX1  引数がpackedで正確に変換できないときセット、それ以外はクリア
 21186:         epbFPn[nnn].log (epbFPn[mmm]);
 21187:         break;
 21188: 
 21189:       case 0b001_0101:  //$xx15: FLOG10.* *m,FPn
 21190:         //  BSUN   常にクリア
 21191:         //  SNAN   引数がシグナリングNaNのときセット、それ以外はクリア
 21192:         //  OPERR  引数が0よりも小さいときセット、それ以外はクリア
 21193:         //  OVFL   常にクリア
 21194:         //  UNFL   常にクリア
 21195:         //  DZ     引数がゼロのときセット、それ以外はクリア
 21196:         //  INEX2  結果に誤差があるときセット、それ以外はクリア
 21197:         //  INEX1  引数がpackedで正確に変換できないときセット、それ以外はクリア
 21198:         epbFPn[nnn].log10 (epbFPn[mmm]);
 21199:         break;
 21200: 
 21201:       case 0b001_0110:  //$xx16: FLOG2.* *m,FPn
 21202:       case 0b001_0111:  //$xx17: FLOG2.* *m,FPn (MC68882)
 21203:         //  BSUN   常にクリア
 21204:         //  SNAN   引数がシグナリングNaNのときセット、それ以外はクリア
 21205:         //  OPERR  引数が0よりも小さいときセット、それ以外はクリア
 21206:         //  OVFL   常にクリア
 21207:         //  UNFL   常にクリア
 21208:         //  DZ     引数がゼロのときセット、それ以外はクリア
 21209:         //  INEX2  結果に誤差があるときセット、それ以外はクリア
 21210:         //  INEX1  引数がpackedで正確に変換できないときセット、それ以外はクリア
 21211:         epbFPn[nnn].log2 (epbFPn[mmm]);
 21212:         break;
 21213: 
 21214:       case 0b001_1000:  //$xx18: FABS.* *m,FPn
 21215:         //  BSUN   常にクリア
 21216:         //  SNAN   引数がシグナリングNaNのときセット、それ以外はクリア
 21217:         //  OPERR  常にクリア
 21218:         //  OVFL   常にクリア
 21219:         //  UNFL   結果が非正規化数のときセット、それ以外はクリア
 21220:         //  DZ     常にクリア
 21221:         //  INEX2  常にクリア
 21222:         //  INEX1  引数がpackedで正確に変換できないときセット、それ以外はクリア
 21223:         epbFPn[nnn].abs (epbFPn[mmm]);
 21224:         break;
 21225: 
 21226:       case 0b001_1001:  //$xx19: FCOSH.* *m,FPn
 21227:         //  BSUN   常にクリア
 21228:         //  SNAN   引数がシグナリングNaNのときセット、それ以外はクリア
 21229:         //  OPERR  常にクリア
 21230:         //  OVFL   オーバーフローしたときセット、それ以外はクリア
 21231:         //  UNFL   常にクリア
 21232:         //  DZ     常にクリア
 21233:         //  INEX2  結果に誤差があるときセット、それ以外はクリア
 21234:         //  INEX1  引数がpackedで正確に変換できないときセット、それ以外はクリア
 21235:         epbFPn[nnn].cosh (epbFPn[mmm]);
 21236:         break;
 21237: 
 21238:       case 0b001_1010:  //$xx1A: FNEG.* *m,FPn
 21239:       case 0b001_1011:  //$xx1B: FNEG.* *m,FPn (MC68882)
 21240:         //  BSUN   常にクリア
 21241:         //  SNAN   引数がシグナリングNaNのときセット、それ以外はクリア
 21242:         //  OPERR  常にクリア
 21243:         //  OVFL   常にクリア
 21244:         //  UNFL   結果が非正規化数のときセット、それ以外はクリア
 21245:         //  DZ     常にクリア
 21246:         //  INEX2  常にクリア
 21247:         //  INEX1  引数がpackedで正確に変換できないときセット、それ以外はクリア
 21248:         epbFPn[nnn].neg (epbFPn[mmm]);
 21249:         break;
 21250: 
 21251:       case 0b001_1100:  //$xx1C: FACOS.* *m,FPn
 21252:         //  BSUN   常にクリア
 21253:         //  SNAN   引数がシグナリングNaNのときセット、それ以外はクリア
 21254:         //  OPERR  引数の絶対値が1よりも大きいときセット、それ以外はクリア
 21255:         //  OVFL   常にクリア
 21256:         //  UNFL   常にクリア
 21257:         //         acos(1-ulp(1))はulp(1)よりも大きい
 21258:         //  DZ     常にクリア
 21259:         //  INEX2  結果に誤差があるときセット、それ以外はクリア
 21260:         //         おそらくセットされないのはacos(1)=0だけ
 21261:         //  INEX1  引数がpackedで正確に変換できないときセット、それ以外はクリア
 21262:         epbFPn[nnn].acos (epbFPn[mmm]);
 21263:         break;
 21264: 
 21265:       case 0b001_1101:  //$xx1D: FCOS.* *m,FPn
 21266:         //  BSUN   常にクリア
 21267:         //  SNAN   引数がシグナリングNaNのときセット、それ以外はクリア
 21268:         //  OPERR  引数が無限大のときセット、それ以外はクリア
 21269:         //  OVFL   常にクリア
 21270:         //  UNFL   常にクリア
 21271:         //         cos(x)=0を満たすxは正確に表現できず、cos(pi/2)とcos(3*pi/2)が正規化数になってしまう
 21272:         //  DZ     常にクリア
 21273:         //  INEX2  結果に誤差があるときセット、それ以外はクリア
 21274:         //  INEX1  引数がpackedで正確に変換できないときセット、それ以外はクリア
 21275:         epbFPn[nnn].cos (epbFPn[mmm]);
 21276:         break;
 21277: 
 21278:       case 0b001_1110:  //$xx1E: FGETEXP.* *m,FPn
 21279:         //  BSUN   常にクリア
 21280:         //  SNAN   引数がシグナリングNaNのときセット、それ以外はクリア
 21281:         //  OPERR  引数が無限大のときセット、それ以外はクリア
 21282:         //  OVFL   常にクリア
 21283:         //  UNFL   常にクリア
 21284:         //  DZ     常にクリア
 21285:         //  INEX2  常にクリア
 21286:         //  INEX1  引数がpackedで正確に変換できないときセット、それ以外はクリア
 21287:         epbFPn[nnn].getexp (epbFPn[mmm]);
 21288:         break;
 21289: 
 21290:       case 0b001_1111:  //$xx1F: FGETMAN.* *m,FPn
 21291:         //  BSUN   常にクリア
 21292:         //  SNAN   引数がシグナリングNaNのときセット、それ以外はクリア
 21293:         //  OPERR  引数が無限大のときセット、それ以外はクリア
 21294:         //  OVFL   常にクリア
 21295:         //  UNFL   常にクリア
 21296:         //  DZ     常にクリア
 21297:         //  INEX2  常にクリア
 21298:         //  INEX1  引数がpackedで正確に変換できないときセット、それ以外はクリア
 21299:         epbFPn[nnn].getman (epbFPn[mmm]);
 21300:         break;
 21301: 
 21302:       case 0b010_0000:  //$xx20: FDIV.* *m,FPn
 21303:         //  BSUN   常にクリア
 21304:         //  SNAN   引数がシグナリングNaNのときセット、それ以外はクリア
 21305:         //  OPERR  引数が両方ゼロまたは両方無限大のときセット、それ以外はクリア
 21306:         //  OVFL   オーバーフローしたときセット、それ以外はクリア
 21307:         //  UNFL   結果が非正規化数のときセット、それ以外はクリア
 21308:         //  DZ     被除数がゼロ、無限大、NaN以外で除数がゼロのときセット、それ以外はクリア
 21309:         //  INEX2  結果に誤差があるときセット、それ以外はクリア
 21310:         //  INEX1  引数がpackedで正確に変換できないときセット、それ以外はクリア
 21311:         epbFPn[nnn].div (epbFPn[mmm]);
 21312:         break;
 21313: 
 21314:       case 0b010_0001:  //$xx21: FMOD.* *m,FPn
 21315:         //  BSUN   常にクリア
 21316:         //  SNAN   引数がシグナリングNaNのときセット、それ以外はクリア
 21317:         //  OPERR  除数がゼロまたは被除数が無限大のときセット、それ以外はクリア
 21318:         //  OVFL   常にクリア
 21319:         //  UNFL   結果が非正規化数のときセット、それ以外はクリア
 21320:         //  DZ     常にクリア
 21321:         //         除数がゼロのとき結果は無限大ではなくNaNでありゼロ除算にはならない
 21322:         //  INEX2  結果に誤差があるときセット、それ以外はクリア
 21323:         //  INEX1  引数がpackedで正確に変換できないときセット、それ以外はクリア
 21324:         //  FPSRのquotient byteに符号付き商の下位7bitが入る
 21325:         epbFPn[nnn].rem (epbFPn[mmm]);
 21326:         break;
 21327: 
 21328:       case 0b010_0010:  //$xx22: FADD.* *m,FPn
 21329:         //  BSUN   常にクリア
 21330:         //  SNAN   引数がシグナリングNaNのときセット、それ以外はクリア
 21331:         //  OPERR  引数が両方無限大で符号が異なるときセット、それ以外はクリア
 21332:         //  OVFL   オーバーフローしたときセット、それ以外はクリア
 21333:         //  UNFL   結果が非正規化数のときセット、それ以外はクリア
 21334:         //  DZ     常にクリア
 21335:         //  INEX2  結果に誤差があるときセット、それ以外はクリア
 21336:         //  INEX1  引数がpackedで正確に変換できないときセット、それ以外はクリア
 21337:         epbFPn[nnn].add (epbFPn[mmm]);
 21338:         break;
 21339: 
 21340:       case 0b010_0011:  //$xx23: FMUL.* *m,FPn
 21341:         //  BSUN   常にクリア
 21342:         //  SNAN   引数がシグナリングNaNのときセット、それ以外はクリア
 21343:         //  OPERR  引数の一方がゼロで他方が無限大のときセット、それ以外はクリア
 21344:         //  OVFL   オーバーフローしたときセット、それ以外はクリア
 21345:         //  UNFL   結果が非正規化数のときセット、それ以外はクリア
 21346:         //  DZ     常にクリア
 21347:         //  INEX2  結果に誤差があるときセット、それ以外はクリア
 21348:         //  INEX1  引数がpackedで正確に変換できないときセット、それ以外はクリア
 21349:         epbFPn[nnn].mul (epbFPn[mmm]);
 21350:         break;
 21351: 
 21352:       case 0b010_0100:  //$xx24: FSGLDIV.* *m,FPn
 21353:         //  BSUN   常にクリア
 21354:         //  SNAN   引数がシグナリングNaNのときセット、それ以外はクリア
 21355:         //  OPERR  引数が両方ゼロまたは両方無限大のときセット、それ以外はクリア
 21356:         //  OVFL   オーバーフローしたときセット、それ以外はクリア
 21357:         //  UNFL   結果が非正規化数のときセット、それ以外はクリア
 21358:         //  DZ     被除数がゼロ、無限大、NaN以外で除数がゼロのときセット、それ以外はクリア
 21359:         //  INEX2  結果に誤差があるときセット、それ以外はクリア
 21360:         //  INEX1  引数がpackedで正確に変換できないときセット、それ以外はクリア
 21361:         epbSetRoundingPrec (EPB_PREC_XSG);
 21362:         epbFPn[nnn].div (epbFPn[mmm]);
 21363:         break;
 21364: 
 21365:       case 0b010_0101:  //$xx25: FREM.* *m,FPn
 21366:         //  BSUN   常にクリア
 21367:         //  SNAN   引数がシグナリングNaNのときセット、それ以外はクリア
 21368:         //  OPERR  除数がゼロまたは被除数が無限大のときセット、それ以外はクリア
 21369:         //  OVFL   常にクリア
 21370:         //  UNFL   結果が非正規化数のときセット、それ以外はクリア
 21371:         //  DZ     常にクリア
 21372:         //         除数がゼロのとき結果は無限大ではなくNaNでありゼロ除算にはならない
 21373:         //  INEX2  結果に誤差があるときセット、それ以外はクリア
 21374:         //         マニュアルにClearedと書いてあるのは間違い
 21375:         //         除数が無限大で被除数をそのまま返す場合でもサイズが減ればアンダーフローや不正確な結果になることはマニュアルにも書かれている
 21376:         //  INEX1  引数がpackedで正確に変換できないときセット、それ以外はクリア
 21377:         //  FPSRのquotient byteに符号付き商の下位7bitが入る
 21378:         epbFPn[nnn].ieeerem (epbFPn[mmm]);
 21379:         break;
 21380: 
 21381:       case 0b010_0110:  //$xx26: FSCALE.* *m,FPn
 21382:         //  BSUN   常にクリア
 21383:         //  SNAN   引数がシグナリングNaNのときセット、それ以外はクリア
 21384:         //  OPERR  引数が無限大のときセット、それ以外はクリア
 21385:         //  OVFL   オーバーフローしたときセット、それ以外はクリア
 21386:         //  UNFL   結果が非正規化数のときセット、それ以外はクリア
 21387:         //  DZ     常にクリア
 21388:         //  INEX2  常にクリア
 21389:         //  INEX1  引数がpackedで正確に変換できないときセット、それ以外はクリア
 21390:         //! 本来はソースが整数のとき浮動小数点数を経由しないが、これは経由してしまっている。結果は同じだが効率が悪い
 21391:         epbFPn[nnn].scale (epbFPn[mmm]);
 21392:         break;
 21393: 
 21394:       case 0b010_0111:  //$xx27: FSGLMUL.* *m,FPn
 21395:         //  BSUN   常にクリア
 21396:         //  SNAN   引数がシグナリングNaNのときセット、それ以外はクリア
 21397:         //  OPERR  引数の一方がゼロで他方が無限大のときセット、それ以外はクリア
 21398:         //  OVFL   オーバーフローしたときセット、それ以外はクリア
 21399:         //  UNFL   結果が非正規化数のときセット、それ以外はクリア
 21400:         //  DZ     常にクリア
 21401:         //  INEX2  結果に誤差があるときセット、それ以外はクリア
 21402:         //  INEX1  引数がpackedで正確に変換できないときセット、それ以外はクリア
 21403:         {
 21404:           //引数を24bitに切り捨てるときX2をセットしない
 21405:           int sr = epbFpsr;
 21406:           epbFPn[EPB_SRC_TMP].roundmanf (epbFPn[mmm], EPB_MODE_RZ);
 21407:           epbFPn[EPB_DST_TMP].roundmanf (epbFPn[nnn], EPB_MODE_RZ);
 21408:           epbFpsr = sr;
 21409:         }
 21410:         epbSetRoundingPrec (EPB_PREC_XSG);
 21411:         epbFPn[nnn].mul (epbFPn[EPB_DST_TMP], epbFPn[EPB_SRC_TMP]);
 21412:         break;
 21413: 
 21414:       case 0b010_1000:  //$xx28: FSUB.* *m,FPn
 21415:       case 0b010_1001:  //$xx29: FSUB.* *m,FPn (MC68882)
 21416:       case 0b010_1010:  //$xx2A: FSUB.* *m,FPn (MC68882)
 21417:       case 0b010_1011:  //$xx2B: FSUB.* *m,FPn (MC68882)
 21418:       case 0b010_1100:  //$xx2C: FSUB.* *m,FPn (MC68882)
 21419:       case 0b010_1101:  //$xx2D: FSUB.* *m,FPn (MC68882)
 21420:       case 0b010_1110:  //$xx2E: FSUB.* *m,FPn (MC68882)
 21421:       case 0b010_1111:  //$xx2F: FSUB.* *m,FPn (MC68882)
 21422:         //  BSUN   常にクリア
 21423:         //  SNAN   引数がシグナリングNaNのときセット、それ以外はクリア
 21424:         //  OPERR  引数が両方無限大で符号が同じときセット、それ以外はクリア
 21425:         //  OVFL   オーバーフローしたときセット、それ以外はクリア
 21426:         //  UNFL   結果が非正規化数のときセット、それ以外はクリア
 21427:         //  DZ     常にクリア
 21428:         //  INEX2  結果に誤差があるときセット、それ以外はクリア
 21429:         //  INEX1  引数がpackedで正確に変換できないときセット、それ以外はクリア
 21430:         epbFPn[nnn].sub (epbFPn[mmm]);
 21431:         break;
 21432: 
 21433:       case 0b011_0000:  //$xx30: FSINCOS.* *m,FP0:FPn (c=0,s=n)
 21434:       case 0b011_0001:  //$xx31: FSINCOS.* *m,FP1:FPn (c=1,s=n)
 21435:       case 0b011_0010:  //$xx32: FSINCOS.* *m,FP2:FPn (c=2,s=n)
 21436:       case 0b011_0011:  //$xx33: FSINCOS.* *m,FP3:FPn (c=3,s=n)
 21437:       case 0b011_0100:  //$xx34: FSINCOS.* *m,FP4:FPn (c=4,s=n)
 21438:       case 0b011_0101:  //$xx35: FSINCOS.* *m,FP5:FPn (c=5,s=n)
 21439:       case 0b011_0110:  //$xx36: FSINCOS.* *m,FP6:FPn (c=6,s=n)
 21440:       case 0b011_0111:  //$xx37: FSINCOS.* *m,FP7:FPn (c=7,s=n)
 21441:         //  BSUN   常にクリア
 21442:         //  SNAN   引数がシグナリングNaNのときセット、それ以外はクリア
 21443:         //  OPERR  引数が無限大のときセット、それ以外はクリア
 21444:         //  OVFL   常にクリア
 21445:         //  UNFL   sin(x)の結果が非正規化数のときセット、それ以外はクリア
 21446:         //         cos(x)の結果は非正規化数にならない
 21447:         //  DZ     常にクリア
 21448:         //  INEX2  結果に誤差があるときセット、それ以外はクリア
 21449:         //  INEX1  引数がpackedで正確に変換できないときセット、それ以外はクリア
 21450:         {
 21451:           int ccc = ccccccc & 7;
 21452:           //mmm==EPB_SRC_TMP||mmm==nnn||mmm==cccの場合があることに注意する
 21453:           epbFPn[EPB_SRC_TMP].sete (epbFPn[mmm]);
 21454:           epbFPn[ccc].cos (epbFPn[EPB_SRC_TMP]);
 21455:           epbFPn[nnn].sin (epbFPn[EPB_SRC_TMP]);
 21456:         }
 21457:         break;
 21458: 
 21459:       case 0b011_1000:  //$xx38: FCMP.* *m,FPn
 21460:       case 0b011_1001:  //$xx39: FCMP.* *m,FPn (MC68882)
 21461:       case 0b011_1100:  //$xx3C: FCMP.* *m,FPn (MC68882)  コマンドワードの不連続箇所に注意
 21462:       case 0b011_1101:  //$xx3D: FCMP.* *m,FPn (MC68882)
 21463:         //  BSUN   常にクリア
 21464:         //  SNAN   引数がシグナリングNaNのときセット、それ以外はクリア
 21465:         //  OPERR  常にクリア
 21466:         //  OVFL   常にクリア
 21467:         //  UNFL   常にクリア
 21468:         //  DZ     常にクリア
 21469:         //  INEX2  常にクリア
 21470:         //  INEX1  引数がpackedで正確に変換できないときセット、それ以外はクリア
 21471:         //  FCMPはinfinityを常にクリアする
 21472:         //  efp.compareTo(x,y)を使う
 21473:         //    efp.compareTo(x,y)はefp.sub(x,y)よりも速い
 21474:         //    efp.sub(x,y)はINEX2をセットしてしまう
 21475:         //  efp.compareTo(x,y)は-0<+0だがFCMPは-0==+0なのでこれだけ調節する
 21476:         {
 21477:           int xf = epbFPn[nnn].flg;
 21478:           int yf = epbFPn[mmm].flg;
 21479:           if ((xf | yf) << 3 < 0) {  //どちらかがNaN
 21480:             //epbFPn[EPB_DST_TMP].setnan ();
 21481:             epbFPn[EPB_DST_TMP].flg = N;
 21482:           } else {
 21483:             int i = ((xf & yf) << 1 < 0 ? 0 :  //両方±0
 21484:                      epbFPn[nnn].compareTo (epbFPn[mmm]));  //-Inf==-Inf<-x<-0<+0<+x<+Inf==+Inf<NaN==NaN
 21485:             if (i == 0) {
 21486:               if (xf < 0) {
 21487:                 //epbFPn[EPB_DST_TMP].negset0 ();
 21488:                 epbFPn[EPB_DST_TMP].flg = M | Z;
 21489:               } else {
 21490:                 //epbFPn[EPB_DST_TMP].set0 ();
 21491:                 epbFPn[EPB_DST_TMP].flg = P | Z;
 21492:               }
 21493:             } else if (i < 0) {
 21494:               epbFPn[EPB_DST_TMP].negset1 ();
 21495:             } else {
 21496:               epbFPn[EPB_DST_TMP].set1 ();
 21497:             }
 21498:           }
 21499:           nnn = EPB_DST_TMP;
 21500:         }
 21501:         break;
 21502: 
 21503:       case 0b011_1010:  //$xx3A: FTST.* *m
 21504:       case 0b011_1011:  //$xx3B: FTST.* *m (MC68882)
 21505:       case 0b011_1110:  //$xx3E: FTST.* *m (MC68882)  コマンドワードの不連続箇所に注意
 21506:       case 0b011_1111:  //$xx3F: FTST.* *m (MC68882)
 21507:         //  BSUN   常にクリア
 21508:         //  SNAN   引数がシグナリングNaNのときセット、それ以外はクリア
 21509:         //  OPERR  常にクリア
 21510:         //  OVFL   常にクリア
 21511:         //  UNFL   常にクリア
 21512:         //  DZ     常にクリア
 21513:         //  INEX2  常にクリア
 21514:         //  INEX1  引数がpackedで正確に変換できないときセット、それ以外はクリア
 21515:         //  ソースオペランドをダミーのデスティネーションオペランドにコピーしてテストする
 21516:         //  デスティネーションオペランドは変化しない
 21517:         //  デスティネーションオペランドにはFP0が指定される場合が多いがFP0である必要はない
 21518:         epbFPn[EPB_DST_TMP].sete (epbFPn[mmm]);
 21519:         nnn = EPB_DST_TMP;
 21520:         break;
 21521: 
 21522:       case 0b100_0000:  //$xx40: FSMOVE.* *m,FPn
 21523:         //  BSUN   常にクリア
 21524:         //  SNAN   引数がシグナリングNaNのときセット、それ以外はクリア
 21525:         //  OPERR  常にクリア
 21526:         //  OVFL   常にクリア
 21527:         //  UNFL   結果が非正規化数のときセット、それ以外はクリア
 21528:         //  DZ     常にクリア
 21529:         //  INEX2  結果に誤差があるときセット、それ以外はクリア
 21530:         //  INEX1  引数がpackedで正確に変換できないときセット、それ以外はクリア
 21531:         epbSetRoundingPrec (EPB_PREC_SGL);
 21532:         epbFPn[nnn].sete (epbFPn[mmm]).finish ();
 21533:         break;
 21534: 
 21535:       case 0b100_0001:  //$xx41: FSSQRT.* *m,FPn
 21536:         //  BSUN   常にクリア
 21537:         //  SNAN   引数がシグナリングNaNのときセット、それ以外はクリア
 21538:         //  OPERR  引数が-0を除く負数のときセット、それ以外はクリア
 21539:         //  OVFL   常にクリア
 21540:         //  UNFL   常にクリア
 21541:         //  DZ     常にクリア
 21542:         //  INEX2  結果に誤差があるときセット、それ以外はクリア
 21543:         //  INEX1  引数がpackedで正確に変換できないときセット、それ以外はクリア
 21544:         epbSetRoundingPrec (EPB_PREC_SGL);
 21545:         epbFPn[nnn].sqrt (epbFPn[mmm]);
 21546:         break;
 21547: 
 21548:         //case 0b100_0010:  //$xx42:
 21549:         //case 0b100_0011:  //$xx43:
 21550: 
 21551:       case 0b100_0100:  //$xx44: FDMOVE.* *m,FPn
 21552:         //  BSUN   常にクリア
 21553:         //  SNAN   引数がシグナリングNaNのときセット、それ以外はクリア
 21554:         //  OPERR  常にクリア
 21555:         //  OVFL   常にクリア
 21556:         //  UNFL   結果が非正規化数のときセット、それ以外はクリア
 21557:         //  DZ     常にクリア
 21558:         //  INEX2  結果に誤差があるときセット、それ以外はクリア
 21559:         //  INEX1  引数がpackedで正確に変換できないときセット、それ以外はクリア
 21560:         epbSetRoundingPrec (EPB_PREC_DBL);
 21561:         epbFPn[nnn].sete (epbFPn[mmm]).finish ();
 21562:         break;
 21563: 
 21564:       case 0b100_0101:  //$xx45: FDSQRT.* *m,FPn
 21565:         //  BSUN   常にクリア
 21566:         //  SNAN   引数がシグナリングNaNのときセット、それ以外はクリア
 21567:         //  OPERR  引数が-0を除く負数のときセット、それ以外はクリア
 21568:         //  OVFL   常にクリア
 21569:         //  UNFL   常にクリア
 21570:         //  DZ     常にクリア
 21571:         //  INEX2  結果に誤差があるときセット、それ以外はクリア
 21572:         //  INEX1  引数がpackedで正確に変換できないときセット、それ以外はクリア
 21573:         epbSetRoundingPrec (EPB_PREC_DBL);
 21574:         epbFPn[nnn].sqrt (epbFPn[mmm]);
 21575:         break;
 21576: 
 21577:         //case 0b100_0110:  //$xx46:
 21578:         //case 0b100_0111:  //$xx47:
 21579:         //case 0b100_1000:  //$xx48:
 21580:         //case 0b100_1001:  //$xx49:
 21581:         //case 0b100_1010:  //$xx4A:
 21582:         //case 0b100_1011:  //$xx4B:
 21583:         //case 0b100_1100:  //$xx4C:
 21584:         //case 0b100_1101:  //$xx4D:
 21585:         //case 0b100_1110:  //$xx4E:
 21586:         //case 0b100_1111:  //$xx4F:
 21587:         //case 0b101_0000:  //$xx50:
 21588:         //case 0b101_0001:  //$xx51:
 21589:         //case 0b101_0010:  //$xx52:
 21590:         //case 0b101_0011:  //$xx53:
 21591:         //case 0b101_0100:  //$xx54:
 21592:         //case 0b101_0101:  //$xx55:
 21593:         //case 0b101_0110:  //$xx56:
 21594:         //case 0b101_0111:  //$xx57:
 21595: 
 21596:       case 0b101_1000:  //$xx58: FSABS.* *m,FPn
 21597:         //  BSUN   常にクリア
 21598:         //  SNAN   引数がシグナリングNaNのときセット、それ以外はクリア
 21599:         //  OPERR  常にクリア
 21600:         //  OVFL   常にクリア
 21601:         //  UNFL   結果が非正規化数のときセット、それ以外はクリア
 21602:         //  DZ     常にクリア
 21603:         //  INEX2  常にクリア
 21604:         //  INEX1  引数がpackedで正確に変換できないときセット、それ以外はクリア
 21605:         epbSetRoundingPrec (EPB_PREC_SGL);
 21606:         epbFPn[nnn].abs (epbFPn[mmm]);
 21607:         break;
 21608: 
 21609:         //case 0b101_1001:  //$xx59:
 21610: 
 21611:       case 0b101_1010:  //$xx5A: FSNEG.* *m,FPn
 21612:         //  BSUN   常にクリア
 21613:         //  SNAN   引数がシグナリングNaNのときセット、それ以外はクリア
 21614:         //  OPERR  常にクリア
 21615:         //  OVFL   常にクリア
 21616:         //  UNFL   結果が非正規化数のときセット、それ以外はクリア
 21617:         //  DZ     常にクリア
 21618:         //  INEX2  常にクリア
 21619:         //  INEX1  引数がpackedで正確に変換できないときセット、それ以外はクリア
 21620:         epbSetRoundingPrec (EPB_PREC_SGL);
 21621:         epbFPn[nnn].neg (epbFPn[mmm]);
 21622:         break;
 21623: 
 21624:         //case 0b101_1011:  //$xx5B:
 21625: 
 21626:       case 0b101_1100:  //$xx5C: FDABS.* *m,FPn
 21627:         //  BSUN   常にクリア
 21628:         //  SNAN   引数がシグナリングNaNのときセット、それ以外はクリア
 21629:         //  OPERR  常にクリア
 21630:         //  OVFL   常にクリア
 21631:         //  UNFL   結果が非正規化数のときセット、それ以外はクリア
 21632:         //  DZ     常にクリア
 21633:         //  INEX2  常にクリア
 21634:         //  INEX1  引数がpackedで正確に変換できないときセット、それ以外はクリア
 21635:         epbSetRoundingPrec (EPB_PREC_DBL);
 21636:         epbFPn[nnn].abs (epbFPn[mmm]);
 21637:         break;
 21638: 
 21639:         //case 0b101_1101:  //$xx5D:
 21640: 
 21641:       case 0b101_1110:  //$xx5E: FDNEG.* *m,FPn
 21642:         //  BSUN   常にクリア
 21643:         //  SNAN   引数がシグナリングNaNのときセット、それ以外はクリア
 21644:         //  OPERR  常にクリア
 21645:         //  OVFL   常にクリア
 21646:         //  UNFL   結果が非正規化数のときセット、それ以外はクリア
 21647:         //  DZ     常にクリア
 21648:         //  INEX2  常にクリア
 21649:         //  INEX1  引数がpackedで正確に変換できないときセット、それ以外はクリア
 21650:         epbSetRoundingPrec (EPB_PREC_DBL);
 21651:         epbFPn[nnn].neg (epbFPn[mmm]);
 21652:         break;
 21653: 
 21654:         //case 0b101_1111:  //$xx5F:
 21655: 
 21656:       case 0b110_0000:  //$xx60: FSDIV.* *m,FPn
 21657:         //  BSUN   常にクリア
 21658:         //  SNAN   引数がシグナリングNaNのときセット、それ以外はクリア
 21659:         //  OPERR  引数が両方ゼロまたは両方無限大のときセット、それ以外はクリア
 21660:         //  OVFL   オーバーフローしたときセット、それ以外はクリア
 21661:         //  UNFL   結果が非正規化数のときセット、それ以外はクリア
 21662:         //  DZ     被除数がゼロ、無限大、NaN以外で除数がゼロのときセット、それ以外はクリア
 21663:         //  INEX2  結果に誤差があるときセット、それ以外はクリア
 21664:         //  INEX1  引数がpackedで正確に変換できないときセット、それ以外はクリア
 21665:         epbSetRoundingPrec (EPB_PREC_SGL);
 21666:         epbFPn[nnn].div (epbFPn[mmm]);
 21667:         break;
 21668: 
 21669:         //case 0b110_0001:  //$xx61:
 21670: 
 21671:       case 0b110_0010:  //$xx62: FSADD.* *m,FPn
 21672:         //  BSUN   常にクリア
 21673:         //  SNAN   引数がシグナリングNaNのときセット、それ以外はクリア
 21674:         //  OPERR  引数が両方無限大で符号が異なるときセット、それ以外はクリア
 21675:         //  OVFL   オーバーフローしたときセット、それ以外はクリア
 21676:         //  UNFL   結果が非正規化数のときセット、それ以外はクリア
 21677:         //  DZ     常にクリア
 21678:         //  INEX2  結果に誤差があるときセット、それ以外はクリア
 21679:         //  INEX1  引数がpackedで正確に変換できないときセット、それ以外はクリア
 21680:         epbSetRoundingPrec (EPB_PREC_SGL);
 21681:         epbFPn[nnn].add (epbFPn[mmm]);
 21682:         break;
 21683: 
 21684:       case 0b110_0011:  //$xx63: FSMUL.* *m,FPn
 21685:         //  BSUN   常にクリア
 21686:         //  SNAN   引数がシグナリングNaNのときセット、それ以外はクリア
 21687:         //  OPERR  引数の一方がゼロで他方が無限大のときセット、それ以外はクリア
 21688:         //  OVFL   オーバーフローしたときセット、それ以外はクリア
 21689:         //  UNFL   結果が非正規化数のときセット、それ以外はクリア
 21690:         //  DZ     常にクリア
 21691:         //  INEX2  結果に誤差があるときセット、それ以外はクリア
 21692:         //  INEX1  引数がpackedで正確に変換できないときセット、それ以外はクリア
 21693:         epbSetRoundingPrec (EPB_PREC_SGL);
 21694:         epbFPn[nnn].mul (epbFPn[mmm]);
 21695:         break;
 21696: 
 21697:       case 0b110_0100:  //$xx64: FDDIV.* *m,FPn
 21698:         //  BSUN   常にクリア
 21699:         //  SNAN   引数がシグナリングNaNのときセット、それ以外はクリア
 21700:         //  OPERR  引数が両方ゼロまたは両方無限大のときセット、それ以外はクリア
 21701:         //  OVFL   オーバーフローしたときセット、それ以外はクリア
 21702:         //  UNFL   結果が非正規化数のときセット、それ以外はクリア
 21703:         //  DZ     被除数がゼロ、無限大、NaN以外で除数がゼロのときセット、それ以外はクリア
 21704:         //  INEX2  結果に誤差があるときセット、それ以外はクリア
 21705:         //  INEX1  引数がpackedで正確に変換できないときセット、それ以外はクリア
 21706:         epbSetRoundingPrec (EPB_PREC_DBL);
 21707:         epbFPn[nnn].div (epbFPn[mmm]);
 21708:         break;
 21709: 
 21710:         //case 0b110_0101:  //$xx65:
 21711: 
 21712:       case 0b110_0110:  //$xx66: FDADD.* *m,FPn
 21713:         //  BSUN   常にクリア
 21714:         //  SNAN   引数がシグナリングNaNのときセット、それ以外はクリア
 21715:         //  OPERR  引数が両方無限大で符号が異なるときセット、それ以外はクリア
 21716:         //  OVFL   オーバーフローしたときセット、それ以外はクリア
 21717:         //  UNFL   結果が非正規化数のときセット、それ以外はクリア
 21718:         //  DZ     常にクリア
 21719:         //  INEX2  結果に誤差があるときセット、それ以外はクリア
 21720:         //  INEX1  引数がpackedで正確に変換できないときセット、それ以外はクリア
 21721:         epbSetRoundingPrec (EPB_PREC_DBL);
 21722:         epbFPn[nnn].add (epbFPn[mmm]);
 21723:         break;
 21724: 
 21725:       case 0b110_0111:  //$xx67: FDMUL.* *m,FPn
 21726:         //  BSUN   常にクリア
 21727:         //  SNAN   引数がシグナリングNaNのときセット、それ以外はクリア
 21728:         //  OPERR  引数の一方がゼロで他方が無限大のときセット、それ以外はクリア
 21729:         //  OVFL   オーバーフローしたときセット、それ以外はクリア
 21730:         //  UNFL   結果が非正規化数のときセット、それ以外はクリア
 21731:         //  DZ     常にクリア
 21732:         //  INEX2  結果に誤差があるときセット、それ以外はクリア
 21733:         //  INEX1  引数がpackedで正確に変換できないときセット、それ以外はクリア
 21734:         epbSetRoundingPrec (EPB_PREC_DBL);
 21735:         epbFPn[nnn].mul (epbFPn[mmm]);
 21736:         break;
 21737: 
 21738:       case 0b110_1000:  //$xx68: FSSUB.* *m,FPn
 21739:         //  BSUN   常にクリア
 21740:         //  SNAN   引数がシグナリングNaNのときセット、それ以外はクリア
 21741:         //  OPERR  引数が両方無限大で符号が同じときセット、それ以外はクリア
 21742:         //  OVFL   オーバーフローしたときセット、それ以外はクリア
 21743:         //  UNFL   結果が非正規化数のときセット、それ以外はクリア
 21744:         //  DZ     常にクリア
 21745:         //  INEX2  結果に誤差があるときセット、それ以外はクリア
 21746:         //  INEX1  引数がpackedで正確に変換できないときセット、それ以外はクリア
 21747:         epbSetRoundingPrec (EPB_PREC_SGL);
 21748:         epbFPn[nnn].sub (epbFPn[mmm]);
 21749:         break;
 21750: 
 21751:         //case 0b110_1001:  //$xx69:
 21752:         //case 0b110_1010:  //$xx6A:
 21753:         //case 0b110_1011:  //$xx6B:
 21754: 
 21755:       case 0b110_1100:  //$xx6C: FDSUB.* *m,FPn
 21756:         //    --------------------------------
 21757:         //    > cir 00 .
 21758:         //    0802 
 21759:         //    > cir 0a 4000
 21760:         //    > cir 00 ...
 21761:         //    9504 8900 8900 
 21762:         //    > cir 10 00000001
 21763:         //    > cir 00 ..
 21764:         //    0802 0802 
 21765:         //    > cir 0a 006c
 21766:         //    > cir 00 ...
 21767:         //    1C0B 1C0B 1C0B 
 21768:         //    > cir 02 0000
 21769:         //    > cir 00 ...
 21770:         //    0802 0802 0802 
 21771:         //    --------------------------------
 21772:         //  BSUN   常にクリア
 21773:         //  SNAN   引数がシグナリングNaNのときセット、それ以外はクリア
 21774:         //  OPERR  引数が両方無限大で符号が同じときセット、それ以外はクリア
 21775:         //  OVFL   オーバーフローしたときセット、それ以外はクリア
 21776:         //  UNFL   結果が非正規化数のときセット、それ以外はクリア
 21777:         //  DZ     常にクリア
 21778:         //  INEX2  結果に誤差があるときセット、それ以外はクリア
 21779:         //  INEX1  引数がpackedで正確に変換できないときセット、それ以外はクリア
 21780:         epbSetRoundingPrec (EPB_PREC_DBL);
 21781:         epbFPn[nnn].sub (epbFPn[mmm]);
 21782:         break;
 21783: 
 21784:         //case 0b110_1101:  //$xx6D:
 21785:         //case 0b110_1110:  //$xx6E:
 21786:         //case 0b110_1111:  //$xx6F:
 21787: 
 21788:       case 0b111_0000:  //$xx70: FLGAMMA *m,FPn
 21789:         if (EFPBox.EPB_EXTRA_OPERATION) {
 21790:           epbFPn[nnn].lgamma (epbFPn[mmm]);
 21791:         } else {
 21792:           cirException (0x1c0b);  //F-line emulator
 21793:         }
 21794:         break;
 21795: 
 21796:       case 0b111_0001:  //$xx71: FTGAMMA *m,FPn
 21797:         if (EFPBox.EPB_EXTRA_OPERATION) {
 21798:           epbFPn[nnn].tgamma (epbFPn[mmm]);
 21799:         } else {
 21800:           cirException (0x1c0b);  //F-line emulator
 21801:         }
 21802:         break;
 21803: 
 21804:         //case 0b111_0010:  //$xx72:
 21805:         //case 0b111_0011:  //$xx73:
 21806:         //case 0b111_0100:  //$xx74:
 21807:         //case 0b111_0101:  //$xx75:
 21808:         //case 0b111_0110:  //$xx76:
 21809:         //case 0b111_0111:  //$xx77:
 21810:         //case 0b111_1000:  //$xx78:
 21811:         //case 0b111_1001:  //$xx79:
 21812:         //case 0b111_1010:  //$xx7A:
 21813:         //case 0b111_1011:  //$xx7B:
 21814:         //case 0b111_1100:  //$xx7C:
 21815:         //case 0b111_1101:  //$xx7D:
 21816:         //case 0b111_1110:  //$xx7E:
 21817:         //case 0b111_1111:  //$xx7F:
 21818: 
 21819:       default:  //未定義
 21820:         cirException (0x1c0b);  //F-line emulator
 21821:         return;
 21822:       }
 21823:       //FPSRのFPCCを設定する
 21824:       epbFpsr |= epbFPn[nnn].flg >>> 4;
 21825:       if (cirMidInstruction ()) {
 21826:         return;
 21827:       }
 21828:       //終了
 21829:       cirIdle (0x0802);
 21830:       return;
 21831: 
 21832: 
 21833:     case 0b011:  //$6xxx-$7xxx: FMOVE.* FPn,<ea>
 21834:       //  BSUN   常にクリア
 21835:       //  SNAN   引数がシグナリングNaNのときセット、それ以外はクリア
 21836:       //  OPERR  byte,word,longで無限大または指定されたサイズに収まらないとき、packedでk-factorが17よりも大きいか指数部が3桁に収まらないときセット、それ以外はクリア
 21837:       //  OVFL   packedではなくてオーバーフローしたときセット、それ以外はクリア
 21838:       //  UNFL   packedではなくて結果が非正規化数のときセット、それ以外はクリア
 21839:       //  DZ     常にクリア
 21840:       //  INEX2  結果に誤差があるときセット、それ以外はクリア
 21841:       //  INEX1  常にクリア
 21842:       if (cirStage == CIR_IDLE) {  //開始
 21843:         epbFpsr &= 0xffff00ff;  //FMOVE.* FPn,<ea>でFPSRのコンディションコードバイトは変化しない
 21844:       } else if (cirStage == CIR_DESTINATION_OPERAND) {  //デスティネーションオペランド転送終了
 21845:         //終了
 21846:         cirIdle (0x0802);
 21847:         return;
 21848:       }
 21849: 
 21850:       switch (mmm) {
 21851: 
 21852:       case 0b000:  //$60xx-$63xx: FMOVE.L FPn,<ea>
 21853:         //    --------------------------------
 21854:         //    > cir 00 .
 21855:         //    0802 
 21856:         //    > cir 0a 4000
 21857:         //    > cir 00 ...
 21858:         //    9504 8900 8900 
 21859:         //    > cir 10 00000001
 21860:         //    > cir 00 .
 21861:         //    0802 
 21862:         //    > cir 0a 6000
 21863:         //    > cir 00 ...
 21864:         //    8900 B104 0802 
 21865:         //    > cir 10 .
 21866:         //    00000001 
 21867:         //    > cir 00 ..
 21868:         //    0802 0802 
 21869:         //    --------------------------------
 21870:         cirOperandBuffer[0] = epbFPn[nnn].geti (epbRoundingMode);
 21871:         if (cirMidInstruction ()) {
 21872:           return;
 21873:         }
 21874:         cirResponse = 0x8900_b104;  //(come-again→)ロングのデータを出力する→come-again
 21875:         cirOperandLength = 1;
 21876:         cirOperandIndex = 0;
 21877:         cirStage = CIR_DESTINATION_OPERAND;  //デスティネーションオペランド転送開始
 21878:         break;
 21879: 
 21880:       case 0b001:  //$64xx-$67xx: FMOVE.S FPn,<ea>
 21881:         //    --------------------------------
 21882:         //    > cir 00 .
 21883:         //    0802 
 21884:         //    > cir 0a 4000
 21885:         //    > cir 00 ...
 21886:         //    9504 8900 8900 
 21887:         //    > cir 10 00000001
 21888:         //    > cir 00 .
 21889:         //    0802 
 21890:         //    > cir 0a 6400
 21891:         //    > cir 00 ....
 21892:         //    8900 3104 0802 0802 
 21893:         //    > cir 10 .
 21894:         //    3F800000 
 21895:         //    > cir 00 ..
 21896:         //    0802 0802 
 21897:         //    --------------------------------
 21898:         cirOperandBuffer[0] = epbFPn[nnn].getf0 (epbRoundingMode);
 21899:         if (cirMidInstruction ()) {
 21900:           return;
 21901:         }
 21902:         if ((epbMode & EPB_MODE_MC68882) != 0) {  //MC68882
 21903:           cirResponse = 0x8900_3104;  //(come-again→)ロングのデータを出力する→come-again
 21904:         } else {  //MC68881
 21905:           cirResponse = 0x8900_b104;  //(come-again→)ロングのデータを出力する→come-again
 21906:         }
 21907:         cirOperandLength = 1;
 21908:         cirOperandIndex = 0;
 21909:         cirStage = CIR_DESTINATION_OPERAND;  //デスティネーションオペランド転送開始
 21910:         break;
 21911: 
 21912:       case 0b010:  //$68xx-$6Bxx: FMOVE.X FPn,<ea>
 21913:         //    --------------------------------
 21914:         //    > cir 00 .
 21915:         //    0802 
 21916:         //    > cir 0a 4000
 21917:         //    > cir 00 ...
 21918:         //    9504 8900 8900 
 21919:         //    > cir 10 00000001
 21920:         //    > cir 00 .
 21921:         //    0802 
 21922:         //    > cir 0a 6800
 21923:         //    > cir 00 ....
 21924:         //    8900 320C 8900 8900 
 21925:         //    > cir 10 .
 21926:         //    3FFF0000 
 21927:         //    > cir 00 ..
 21928:         //    8900 8900 
 21929:         //    > cir 10 .
 21930:         //    80000000 
 21931:         //    > cir 00 ..
 21932:         //    0802 0802 
 21933:         //    > cir 10 .
 21934:         //    00000000 
 21935:         //    > cir 00 ..
 21936:         //    0802 0802 
 21937:         //    --------------------------------
 21938:         {
 21939:           byte[] b = new byte[12];
 21940:           if (epbIsTriple ()) {  //三倍精度
 21941:             epbFPn[nnn].gety012 (b, 0, epbRoundingMode);
 21942:           } else {  //拡張精度
 21943:             epbFPn[nnn].getx012 (b, 0, epbRoundingMode);
 21944:           }
 21945:           if (cirMidInstruction ()) {
 21946:             return;
 21947:           }
 21948:           cirOperandBuffer[0] = b[0] << 24 | (b[1] & 255) << 16 | (char) (b[2] << 8 | b[3] & 255);
 21949:           cirOperandBuffer[1] = b[4] << 24 | (b[5] & 255) << 16 | (char) (b[6] << 8 | b[7] & 255);
 21950:           cirOperandBuffer[2] = b[8] << 24 | (b[9] & 255) << 16 | (char) (b[10] << 8 | b[11] & 255);
 21951:           if ((epbMode & EPB_MODE_MC68882) != 0) {  //MC68882
 21952:             cirResponse = 0x8900_320c;  //(come-again→)エクステンデッドのデータを出力する→come-again
 21953:           } else {  //MC68881
 21954:             cirResponse = 0x8900_320c;  //(come-again→)エクステンデッドのデータを出力する→come-again
 21955:           }
 21956:           cirOperandLength = 3;
 21957:           cirOperandIndex = 0;
 21958:           cirStage = CIR_DESTINATION_OPERAND;  //デスティネーションオペランド転送開始
 21959:           break;
 21960:         }
 21961: 
 21962:       case 0b011:  //$6Cxx-$6Fxx: FMOVE.P FPn,<ea>{#k}
 21963:         //    --------------------------------
 21964:         //    > cir 00 .
 21965:         //    0802 
 21966:         //    > cir 0a 4000
 21967:         //    > cir 00 ...
 21968:         //    9504 8900 8900 
 21969:         //    > cir 10 00000001
 21970:         //    > cir 00 .
 21971:         //    0802 
 21972:         //    > cir 0a 6c00
 21973:         //    > cir 00 ....
 21974:         //    8900 B20C 8900 8900 
 21975:         //    > cir 10 .
 21976:         //    00000001 
 21977:         //    > cir 00 ..
 21978:         //    8900 8900 
 21979:         //    > cir 10 .
 21980:         //    00000000 
 21981:         //    > cir 00 ..
 21982:         //    0802 0802 
 21983:         //    > cir 10 .
 21984:         //    00000000 
 21985:         //    > cir 00 ..
 21986:         //    0802 0802 
 21987:         //    --------------------------------
 21988:         //    > cir 00 .
 21989:         //    0802 
 21990:         //    > cir 0a 5c00
 21991:         //    > cir 00 ..
 21992:         //    0900 0802 
 21993:         //    > cir 0a 6c7e
 21994:         //    > cir 00 ....
 21995:         //    8900 B20C 8900 8900 
 21996:         //    > cir 10 ...
 21997:         //    00000003 14000000 00000000 
 21998:         //    > cir 00 ..
 21999:         //    0802 0802 
 22000:         //    > cir 0a 6c7f
 22001:         //    > cir 00 ....
 22002:         //    8900 B20C 8900 8900 
 22003:         //    > cir 10 ...
 22004:         //    00000003 10000000 00000000 
 22005:         //    > cir 00 ..
 22006:         //    0802 0802 
 22007:         //    > cir 0a 6c00
 22008:         //    > cir 00 ....
 22009:         //    8900 B20C 8900 8900 
 22010:         //    > cir 10 ...
 22011:         //    00000003 00000000 00000000 
 22012:         //    > cir 00 ..
 22013:         //    0802 0802 
 22014:         //    > cir 0a 6c01
 22015:         //    > cir 00 ....
 22016:         //    8900 B20C 8900 8900 
 22017:         //    > cir 10 ...
 22018:         //    00000003 00000000 00000000 
 22019:         //    > cir 00 ..
 22020:         //    0802 0802 
 22021:         //    > cir 0a 6c02
 22022:         //    > cir 00 ....
 22023:         //    8900 B20C 8900 8900 
 22024:         //    > cir 10 ...
 22025:         //    00000003 10000000 00000000 
 22026:         //    > cir 00 ..
 22027:         //    0802 0802 
 22028:         //    > cir 0a 6c03
 22029:         //    > cir 00 ....
 22030:         //    8900 B20C 8900 8900 
 22031:         //    > cir 10 ...
 22032:         //    00000003 14000000 00000000 
 22033:         //    > cir 00 ..
 22034:         //    0802 0802 
 22035:         //    > cir 0a 6c04
 22036:         //    > cir 00 ....
 22037:         //    8900 B20C 8900 8900 
 22038:         //    > cir 10 ...
 22039:         //    00000003 14200000 00000000 
 22040:         //    > cir 00 ..
 22041:         //    0802 0802 
 22042:         //    > cir 0a 6c05
 22043:         //    > cir 00 ....
 22044:         //    8900 B20C 8900 8900 
 22045:         //    > cir 10 ...
 22046:         //    00000003 14160000 00000000 
 22047:         //    > cir 00 ..
 22048:         //    0802 0802 
 22049:         //    > cir 0a 6c7d
 22050:         //    > cir 00 ....
 22051:         //    8900 B20C 8900 8900 
 22052:         //    > cir 10 ...
 22053:         //    00000003 14200000 00000000 
 22054:         //    > cir 00 ..
 22055:         //    0802 0802 
 22056:         //    > cir 0a 6c7c
 22057:         //    > cir 00 ....
 22058:         //    8900 B20C 8900 8900 
 22059:         //    > cir 10 ...
 22060:         //    00000003 14160000 00000000 
 22061:         //    > cir 00 ..
 22062:         //    0802 0802 
 22063:         //    --------------------------------
 22064:         {
 22065:           byte[] b = new byte[12];
 22066:           epbFPn[nnn].getp012 (b, 0, ccccccc);  //k-factor付き
 22067:           if (cirMidInstruction ()) {
 22068:             return;
 22069:           }
 22070:           cirOperandBuffer[0] = b[0] << 24 | (b[1] & 255) << 16 | (char) (b[2] << 8 | b[3] & 255);
 22071:           cirOperandBuffer[1] = b[4] << 24 | (b[5] & 255) << 16 | (char) (b[6] << 8 | b[7] & 255);
 22072:           cirOperandBuffer[2] = b[8] << 24 | (b[9] & 255) << 16 | (char) (b[10] << 8 | b[11] & 255);
 22073:           cirResponse = 0x8900_b20c;  //(come-again→)パックトのデータを出力する→come-again
 22074:           cirOperandLength = 3;
 22075:           cirOperandIndex = 0;
 22076:           cirStage = CIR_DESTINATION_OPERAND;  //デスティネーションオペランド転送開始
 22077:           break;
 22078:         }
 22079: 
 22080:       case 0b100:  //$70xx-$73xx: FMOVE.W FPn,<ea>
 22081:         //    --------------------------------
 22082:         //    > cir 00 .
 22083:         //    0802 
 22084:         //    > cir 0a 4000
 22085:         //    > cir 00 ...
 22086:         //    9504 8900 8900 
 22087:         //    > cir 10 00000001
 22088:         //    > cir 00 .
 22089:         //    0802 
 22090:         //    > cir 0a 7000
 22091:         //    > cir 00 ....
 22092:         //    8900 B102 0802 0802 
 22093:         //    > cir 10 .
 22094:         //    00010000 
 22095:         //    > cir 00 ..
 22096:         //    0802 0802 
 22097:         //    --------------------------------
 22098:         cirOperandBuffer[0] = epbFPn[nnn].gets (epbRoundingMode) << 16;  //左詰めにする
 22099:         if (cirMidInstruction ()) {
 22100:           return;
 22101:         }
 22102:         cirResponse = 0x8900_b102;  //(come-again→)ワードのデータを出力する→come-again
 22103:         cirOperandLength = 1;
 22104:         cirOperandIndex = 0;
 22105:         cirStage = CIR_DESTINATION_OPERAND;  //デスティネーションオペランド転送開始
 22106:         break;
 22107: 
 22108:       case 0b101:  //$74xx-$77xx: FMOVE.D FPn,<ea>
 22109:         //    --------------------------------
 22110:         //    > cir 00 .
 22111:         //    0802 
 22112:         //    > cir 0a 4000
 22113:         //    > cir 00 ...
 22114:         //    9504 8900 8900 
 22115:         //    > cir 10 00000001
 22116:         //    > cir 00 .
 22117:         //    0802 
 22118:         //    > cir 0a 7400
 22119:         //    > cir 00 ....
 22120:         //    8900 3208 8900 8900 
 22121:         //    > cir 10 .
 22122:         //    3FF00000 
 22123:         //    > cir 00 ..
 22124:         //    0802 0802 
 22125:         //    > cir 10 .
 22126:         //    00000000 
 22127:         //    > cir 00 ..
 22128:         //    0802 0802 
 22129:         //    --------------------------------
 22130:         {
 22131:           long l = epbFPn[nnn].getd01 (epbRoundingMode);
 22132:           if (cirMidInstruction ()) {
 22133:             return;
 22134:           }
 22135:           cirOperandBuffer[0] = (int) (l >> 32);
 22136:           cirOperandBuffer[1] = (int) l;
 22137:           if ((epbMode & EPB_MODE_MC68882) != 0) {  //MC68882
 22138:             cirResponse = 0x8900_3208;  //(come-again→)ダブルのデータを出力する→come-again
 22139:           } else {
 22140:             cirResponse = 0x8900_b208;  //(come-again→)ダブルのデータを出力する→come-again
 22141:           }
 22142:           cirOperandLength = 2;
 22143:           cirOperandIndex = 0;
 22144:           cirStage = CIR_DESTINATION_OPERAND;  //デスティネーションオペランド転送開始
 22145:         }
 22146:         break;
 22147: 
 22148:       case 0b110:  //$78xx-$7Bxx: FMOVE.B FPn,<ea>
 22149:         //    --------------------------------
 22150:         //    > cir 00 .
 22151:         //    0802 
 22152:         //    > cir 0a 4000
 22153:         //    > cir 00 ....
 22154:         //    9504 8900 8900 8900 
 22155:         //    > cir 10 00000001
 22156:         //    > cir 00 .
 22157:         //    0802 
 22158:         //    > cir 0a 7800
 22159:         //    > cir 00 ....
 22160:         //    8900 B101 0802 0802 
 22161:         //    > cir 10 .
 22162:         //    01000000 
 22163:         //    > cir 00 ..
 22164:         //    0802 0802 
 22165:         //    --------------------------------
 22166:         cirOperandBuffer[0] = epbFPn[nnn].getb (epbRoundingMode) << 24;  //左詰めにする
 22167:         if (cirMidInstruction ()) {
 22168:           return;
 22169:         }
 22170:         cirResponse = 0x8900_b101;  //(come-again→)バイトのデータを出力する→come-again
 22171:         cirOperandLength = 1;
 22172:         cirOperandIndex = 0;
 22173:         cirStage = CIR_DESTINATION_OPERAND;  //デスティネーションオペランド転送開始
 22174:         break;
 22175: 
 22176:       case 0b111:  //$7Cxx-$7Fxx: FMOVE.P FPn,<ea>{Dl}
 22177:         //    --------------------------------
 22178:         //    > cir 00 .
 22179:         //    0802 
 22180:         //    > cir 0a 4000
 22181:         //    > cir 00 ...
 22182:         //    9504 8900 8900 
 22183:         //    > cir 10 00000100
 22184:         //    > cir 00 .
 22185:         //    0802 
 22186:         //    > cir 0a 7c00
 22187:         //    > cir 00 ....
 22188:         //    8C00 8900 8900 8900 
 22189:         //    > cir 10 00000005
 22190:         //    > cir 00 ...
 22191:         //    B20C 8900 8900 
 22192:         //    > cir 10 .
 22193:         //    00020002 
 22194:         //    > cir 00 ..
 22195:         //    8900 8900 
 22196:         //    > cir 10 .
 22197:         //    56000000 
 22198:         //    > cir 00 ..
 22199:         //    0802 0802 
 22200:         //    > cir 10 .
 22201:         //    00000000 
 22202:         //    > cir 00 ..
 22203:         //    0802 0802 
 22204:         //    --------------------------------
 22205:       default:
 22206:         if (cirStage == CIR_IDLE) {  //開始
 22207:           cirResponse = 0x8900_8c00 + (cirCommand >> 4 & 7);  //データレジスタを入力する→come-again
 22208:           cirOperandLength = 1;
 22209:           cirOperandIndex = 0;
 22210:           cirStage = CIR_DYNAMIC_K_FACTOR;  //動的k-factor転送開始
 22211:           return;
 22212:         } else if (cirStage == CIR_DYNAMIC_K_FACTOR) {  //動的k-factor転送終了
 22213:           byte[] b = new byte[12];
 22214:           epbFPn[nnn].getp012 (b, 0, cirOperandBuffer[0]);  //k-factor付き
 22215:           if (cirMidInstruction ()) {
 22216:             return;
 22217:           }
 22218:           cirOperandBuffer[0] = b[0] << 24 | (b[1] & 255) << 16 | (char) (b[2] << 8 | b[3] & 255);
 22219:           cirOperandBuffer[1] = b[4] << 24 | (b[5] & 255) << 16 | (char) (b[6] << 8 | b[7] & 255);
 22220:           cirOperandBuffer[2] = b[8] << 24 | (b[9] & 255) << 16 | (char) (b[10] << 8 | b[11] & 255);
 22221:           cirResponse = 0x8900_b20c;  //(come-again→)パックトのデータを出力する→come-again
 22222:           cirOperandLength = 3;
 22223:           cirOperandIndex = 0;
 22224:           cirStage = CIR_DESTINATION_OPERAND;  //デスティネーションオペランド転送開始
 22225:         }
 22226:       }
 22227:       return;
 22228: 
 22229: 
 22230:     case 0b100:  //$8xxx-$9xxx: FMOVEM.L <ea>,FPCR/FPSR/FPIAR
 22231:       //  FMOVEM命令は例外を発生させずFPCR/FPSR/FPIARも(デスティネーションに書かれたもの以外)変化しない
 22232:       //  格納順序はFPCRが下位アドレス(連結したとき上位),FPIARが上位アドレス(連結したとき下位)
 22233: 
 22234:       switch (mmm) {
 22235: 
 22236:       case 0b000:  //$8000: FMOVE.L <ea>,<>
 22237:         //    --------------------------------
 22238:         //    > cir 00 .
 22239:         //    0802 
 22240:         //    > cir 0a 8000
 22241:         //    > cir 00 ....
 22242:         //    8900 9704 8900 8900 
 22243:         //    > cir 10 00000000
 22244:         //    > cir 00 ..
 22245:         //    0802 0802 
 22246:         //    --------------------------------
 22247:         //  レジスタを1個も指定しないとFPIARが指定されたものとみなされる
 22248: 
 22249:       case 0b001:  //$8400: FMOVE.L <ea>,FPIAR
 22250:         //    --------------------------------
 22251:         //    > cir 00 .
 22252:         //    0802 
 22253:         //    > cir 0a 8400
 22254:         //    > cir 00 ....
 22255:         //    8900 9704 8900 8900 
 22256:         //    > cir 10 00000000
 22257:         //    > cir 00 ..
 22258:         //    0802 0802 
 22259:         //    --------------------------------
 22260:         if (cirStage == CIR_IDLE) {  //開始
 22261:           cirResponse = 0x8900_9704;  //FPIARを入力する→come_again
 22262:           cirOperandLength = 1;
 22263:           cirOperandIndex = 0;
 22264:           cirStage = CIR_SOURCE_OPERAND;  //ソースオペランド転送開始
 22265:           return;
 22266:         } else {  //ソースオペランド転送終了
 22267:           epbFpiar = cirOperandBuffer[0];
 22268:         }
 22269:         break;
 22270: 
 22271:       case 0b010:  //$8800: FMOVE.L <ea>,FPSR
 22272:         //  fmove.lでfpsrのEXCに書き込んだだけではAEXCは更新されない
 22273:         //  fmove.lでfpsrに0x0000ff00を書き込んですぐに読み出しても0x0000ff00のまま
 22274:         //    --------------------------------
 22275:         //    > cir 00 .
 22276:         //    0802 
 22277:         //    > cir 0a 8800
 22278:         //    > cir 00 ....
 22279:         //    8900 9504 8900 8900 
 22280:         //    > cir 10 00000000
 22281:         //    > cir 00 ..
 22282:         //    0802 0802 
 22283:         //    --------------------------------
 22284:         if (cirStage == CIR_IDLE) {  //開始
 22285:           cirResponse = 0x8900_9504;  //FPSRを入力する→come_again
 22286:           cirOperandLength = 1;
 22287:           cirOperandIndex = 0;
 22288:           cirStage = CIR_SOURCE_OPERAND;  //ソースオペランド転送開始
 22289:           return;
 22290:         } else {  //ソースオペランド転送終了
 22291:           epbFpsr = cirOperandBuffer[0] & EPB_FPSR_ALL;
 22292:         }
 22293:         break;
 22294: 
 22295:       case 0b011:  //$8C00: FMOVEM.L <ea>,FPSR/FPIAR
 22296:         //    --------------------------------
 22297:         //    > cir 00 .
 22298:         //    0802 
 22299:         //    > cir 0a 8c00
 22300:         //    > cir 00 ....
 22301:         //    8900 9608 8900 8900 
 22302:         //    > cir 10 00000000
 22303:         //    > cir 00 ..
 22304:         //    8900 8900 
 22305:         //    > cir 10 00000000
 22306:         //    > cir 00 ..
 22307:         //    0802 0802 
 22308:         //    --------------------------------
 22309:         if (cirStage == CIR_IDLE) {  //開始
 22310:           cirResponse = 0x8900_9608;  //FPSR/FPIARを入力する→come_again
 22311:           cirOperandLength = 2;
 22312:           cirOperandIndex = 0;
 22313:           cirStage = CIR_SOURCE_OPERAND;  //ソースオペランド転送開始
 22314:           return;
 22315:         } else {  //ソースオペランド転送終了
 22316:           epbFpsr = cirOperandBuffer[0] & EPB_FPSR_ALL;
 22317:           epbFpiar = cirOperandBuffer[1];
 22318:         }
 22319:         break;
 22320: 
 22321:       case 0b100:  //$9000: FMOVE.L <ea>,FPCR
 22322:         //    --------------------------------
 22323:         //    > cir 00 .
 22324:         //    0802 
 22325:         //    > cir 0a 9000
 22326:         //    > cir 00 ....
 22327:         //    8900 9504 8900 8900 
 22328:         //    > cir 10 00000000
 22329:         //    > cir 00 ..
 22330:         //    0802 0802 
 22331:         //    --------------------------------
 22332:         if (cirStage == CIR_IDLE) {  //開始
 22333:           cirResponse = 0x8900_9504;  //FPCRを入力する→come_again
 22334:           cirOperandLength = 1;
 22335:           cirOperandIndex = 0;
 22336:           cirStage = CIR_SOURCE_OPERAND;  //ソースオペランド転送開始
 22337:           return;
 22338:         } else {  //ソースオペランド転送終了
 22339:           epbFpcr = cirOperandBuffer[0] & EPB_FPCR_ALL;
 22340:         }
 22341:         break;
 22342: 
 22343:       case 0b101:  //$9400: FMOVEM.L <ea>,FPCR/FPIAR
 22344:         //    --------------------------------
 22345:         //    > cir 00 .
 22346:         //    0802 
 22347:         //    > cir 0a 9400
 22348:         //    > cir 00 ....
 22349:         //    8900 9608 8900 8900 
 22350:         //    > cir 10 00000000
 22351:         //    > cir 00 ..
 22352:         //    8900 8900 
 22353:         //    > cir 10 00000000
 22354:         //    > cir 00 ..
 22355:         //    0802 0802 
 22356:         //    --------------------------------
 22357:         if (cirStage == CIR_IDLE) {  //開始
 22358:           cirResponse = 0x8900_9608;  //FPCR/FPIARを入力する→come_again
 22359:           cirOperandLength = 2;
 22360:           cirOperandIndex = 0;
 22361:           cirStage = CIR_SOURCE_OPERAND;  //ソースオペランド転送開始
 22362:           return;
 22363:         } else {  //ソースオペランド転送終了
 22364:           epbFpcr = cirOperandBuffer[0] & EPB_FPCR_ALL;
 22365:           epbFpiar = cirOperandBuffer[1];
 22366:         }
 22367:         break;
 22368: 
 22369:       case 0b110:  //$9800: FMOVEM.L <ea>,FPCR/FPSR
 22370:         //    --------------------------------
 22371:         //    > cir 00 .
 22372:         //    0802 
 22373:         //    > cir 0a 9800
 22374:         //    > cir 00 ....
 22375:         //    8900 9608 8900 8900 
 22376:         //    > cir 10 00000000
 22377:         //    > cir 00 ..
 22378:         //    8900 8900 
 22379:         //    > cir 10 00000000
 22380:         //    > cir 00 ..
 22381:         //    0802 0802 
 22382:         //    --------------------------------
 22383:         if (cirStage == CIR_IDLE) {  //開始
 22384:           cirResponse = 0x8900_9608;  //FPCR/FPSRを入力する→come_again
 22385:           cirOperandLength = 2;
 22386:           cirOperandIndex = 0;
 22387:           cirStage = CIR_SOURCE_OPERAND;  //ソースオペランド転送開始
 22388:           return;
 22389:         } else {  //ソースオペランド転送終了
 22390:           epbFpcr = cirOperandBuffer[0] & EPB_FPCR_ALL;
 22391:           epbFpsr = cirOperandBuffer[1] & EPB_FPSR_ALL;
 22392:         }
 22393:         break;
 22394: 
 22395:       case 0b111:  //$9C00: FMOVEM.L <ea>,FPCR/FPSR/FPIAR
 22396:         //    --------------------------------
 22397:         //    > cir 00 .
 22398:         //    0802 
 22399:         //    > cir 0a 9c00
 22400:         //    > cir 00 ....
 22401:         //    8900 960C 8900 8900 
 22402:         //    > cir 10 00000000
 22403:         //    > cir 00 ..
 22404:         //    8900 8900 
 22405:         //    > cir 10 00000000
 22406:         //    > cir 00 ..
 22407:         //    8900 8900 
 22408:         //    > cir 10 00000000
 22409:         //    > cir 00 ..
 22410:         //    0802 0802 
 22411:         //    --------------------------------
 22412:       default:
 22413:         if (cirStage == CIR_IDLE) {  //開始
 22414:           cirResponse = 0x8900_960c;  //FPCR/FPSR/FPIARを入力する→come_again
 22415:           cirOperandLength = 3;
 22416:           cirOperandIndex = 0;
 22417:           cirStage = CIR_SOURCE_OPERAND;  //ソースオペランド転送開始
 22418:           return;
 22419:         } else {  //ソースオペランド転送終了
 22420:           epbFpcr = cirOperandBuffer[0] & EPB_FPCR_ALL;
 22421:           epbFpsr = cirOperandBuffer[1] & EPB_FPSR_ALL;
 22422:           epbFpiar = cirOperandBuffer[2];
 22423:         }
 22424:       }
 22425:       //終了
 22426:       cirIdle (0x0802);
 22427:       return;
 22428: 
 22429: 
 22430:     case 0b101:  //$Axxx-$Bxxx: FMOVEM.L FPCR/FPSR/FPIAR,<ea>
 22431:       //  FMOVEM命令は例外を発生させずFPCR/FPSR/FPIARも(デスティネーションに書かれたもの以外)変化しない
 22432:       //  格納順序はFPCRが下位アドレス(連結したとき上位),FPIARが上位アドレス(連結したとき下位)
 22433:       if (cirStage == CIR_DESTINATION_OPERAND) {  //デスティネーションオペランド転送終了
 22434:         //終了
 22435:         cirIdle (0x0802);
 22436:         return;
 22437:       }
 22438: 
 22439:       switch (mmm) {
 22440: 
 22441:       case 0b000:  //$A000: FMOVE.L <>,<ea>
 22442:         //  レジスタを1個も指定しないとFPIARが指定されたものとみなされる
 22443:         //    --------------------------------
 22444:         //    > cir 00 .
 22445:         //    0802 
 22446:         //    > cir 0a a000
 22447:         //    > cir 00 ....
 22448:         //    8900 B304 0802 0802 
 22449:         //    > cir 10 .
 22450:         //    00000000 
 22451:         //    > cir 00 ..
 22452:         //    0802 0802 
 22453:         //    --------------------------------
 22454: 
 22455:       case 0b001:  //$A400: FMOVE.L FPIAR,<ea>
 22456:         //    --------------------------------
 22457:         //    > cir 00 .
 22458:         //    0802 
 22459:         //    > cir 0a a400
 22460:         //    > cir 00 ....
 22461:         //    8900 B304 0802 0802 
 22462:         //    > cir 10 .
 22463:         //    00000000 
 22464:         //    > cir 00 ..
 22465:         //    0802 0802 
 22466:         //    --------------------------------
 22467:         cirOperandBuffer[0] = epbFpiar;
 22468:         cirResponse = 0x8900_b304;  //FPIARを出力する→come_again
 22469:         cirOperandLength = 1;
 22470:         cirOperandIndex = 0;
 22471:         cirStage = CIR_DESTINATION_OPERAND;  //デスティネーションオペランド転送開始
 22472:         return;
 22473: 
 22474:       case 0b010:  //$A800: FMOVE.L FPSR,<ea>
 22475:         //    --------------------------------
 22476:         //    > cir 00 .
 22477:         //    0802 
 22478:         //    > cir 0a a800
 22479:         //    > cir 00 ....
 22480:         //    8900 B104 0802 0802 
 22481:         //    > cir 10 .
 22482:         //    00000000 
 22483:         //    > cir 00 ..
 22484:         //    0802 0802 
 22485:         //    --------------------------------
 22486:         cirOperandBuffer[0] = epbFpsr;
 22487:         cirResponse = 0x8900_b104;  //FPSRを出力する→come_again
 22488:         cirOperandLength = 1;
 22489:         cirOperandIndex = 0;
 22490:         cirStage = CIR_DESTINATION_OPERAND;  //デスティネーションオペランド転送開始
 22491:         return;
 22492: 
 22493:       case 0b011:  //$AC00: FMOVEM.L FPSR/FPIAR,<ea>
 22494:         //    --------------------------------
 22495:         //    > cir 00 .
 22496:         //    0802 
 22497:         //    > cir 0a ac00
 22498:         //    > cir 00 ....
 22499:         //    8900 B208 8900 8900 
 22500:         //    > cir 10 .
 22501:         //    00000000 
 22502:         //    > cir 00 ..
 22503:         //    0802 0802 
 22504:         //    > cir 10 .
 22505:         //    00000000 
 22506:         //    > cir 00 ..
 22507:         //    0802 0802 
 22508:         //    --------------------------------
 22509:         cirOperandBuffer[0] = epbFpsr;
 22510:         cirOperandBuffer[1] = epbFpiar;
 22511:         cirResponse = 0x8900_b208;  //FPSR/FPIARを出力する→come_again
 22512:         cirOperandLength = 2;
 22513:         cirOperandIndex = 0;
 22514:         cirStage = CIR_DESTINATION_OPERAND;  //デスティネーションオペランド転送開始
 22515:         return;
 22516: 
 22517:       case 0b100:  //$B000: FMOVE.L FPCR,<ea>
 22518:         //    --------------------------------
 22519:         //    > cir 00 .
 22520:         //    0802 
 22521:         //    > cir 0a b000
 22522:         //    > cir 00 ....
 22523:         //    8900 B104 0802 0802 
 22524:         //    > cir 10 .
 22525:         //    00000000 
 22526:         //    > cir 00 ..
 22527:         //    0802 0802 
 22528:         //    --------------------------------
 22529:         cirOperandBuffer[0] = epbFpcr;
 22530:         cirResponse = 0x8900_b104;  //FPCRを出力する→come_again
 22531:         cirOperandLength = 1;
 22532:         cirOperandIndex = 0;
 22533:         cirStage = CIR_DESTINATION_OPERAND;  //デスティネーションオペランド転送開始
 22534:         return;
 22535: 
 22536:       case 0b101:  //$B400: FMOVEM.L FPCR/FPIAR,<ea>
 22537:         //    --------------------------------
 22538:         //    > cir 00 .
 22539:         //    0802 
 22540:         //    > cir 0a b400
 22541:         //    > cir 00 ....
 22542:         //    8900 B208 8900 8900 
 22543:         //    > cir 10 .
 22544:         //    00000000 
 22545:         //    > cir 00 ..
 22546:         //    0802 0802 
 22547:         //    > cir 10 .
 22548:         //    00000000 
 22549:         //    > cir 00 ..
 22550:         //    0802 0802 
 22551:         //    --------------------------------
 22552:         cirOperandBuffer[0] = epbFpcr;
 22553:         cirOperandBuffer[1] = epbFpiar;
 22554:         cirResponse = 0x8900_b208;  //FPCR/FPIARを出力する→come_again
 22555:         cirOperandLength = 2;
 22556:         cirOperandIndex = 0;
 22557:         cirStage = CIR_DESTINATION_OPERAND;  //デスティネーションオペランド転送開始
 22558:         return;
 22559: 
 22560:       case 0b110:  //$B800: FMOVEM.L FPCR/FPSR,<ea>
 22561:         //    --------------------------------
 22562:         //    > cir 00 .
 22563:         //    0802 
 22564:         //    > cir 0a b800
 22565:         //    > cir 00 ....
 22566:         //    8900 B208 8900 8900 
 22567:         //    > cir 10 .
 22568:         //    00000000 
 22569:         //    > cir 00 ..
 22570:         //    0802 0802 
 22571:         //    > cir 10 .
 22572:         //    00000000 
 22573:         //    > cir 00 ..
 22574:         //    0802 0802 
 22575:         //    --------------------------------
 22576:         cirOperandBuffer[0] = epbFpcr;
 22577:         cirOperandBuffer[1] = epbFpsr;
 22578:         cirResponse = 0x8900_b208;  //FPCR/FPSRを出力する→come_again
 22579:         cirOperandLength = 2;
 22580:         cirOperandIndex = 0;
 22581:         cirStage = CIR_DESTINATION_OPERAND;  //デスティネーションオペランド転送開始
 22582:         return;
 22583: 
 22584:       case 0b111:  //$BC00: FMOVEM.L FPCR/FPSR/FPIAR,<ea>
 22585:         //    --------------------------------
 22586:         //    > cir 00 .
 22587:         //    0802 
 22588:         //    > cir 0a bc00
 22589:         //    > cir 00 ....
 22590:         //    8900 B20C 8900 8900 
 22591:         //    > cir 10 .
 22592:         //    00000000 
 22593:         //    > cir 00 ..
 22594:         //    8900 8900 
 22595:         //    > cir 10 .
 22596:         //    00000000 
 22597:         //    > cir 00 ..
 22598:         //    0802 0802 
 22599:         //    > cir 10 .
 22600:         //    00000000 
 22601:         //    > cir 00 ..
 22602:         //    0802 0802 
 22603:         //    --------------------------------
 22604:       default:
 22605:         cirOperandBuffer[0] = epbFpcr;
 22606:         cirOperandBuffer[1] = epbFpsr;
 22607:         cirOperandBuffer[2] = epbFpiar;
 22608:         cirResponse = 0x8900_b20c;  //FPCR/FPSR/FPIARを出力する→come_again
 22609:         cirOperandLength = 3;
 22610:         cirOperandIndex = 0;
 22611:         cirStage = CIR_DESTINATION_OPERAND;  //デスティネーションオペランド転送開始
 22612:         return;
 22613:       }
 22614:       //break;
 22615: 
 22616: 
 22617:     case 0b110:  //$Cxxx-$Dxxx: FMOVEM.X <ea>,<list>
 22618:       //  FMOVEM命令は例外を発生させずFPCR/FPSR/FPIARも(デスティネーションに書かれたもの以外)変化しない
 22619:       //    --------------------------------
 22620:       //    > cir 00 .
 22621:       //    0802 
 22622:       //    > cir 0a d0ff
 22623:       //    > cir 00 ....
 22624:       //    8900 810C 8900 8900 
 22625:       //    > cir 14 .
 22626:       //    FF00 
 22627:       //    > cir 00 ..
 22628:       //    8900 8900 
 22629:       //    > cir 10 3fff0000
 22630:       //    > cir 00 ..
 22631:       //    8900 8900 
 22632:       //    > cir 10 80000000
 22633:       //    > cir 00 ..
 22634:       //    8900 8900 
 22635:       //    > cir 10 00000000
 22636:       //    > cir 00 ..
 22637:       //    8900 8900 
 22638:       //    > cir 10 40000000 80000000 00000000
 22639:       //    > cir 10 40010000 80000000 00000000
 22640:       //    > cir 10 40020000 80000000 00000000
 22641:       //    > cir 10 40030000 80000000 00000000
 22642:       //    > cir 10 40040000 80000000 00000000
 22643:       //    > cir 10 40050000 80000000 00000000
 22644:       //    > cir 00 ..
 22645:       //    8900 8900 
 22646:       //    > cir 10 40060000
 22647:       //    > cir 00 ..
 22648:       //    8900 8900 
 22649:       //    > cir 10 80000000
 22650:       //    > cir 00 ..
 22651:       //    8900 8900 
 22652:       //    > cir 10 00000000
 22653:       //    > cir 00 ..
 22654:       //    0802 0802 
 22655:       //    --------------------------------
 22656:       //    レスポンス$810Cが帰った直後に$14 register selectをリードしないとプロトコル違反になる
 22657:       //    > cir 00 .
 22658:       //    0802 
 22659:       //    > cir 0a d0ff
 22660:       //    > cir 00 ....
 22661:       //    8900 810C 8900 8900 
 22662:       //    > cir 10 3fff0000
 22663:       //    > cir 00 ..
 22664:       //    1D0D 1D0D 
 22665:       //    > cir 06 0000
 22666:       //    > cir 00 ..
 22667:       //    0802 0802 
 22668:       //    --------------------------------
 22669:       //    転送するレジスタがなくても$14 register selectを1回だけリードしなければならない
 22670:       //    > cir 00 .
 22671:       //    0802 
 22672:       //    > cir 0a d000
 22673:       //    > cir 00 ....
 22674:       //    8900 810C 0802 0802 
 22675:       //    > cir 0a 0000
 22676:       //    > cir 00 ..
 22677:       //    1D0D 1D0D 
 22678:       //    > cir 06 0000
 22679:       //    > cir 00 ..
 22680:       //    0802 0802 
 22681:       //    > cir 00 .
 22682:       //    0802 
 22683:       //    > cir 0a d000
 22684:       //    > cir 00 ....
 22685:       //    8900 810C 0802 0802 
 22686:       //    > cir 14 .
 22687:       //    0000 
 22688:       //    > cir 00 ..
 22689:       //    0802 0802 
 22690:       //    > cir 14 .
 22691:       //    0000 
 22692:       //    > cir 00 ..
 22693:       //    1D0D 1D0D 
 22694:       //    > cir 06 0000
 22695:       //    > cir 00 ..
 22696:       //    0802 0802 
 22697:       //    --------------------------------
 22698:       //    fmovem.x -(a0),fp0-fp7が許容される。転送順序はFP7→FP6→...→FP1→FP0
 22699:       //    > cir 00 .
 22700:       //    0802 
 22701:       //    > cir 0a c0ff
 22702:       //    > cir 00 ....
 22703:       //    8900 810C 8900 8900 
 22704:       //    > cir 14 .
 22705:       //    FF00 
 22706:       //    > cir 10 3fff0000
 22707:       //    > cir 00 ..
 22708:       //    8900 8900 
 22709:       //    > cir 10 80000000
 22710:       //    > cir 00 ..
 22711:       //    8900 8900 
 22712:       //    > cir 10 00000000
 22713:       //    > cir 00 ..
 22714:       //    8900 8900 
 22715:       //    > cir 10 40000000
 22716:       //    > cir 00 ..
 22717:       //    8900 8900 
 22718:       //    > cir 10 80000000
 22719:       //    > cir 00 ..
 22720:       //    8900 8900 
 22721:       //    > cir 10 00000000
 22722:       //    > cir 00 ..
 22723:       //    8900 8900 
 22724:       //    > cir 10 40010000
 22725:       //    > cir 00 ..
 22726:       //    8900 8900 
 22727:       //    > cir 10 80000000
 22728:       //    > cir 00 ..
 22729:       //    8900 8900 
 22730:       //    > cir 10 00000000
 22731:       //    > cir 00 ..
 22732:       //    8900 8900 
 22733:       //    > cir 10 40020000
 22734:       //    > cir 00 ..
 22735:       //    8900 8900 
 22736:       //    > cir 10 80000000
 22737:       //    > cir 00 ..
 22738:       //    8900 8900 
 22739:       //    > cir 10 00000000
 22740:       //    > cir 00 ..
 22741:       //    8900 8900 
 22742:       //    > cir 10 40030000
 22743:       //    > cir 00 ..
 22744:       //    8900 8900 
 22745:       //    > cir 10 80000000
 22746:       //    > cir 00 ..
 22747:       //    8900 8900 
 22748:       //    > cir 10 00000000
 22749:       //    > cir 00 ..
 22750:       //    8900 8900 
 22751:       //    > cir 10 40040000
 22752:       //    > cir 00 ..
 22753:       //    8900 8900 
 22754:       //    > cir 10 80000000
 22755:       //    > cir 00 ..
 22756:       //    8900 8900 
 22757:       //    > cir 10 00000000
 22758:       //    > cir 00 ..
 22759:       //    8900 8900 
 22760:       //    > cir 10 40050000
 22761:       //    > cir 00 ..
 22762:       //    8900 8900 
 22763:       //    > cir 10 80000000
 22764:       //    > cir 00 ..
 22765:       //    8900 8900 
 22766:       //    > cir 10 00000000
 22767:       //    > cir 00 ..
 22768:       //    8900 8900 
 22769:       //    > cir 10 40060000
 22770:       //    > cir 00 ..
 22771:       //    8900 8900 
 22772:       //    > cir 10 80000000
 22773:       //    > cir 00 ..
 22774:       //    8900 8900 
 22775:       //    > cir 10 00000000
 22776:       //    > cir 00 ..
 22777:       //    0802 0802 
 22778:       //    > cir 00 .
 22779:       //    0802 
 22780:       //    > cir 0a 6000
 22781:       //    > cir 00 ....
 22782:       //    8900 B104 0802 0802 
 22783:       //    > cir 10 .
 22784:       //    00000080 
 22785:       //    --------------------------------
 22786:       //    memory to FPCP, pre-decrment, static register list
 22787:       //    > cir 00 .
 22788:       //    0802 
 22789:       //    > cir 0a c001
 22790:       //    > cir 00 ....
 22791:       //    8900 810C 8900 8900 
 22792:       //    > cir 14 .
 22793:       //    0100 
 22794:       //    > cir 00 ....
 22795:       //    8900 8900 8900 8900 
 22796:       //    > cir 10 40020000
 22797:       //    > cir 00 ..
 22798:       //    8900 8900 
 22799:       //    > cir 10 b0000000
 22800:       //    > cir 00 ..
 22801:       //    8900 8900 
 22802:       //    > cir 10 00000000
 22803:       //    > cir 00 ..
 22804:       //    0802 0802 
 22805:       //    > cir 0a 6000
 22806:       //    > cir 00 ....
 22807:       //    8900 B104 0802 0802 
 22808:       //    > cir 10 .
 22809:       //    0000000B 
 22810:       //    > cir 00 ..
 22811:       //    0802 0802 
 22812:       //    --------------------------------
 22813:       //    memory to FPCP, pre-decrment, dynamic register list
 22814:       //    > cir 00 .
 22815:       //    0802 
 22816:       //    > cir 0a c850
 22817:       //    > cir 00 ....
 22818:       //    8C05 8900 8900 8900 
 22819:       //    > cir 10 00000001
 22820:       //    > cir 00 ....
 22821:       //    810C 8900 8900 8900 
 22822:       //    > cir 14 .
 22823:       //    0100 
 22824:       //    > cir 10 40020000
 22825:       //    > cir 00 ..
 22826:       //    8900 8900 
 22827:       //    > cir 10 90000000
 22828:       //    > cir 00 ..
 22829:       //    8900 8900 
 22830:       //    > cir 10 00000000
 22831:       //    > cir 00 ..
 22832:       //    0802 0802 
 22833:       //    > cir 0a 6000
 22834:       //    > cir 00 ....
 22835:       //    8900 B104 0802 0802 
 22836:       //    > cir 10 .
 22837:       //    00000009 
 22838:       //    > cir 00 ..
 22839:       //    0802 0802 
 22840:       //    --------------------------------
 22841:       //    memory to FPCP, post-increment, static register list
 22842:       //    > cir 00 .
 22843:       //    0802 
 22844:       //    > cir 0a d080
 22845:       //    > cir 00 ....
 22846:       //    8900 810C 8900 8900 
 22847:       //    > cir 14 .
 22848:       //    8000 
 22849:       //    > cir 00 ..
 22850:       //    8900 8900 
 22851:       //    > cir 10 40010000
 22852:       //    > cir 00 ..
 22853:       //    8900 8900 
 22854:       //    > cir 10 a0000000
 22855:       //    > cir 00 ..
 22856:       //    8900 8900 
 22857:       //    > cir 10 00000000
 22858:       //    > cir 00 ..
 22859:       //    0802 0802 
 22860:       //    > cir 0a 6000
 22861:       //    > cir 00 ....
 22862:       //    8900 B104 0802 0802 
 22863:       //    > cir 10 .
 22864:       //    00000005 
 22865:       //    > cir 00 ..
 22866:       //    0802 0802 
 22867:       //    --------------------------------
 22868:       //    memory to FPCP, post-increment, dynamic register list
 22869:       //    > cir 00 .
 22870:       //    0802 
 22871:       //    > cir 0a d870
 22872:       //    > cir 00 ....
 22873:       //    8C07 8900 8900 8900 
 22874:       //    > cir 10 00000080
 22875:       //    > cir 00 ...
 22876:       //    810C 8900 8900 
 22877:       //    > cir 14 .
 22878:       //    8000 
 22879:       //    > cir 00 ..
 22880:       //    8900 8900 
 22881:       //    > cir 10 40000000
 22882:       //    > cir 00 ..
 22883:       //    8900 8900 
 22884:       //    > cir 10 c0000000
 22885:       //    > cir 00 ..
 22886:       //    8900 8900 
 22887:       //    > cir 10 00000000
 22888:       //    > cir 00 ..
 22889:       //    0802 0802 
 22890:       //    > cir 0a 6000
 22891:       //    > cir 00 ....
 22892:       //    8900 B104 0802 0802 
 22893:       //    > cir 10 .
 22894:       //    00000003 
 22895:       //    > cir 00 ..
 22896:       //    0802 0802 
 22897:       //    --------------------------------
 22898:       if (cirStage == CIR_IDLE) {  //開始
 22899:         if ((cirCommand & 0x0700) != 0) {
 22900:           cirException (0x1c0b);  //F-line emulator
 22901:           return;
 22902:         }
 22903:         if ((mmm & 2) == 0) {  //静的レジスタリスト
 22904:           cirRegisterList = cirCommand & 255;
 22905:           cirResponse = 0x8900_810c;  //複数レジスタを入力する→come_again
 22906:           cirStage = CIR_REGISTER_SELECT;  //レジスタセレクト転送開始
 22907:         } else {  //動的レジスタリスト
 22908:           cirResponse = 0x8900_8c00 + (cirCommand >> 4 & 7);  //データレジスタを入力する→come-again
 22909:           cirOperandLength = 1;
 22910:           cirOperandIndex = 0;
 22911:           cirStage = CIR_DYNAMIC_REGISTER_LIST;  //動的レジスタリスト転送開始
 22912:         }
 22913:         return;
 22914:       }
 22915:       if (cirStage == CIR_DYNAMIC_REGISTER_LIST) {  //動的レジスタリスト転送終了
 22916:         cirRegisterList = cirOperandBuffer[0] & 255;
 22917:         cirResponse = 0x8900_810c;  //複数レジスタを入力する→come_again
 22918:         cirStage = CIR_REGISTER_SELECT;  //レジスタセレクト転送開始
 22919:         return;
 22920:       }
 22921:       if (cirStage == CIR_REGISTER_SELECT) {  //レジスタセレクト転送終了
 22922:         if (cirRegisterList == 0) {  //転送するレジスタがない
 22923:           //終了
 22924:           cirIdle (0x0802);
 22925:           return;
 22926:         }
 22927:         cirOperandLength = 3 * Integer.bitCount (cirRegisterList);  //転送するレジスタ数*3=転送するロング数
 22928:         cirOperandIndex = 0;
 22929:         cirStage = CIR_SOURCE_OPERAND;  //ソースオペランド転送開始
 22930:         return;
 22931:       }
 22932:       //if (cirStage == CIR_SOURCE_OPERAND)
 22933:       {  //ソースオペランド転送終了
 22934:         int n, p;
 22935:         if ((cirCommand & 0x1000) == 0) {  //プレデクリメント。リストはFP7|…|FP0、転送順序はFP7→FP0、オペランドバッファはFP0,…,FP7
 22936:           n = 7;
 22937:           p = -1;
 22938:         } else {  //ポストインクリメント。リストはFP0|…|FP7、転送順序はFP0→FP7、オペランドバッファはFP7,…,FP0
 22939:           n = 0;
 22940:           p = 1;
 22941:         }
 22942:         int i = 0;
 22943:         for (int list = cirRegisterList << 24; list != 0; n += p, list <<= 1) {
 22944:           if (list < 0) {
 22945:             if (epbIsTriple ()) {  //三倍精度
 22946:               epbFPn[n].sety012 (cirOperandBuffer[i], (long) cirOperandBuffer[i + 1] << 32 | cirOperandBuffer[i + 2] & 0xffffffffL);
 22947:             } else {  //拡張精度
 22948:               epbFPn[n].setx012 (cirOperandBuffer[i], (long) cirOperandBuffer[i + 1] << 32 | cirOperandBuffer[i + 2] & 0xffffffffL);
 22949:             }
 22950:             i += 3;
 22951:           }
 22952:         }
 22953:         //終了
 22954:         cirIdle (0x0802);
 22955:         return;
 22956:       }
 22957:       //break;
 22958: 
 22959: 
 22960:     case 0b111:  //$Exxx-$Fxxx: FMOVEM.X <list>,<ea>
 22961:       //  FMOVEM命令は例外を発生させずFPCR/FPSR/FPIARも(デスティネーションに書かれたもの以外)変化しない
 22962:       //    --------------------------------
 22963:       //    FPCP to memory, pre-decrement, static register list
 22964:       //    > cir 00 .
 22965:       //    0802 
 22966:       //    > cir 0a 4000
 22967:       //    > cir 00 ....
 22968:       //    9504 8900 8900 8900 
 22969:       //    > cir 10 00000080
 22970:       //    > cir 00 ..
 22971:       //    0802 0802 
 22972:       //    > cir 0a 4080
 22973:       //    > cir 00 ....
 22974:       //    9504 8900 8900 8900 
 22975:       //    > cir 10 00000081
 22976:       //    > cir 00 ..
 22977:       //    0802 0802 
 22978:       //    > cir 0a e003
 22979:       //    > cir 00 ....
 22980:       //    8900 A10C 8900 8900 
 22981:       //    > cir 14 .
 22982:       //    0300 
 22983:       //    > cir 00 ..
 22984:       //    8900 8900 
 22985:       //    > cir 10 .
 22986:       //    40060000 
 22987:       //    > cir 00 ..
 22988:       //    8900 8900 
 22989:       //    > cir 10 .
 22990:       //    81000000 
 22991:       //    > cir 00 ..
 22992:       //    8900 8900 
 22993:       //    > cir 10 .
 22994:       //    00000000 
 22995:       //    > cir 00 ..
 22996:       //    8900 8900 
 22997:       //    > cir 10 .
 22998:       //    40060000 
 22999:       //    > cir 00 ..
 23000:       //    8900 8900 
 23001:       //    > cir 10 .
 23002:       //    80000000 
 23003:       //    > cir 00 ..
 23004:       //    0802 0802 
 23005:       //    --------------------------------
 23006:       //    FPCP to memory, pre-decrement, dynamic register list
 23007:       //    > cir 00 .
 23008:       //    0802 
 23009:       //    > cir 0a 4000
 23010:       //    > cir 00 ....
 23011:       //    9504 8900 8900 8900 
 23012:       //    > cir 10 00000082
 23013:       //    > cir 00 ..
 23014:       //    0802 0802 
 23015:       //    > cir 0a 4080
 23016:       //    > cir 00 ....
 23017:       //    9504 8900 8900 8900 
 23018:       //    > cir 10 00000083
 23019:       //    > cir 00 ..
 23020:       //    0802 0802 
 23021:       //    > cir 0a e870
 23022:       //    > cir 00 ....
 23023:       //    8C07 8900 8900 8900 
 23024:       //    > cir 10 00000003
 23025:       //    > cir 00 ....
 23026:       //    A10C 8900 8900 8900 
 23027:       //    > cir 14 .
 23028:       //    0300 
 23029:       //    > cir 00 ..
 23030:       //    8900 8900 
 23031:       //    > cir 10 ...
 23032:       //    40060000 83000000 00000000 
 23033:       //    > cir 00 ..
 23034:       //    8900 8900 
 23035:       //    > cir 10 ...
 23036:       //    40060000 82000000 00000000 
 23037:       //    > cir 00 ..
 23038:       //    0802 0802 
 23039:       //    --------------------------------
 23040:       //    FPCP to memory, post-increment, static register list
 23041:       //    > cir 00 .
 23042:       //    0802 
 23043:       //    > cir 0a 4000
 23044:       //    > cir 00 ....
 23045:       //    9504 8900 8900 8900 
 23046:       //    > cir 10 00000084
 23047:       //    > cir 00 ..
 23048:       //    0802 0802 
 23049:       //    > cir 0a 4080
 23050:       //    > cir 00 ....
 23051:       //    9504 8900 8900 8900 
 23052:       //    > cir 10 00000085
 23053:       //    > cir 00 ..
 23054:       //    0802 0802 
 23055:       //    > cir 0a f0c0
 23056:       //    > cir 00 ....
 23057:       //    8900 A10C 8900 8900 
 23058:       //    > cir 14 .
 23059:       //    C000 
 23060:       //    > cir 00 ..
 23061:       //    8900 8900 
 23062:       //    > cir 10 ...
 23063:       //    40060000 84000000 00000000 
 23064:       //    > cir 00 ..
 23065:       //    8900 8900 
 23066:       //    > cir 10 ...
 23067:       //    40060000 85000000 00000000 
 23068:       //    > cir 00 ..
 23069:       //    0802 0802 
 23070:       //    --------------------------------
 23071:       //    FPCP to memory, post-increment, dynamic register list
 23072:       //    > cir 00 .
 23073:       //    0802 
 23074:       //    > cir 0a 4000
 23075:       //    > cir 00 ....
 23076:       //    9504 8900 8900 8900 
 23077:       //    > cir 10 00000086
 23078:       //    > cir 00 ..
 23079:       //    0802 0802 
 23080:       //    > cir 0a 4080
 23081:       //    > cir 00 ....
 23082:       //    9504 8900 8900 8900 
 23083:       //    > cir 10 00000087
 23084:       //    > cir 00 ..
 23085:       //    0802 0802 
 23086:       //    > cir 0a f870
 23087:       //    > cir 00 ....
 23088:       //    8C07 8900 8900 8900 
 23089:       //    > cir 10 000000c0
 23090:       //    > cir 00 ....
 23091:       //    A10C 8900 8900 8900 
 23092:       //    > cir 14 .
 23093:       //    C000 
 23094:       //    > cir 00 ..
 23095:       //    8900 8900 
 23096:       //    > cir 10 ...
 23097:       //    40060000 86000000 00000000 
 23098:       //    > cir 00 ..
 23099:       //    8900 8900 
 23100:       //    > cir 10 ...
 23101:       //    40060000 87000000 00000000 
 23102:       //    > cir 00 ..
 23103:       //    0802 0802 
 23104:       //    --------------------------------
 23105:       if (cirStage == CIR_IDLE) {  //開始
 23106:         if ((cirCommand & 0x0700) != 0) {
 23107:           cirException (0x1c0b);  //F-line emulator
 23108:           return;
 23109:         }
 23110:         if ((mmm & 2) == 0) {  //静的レジスタリスト
 23111:           cirRegisterList = cirCommand & 255;
 23112:           cirResponse = 0x8900_a10c;  //複数レジスタを出力する→come_again
 23113:           cirStage = CIR_REGISTER_SELECT;  //レジスタセレクト転送開始
 23114:         } else {  //動的レジスタリスト
 23115:           cirResponse = 0x8900_8c00 + (cirCommand >> 4 & 7);  //データレジスタを入力する→come-again
 23116:           cirOperandLength = 1;
 23117:           cirOperandIndex = 0;
 23118:           cirStage = CIR_DYNAMIC_REGISTER_LIST;  //動的レジスタリスト転送開始
 23119:         }
 23120:         return;
 23121:       }
 23122:       if (cirStage == CIR_DYNAMIC_REGISTER_LIST) {  //動的レジスタリスト転送終了
 23123:         cirRegisterList = cirOperandBuffer[0] & 255;
 23124:         cirResponse = 0x8900_a10c;  //複数レジスタを出力する→come_again
 23125:         cirStage = CIR_REGISTER_SELECT;  //レジスタセレクト転送開始
 23126:         return;
 23127:       }
 23128:       if (cirStage == CIR_REGISTER_SELECT) {  //レジスタセレクト転送終了
 23129:         if (cirRegisterList == 0) {  //転送するレジスタがない
 23130:           //終了
 23131:           cirIdle (0x0802);
 23132:           return;
 23133:         }
 23134:         int n, p;
 23135:         if ((cirCommand & 0x1000) == 0) {  //プレデクリメント。リストはFP7|…|FP0、転送順序はFP7→FP0、オペランドバッファはFP0,…,FP7
 23136:           n = 7;
 23137:           p = -1;
 23138:         } else {  //ポストインクリメント。リストはFP0|…|FP7、転送順序はFP0→FP7、オペランドバッファはFP7,…,FP0
 23139:           n = 0;
 23140:           p = 1;
 23141:         }
 23142:         int i = 0;
 23143:         byte[] b = new byte[12];
 23144:         for (int list = cirRegisterList << 24; list != 0; n += p, list <<= 1) {
 23145:           if (list < 0) {
 23146:             if (epbIsTriple ()) {  //三倍精度
 23147:               epbFPn[n].gety012 (b, 0, epbRoundingMode);
 23148:             } else {  //拡張精度
 23149:               epbFPn[n].getx012 (b, 0, epbRoundingMode);
 23150:             }
 23151:             cirOperandBuffer[i] = b[0] << 24 | (b[1] & 255) << 16 | (char) (b[2] << 8 | b[3] & 255);
 23152:             cirOperandBuffer[i + 1] = b[4] << 24 | (b[5] & 255) << 16 | (char) (b[6] << 8 | b[7] & 255);
 23153:             cirOperandBuffer[i + 2] = b[8] << 24 | (b[9] & 255) << 16 | (char) (b[10] << 8 | b[11] & 255);
 23154:             i += 3;
 23155:           }
 23156:         }
 23157:         cirOperandLength = i;
 23158:         cirOperandIndex = 0;
 23159:         cirStage = CIR_DESTINATION_OPERAND;  //デスティネーションオペランド転送開始
 23160:         return;
 23161:       }
 23162:       //if (cirStage == CIR_DESTINATION_OPERAND)
 23163:       {  //デスティネーションオペランド転送終了
 23164:         //終了
 23165:         cirIdle (0x0802);
 23166:         return;
 23167:       }
 23168:       //break;
 23169: 
 23170: 
 23171:     case 0b001:  //$2xxx-$3xxx: 未定義
 23172:     default:
 23173:       cirException (0x1c0b);  //F-line emulator
 23174:       return;
 23175:     }
 23176: 
 23177:   }  //cirGen()
 23178: 
 23179: 
 23180:   //cirPreInstruction ()
 23181:   //  浮動小数点命令実行前例外
 23182:   //  優先順位はBSUN>SNAN>OPERR>OVFL>UNFL>DZ>INEX2/INEX1
 23183:   //  複数の例外が同時に発生したときは最上位の例外ハンドラだけが呼び出される
 23184:   //  浮動小数点例外ハンドラは自分よりも下位の浮動小数点例外が発生していないか確認しなければならない
 23185:   public boolean cirPreInstruction () {
 23186:     //FPSRのAEXCを更新する
 23187:     epbFpsr |= XEiJ.FPU_FPSR_EXC_TO_AEXC[epbFpsr >> 8 & 255];
 23188:     //浮動小数点命令実行前例外 floating-point pre-instruction exception
 23189:     int mask = epbFpcr & epbFpsr & 0x0000ff00;
 23190:     if (mask == 0) {
 23191:       return false;
 23192:     }
 23193:     if ((short) mask < 0) {  //BSUN。(mask & 0x00008000) != 0
 23194:       cirException (0x5c30);  //分岐または比較不能状態でのセット branch or set on unordered
 23195:     } else if (mask << 17 < 0) {  //SNAN。(mask & 0x00004000) != 0
 23196:       cirException (0x1c36);  //シグナリングNAN signaling nan
 23197:     } else if (mask << 18 < 0) {  //OPERR。(mask & 0x00002000) != 0
 23198:       cirException (0x1c34);  //オペランドエラー operand error
 23199:     } else if (mask << 19 < 0) {  //OVFL。(mask & 0x00001000) != 0
 23200:       cirException (0x1c35);  //オーバーフロー overflow
 23201:     } else if (mask << 20 < 0) {  //UNFL。(mask & 0x00000800) != 0
 23202:       cirException (0x1c33);  //アンダーフロー underflow
 23203:     } else if (mask << 21 < 0) {  //DZ。(mask & 0x00000400) != 0
 23204:       cirException (0x1c32);  //ゼロによる除算 floating-point divide by zero
 23205:     } else {  //INEX1,INEX2。(mask & 0x00000300) != 0
 23206:       cirException (0x1c31);  //不正確な結果 inexact result
 23207:     }
 23208:     return true;
 23209:   }  //cirPreInstruction()
 23210: 
 23211:   //cirMidInstruction ()
 23212:   //  浮動小数点命令実行中例外
 23213:   //  優先順位はBSUN>SNAN>OPERR>OVFL>UNFL>DZ>INEX2/INEX1
 23214:   //  複数の例外が同時に発生したときは最上位の例外ハンドラだけが呼び出される
 23215:   //  浮動小数点例外ハンドラは自分よりも下位の浮動小数点例外が発生していないか確認しなければならない
 23216:   public boolean cirMidInstruction () {
 23217:     //FPSRのAEXCを更新する
 23218:     epbFpsr |= XEiJ.FPU_FPSR_EXC_TO_AEXC[epbFpsr >> 8 & 255];
 23219:     //浮動小数点命令実行中例外 floating-point mid-instruction exception
 23220:     int mask = epbFpcr & epbFpsr & 0x0000ff00;
 23221:     if (mask == 0) {
 23222:       return false;
 23223:     }
 23224:     if ((short) mask < 0) {  //BSUN。(mask & 0x00008000) != 0
 23225:       cirException (0x5d30);  //分岐または比較不能状態でのセット branch or set on unordered
 23226:     } else if (mask << 17 < 0) {  //SNAN。(mask & 0x00004000) != 0
 23227:       cirException (0x1d36);  //シグナリングNAN signaling nan
 23228:     } else if (mask << 18 < 0) {  //OPERR。(mask & 0x00002000) != 0
 23229:       cirException (0x1d34);  //オペランドエラー operand error
 23230:     } else if (mask << 19 < 0) {  //OVFL。(mask & 0x00001000) != 0
 23231:       cirException (0x1d35);  //オーバーフロー overflow
 23232:     } else if (mask << 20 < 0) {  //UNFL。(mask & 0x00000800) != 0
 23233:       cirException (0x1d33);  //アンダーフロー underflow
 23234:     } else if (mask << 21 < 0) {  //DZ。(mask & 0x00000400) != 0
 23235:       cirException (0x1d32);  //ゼロによる除算 floating-point divide by zero
 23236:     } else {  //INEX1,INEX2。(mask & 0x00000300) != 0
 23237:       cirException (0x1d31);  //不正確な結果 inexact result
 23238:     }
 23239:     return true;
 23240:   }  //cirMidInstruction()
 23241: 
 23242: 
 23243: 
 23244: }  //class EPB
 23245: 
 23246: 
 23247: