[BACK]Return to multprec_mathematical_functions.adb CVS log [TXT][DIR] Up to [local] / OpenXM_contrib / PHC / Ada / Math_Lib / Numbers

Annotation of OpenXM_contrib/PHC/Ada/Math_Lib/Numbers/multprec_mathematical_functions.adb, Revision 1.1.1.1

1.1       maekawa     1: with text_io;                            use text_io;
                      2: with Multprec_Floating_Numbers_io;       use Multprec_Floating_Numbers_io;
                      3:
                      4: with Standard_Floating_Numbers;          use Standard_Floating_Numbers;
                      5: with Standard_Mathematical_Functions;    use Standard_Mathematical_Functions;
                      6:
                      7: package body Multprec_Mathematical_Functions is
                      8:
                      9: -- EXPONENTIAL AND LOGARITHMIC FUNCTIONS :
                     10:
                     11:   function "**" ( x,y : Floating_Number ) return Floating_Number is
                     12:
                     13:     res : Floating_Number;
                     14:     sx : double_float := Round(x);
                     15:     sy : double_float := Round(y);
                     16:
                     17:   begin
                     18:     sx := sx**sy;
                     19:     res := Create(sx);
                     20:     return res;
                     21:   end "**";
                     22:
                     23:   function LOG2 ( x : Floating_Number ) return Floating_Number is
                     24:
                     25:     res : Floating_Number;
                     26:     sx : double_float := Round(x);
                     27:
                     28:   begin
                     29:     sx := LOG2(sx);
                     30:     res := Create(sx);
                     31:     return res;
                     32:   end LOG2;
                     33:
                     34:   function LOG10 ( x : Floating_Number ) return Floating_Number is
                     35:
                     36:     res : Floating_Number;
                     37:     sx : double_float := Round(x);
                     38:
                     39:   begin
                     40:     sx := LOG10(sx);
                     41:     res := Create(sx);
                     42:     return res;
                     43:   end LOG10;
                     44:
                     45:   function SQRT ( x : Floating_Number ) return Floating_Number is
                     46:
                     47:     res : Floating_Number;
                     48:     sx : double_float := Round(x);
                     49:     sizex : natural := Size_Fraction(x);
                     50:     sizeres : natural;
                     51:
                     52:     procedure Iterate ( a : in Floating_Number ) is
                     53:
                     54:       oneres,twores : Floating_Number;
                     55:
                     56:     begin
                     57:       for i in 1..3 loop
                     58:         Copy(res,oneres);      put("init   : "); put(oneres); new_line;
                     59:         twores := 2.0*oneres;  put("2*init : "); put(twores); new_line;
                     60:         Mul(res,res);
                     61:         Sub(res,a);       put("residual : "); put(res); new_line;
                     62:         Div(res,twores);  put("inc : "); put(res); new_line;
                     63:         twores := oneres - res;
                     64:         Copy(twores,res);
                     65:         Clear(twores); Clear(oneres);
                     66:       end loop;
                     67:     end Iterate;
                     68:
                     69:   begin
                     70:     sx := SQRT(sx);
                     71:     res := Create(sx);
                     72:     sizeres := Size_Fraction(res);
                     73:     if (sx /= 0.0) and (sizeres < sizex)
                     74:      then Expand(res,sizex-sizeres);
                     75:           if sx >= 1.0
                     76:            then Iterate(x);
                     77:            else declare
                     78:                   invx : Floating_Number := 1.0/x;
                     79:                   invres : Floating_Number := 1.0/res;
                     80:                 begin
                     81:                   Copy(invres,res);  Clear(invres);
                     82:                   Iterate(invx);
                     83:                   invres := 1.0/res;
                     84:                   Copy(invres,res);  Clear(invres);
                     85:                 end;
                     86:           end if;
                     87:     end if;
                     88:     return res;
                     89:   end SQRT;
                     90:
                     91: -- TRIGONOMETRIC FUNCTIONS :
                     92:
                     93:   function SIN ( x : Floating_Number ) return Floating_Number is
                     94:
                     95:     res : Floating_Number;
                     96:     sx : double_float := Round(x);
                     97:
                     98:   begin
                     99:     sx := SIN(sx);
                    100:     res := Create(sx);
                    101:     return res;
                    102:   end SIN;
                    103:
                    104:   function COS ( x : Floating_Number ) return Floating_Number is
                    105:
                    106:     res : Floating_Number;
                    107:     sx : double_float := Round(x);
                    108:
                    109:   begin
                    110:     sx := COS(sx);
                    111:     res := Create(sx);
                    112:     return res;
                    113:   end COS;
                    114:
                    115:   function TAN ( x : Floating_Number ) return Floating_Number is
                    116:
                    117:     res : Floating_Number;
                    118:     sx : double_float := Round(x);
                    119:
                    120:   begin
                    121:     sx := TAN(sx);
                    122:     res := Create(sx);
                    123:     return res;
                    124:   end TAN;
                    125:
                    126:   function ARCSIN ( x : Floating_Number ) return Floating_Number is
                    127:
                    128:     res : Floating_Number;
                    129:     sx : double_float := Round(x);
                    130:
                    131:   begin
                    132:     sx := ARCSIN(sx);
                    133:     res := Create(sx);
                    134:     return res;
                    135:   end ARCSIN;
                    136:
                    137:   function ARCCOS ( x : Floating_Number ) return Floating_Number is
                    138:
                    139:     res : Floating_Number;
                    140:     sx : double_float := Round(x);
                    141:
                    142:   begin
                    143:     sx := ARCCOS(sx);
                    144:     res := Create(sx);
                    145:     return res;
                    146:   end ARCCOS;
                    147:
                    148:   function ARCTAN ( x : Floating_Number ) return Floating_Number is
                    149:
                    150:     res : Floating_Number;
                    151:     sx : double_float := Round(x);
                    152:
                    153:   begin
                    154:     sx := ARCTAN(sx);
                    155:     res := Create(sx);
                    156:     return res;
                    157:   end ARCTAN;
                    158:
                    159:   function Radius ( x,y : Floating_Number ) return Floating_Number is
                    160:
                    161:     res : Floating_Number;
                    162:     sx : double_float := Round(x);
                    163:     sy : double_float := Round(y);
                    164:
                    165:   begin
                    166:     sx := Radius(sx,sy);
                    167:     res := Create(sx);
                    168:     return res;
                    169:   end Radius;
                    170:
                    171:   function Angle  ( x,y : Floating_Number ) return Floating_Number is
                    172:
                    173:     res : Floating_Number;
                    174:     sx : double_float := Round(x);
                    175:     sy : double_float := Round(y);
                    176:
                    177:   begin
                    178:     sx := Angle(sx,sy);
                    179:     res := Create(sx);
                    180:     return res;
                    181:   end Angle;
                    182:
                    183: end Multprec_Mathematical_Functions;

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