Ignore:
Timestamp:
Aug 15, 2008, 1:00:15 AM (16 years ago)
Author:
イグトランス (egtra)
Message:

数学関数をActiveBasic.Mathへ統合

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ab5.0/ablib/src/basic/function.sbp

    r581 r589  
    22
    33Const _System_PI = 3.14159265358979323846264
    4 Const _System_LOG2 = 0.6931471805599453094172321214581765680755
    54Const _System_SQRT2 = 1.41421356237309504880168872421
    6 Const _System_Log_N = 7 As Long
    75
    86'------------- サポート関数の定義 -------------
    97
    10 Function ldexp(x As Double, n As Long) As Double
    11     If x = 0 Then
    12         ldexp = 0
    13         Exit Function
    14     End If
    15     Dim pSrc = VarPtr(x) As *QWord
    16     Dim pDest = VarPtr(ldexp) As *QWord
    17     n += (pSrc[0] >> 52) As DWord And &h7FF
    18     pDest[0] = n << 52 Or (pSrc[0] And &h800FFFFFFFFFFFFF)
    19 End Function
    20 
    21 Function frexp(x As Double, ByRef n As Long) As Double
    22     If x = 0 Then
    23         n = 0
    24         frexp = 0
    25         Exit Function
    26     End If
    27 
    28     Dim pSrc = VarPtr(x) As *QWord
    29     Dim pDest = VarPtr(frexp) As *QWord
    30     n = ((pSrc[0] >> 52) As DWord And &h7FF) - 1022
    31     pDest[0] = (pSrc[0] And &h800FFFFFFFFFFFFF) Or &h3FE0000000000000
    32 End Function
    33 
    34 Function frexp(x As Single, ByRef n As Long) As Single
    35     If x = 0 Then
    36         n = 0
    37         frexp = 0
    38         Exit Function
    39     End If
    40 
    41     Dim pSrc As *DWord, pDest As *DWord
    42     pSrc = VarPtr(x) As *DWord
    43     pDest = VarPtr(frexp) As *DWord
    44     n = ((pSrc[0] >> 23) And &hFF) - 126
    45     pDest[0] = (pSrc[0] And &h807FFFFF) Or &h7E000000
    46 End Function
    47 
    488Function ipow(x As Double, n As Long) As Double
    49     Dim abs_n As Long
    50     Dim r = 1 As Double
    51 
    52     abs_n=Abs(n) As Long
    53     While abs_n<>0
    54         If abs_n and 1 Then r *= x
    55         x = x * x
    56         abs_n >>= 1 ' abs_n \= 2
    57     Wend
    58 
    59     If n>=0 Then
    60         ipow=r
    61     Else
    62         ipow=1/r
    63     End If
     9    ipow = ActiveBasic.Math.pow(x, n)
    6410End Function
    6511
    6612Function pow(x As Double, y As Double) As Double
    67 '   If -LONG_MAX<=y and y<=LONG_MAX and y=CDbl(Int(y)) Then
    68     If y = (y As Long) Then
    69         pow = ipow(x, y As Long)
    70     ElseIf x>0 Then
    71         pow = Exp(y * Log(x))
    72         Exit Function
    73     ElseIf x<>0 or y<=0 Then
    74         pow = ActiveBasic.Math.Detail.GetNaN()
    75     Else
    76         pow = 0
    77     End If
     13    pow = ActiveBasic.Math.pow(x, y)
    7814End Function
    7915
     
    8925    _System_RndNext = dwSeek
    9026End Sub
    91 
    9227
    9328'------------- ここからBasic標準関数の定義 -------------
     
    15489'----------
    15590
    156 Function Abs(number As Double) As Double
    157     'Abs = System.Math.Abs(number)
    158     If number < 0 then
    159         Abs = -number
    160     Else
    161         Abs = number
    162     End If
    163 End Function
    164 
    165 Function Abs(number As Int64) As Int64
    166     If number < 0 then
    167         Abs = -number
    168     Else
    169         Abs = number
    170     End If
    171 End Function
    172 
    173 Function Abs(number As Long) As Long
    174     If number < 0 then
    175         Abs = -number
    176     Else
    177         Abs = number
    178     End If
     91/*
     92Function Abs(n As Double) As Double
     93    Abs = ActiveBasic.Math.Abs(n)
     94End Function
     95
     96Function Abs(n As Single) As Single
     97    Abs = ActiveBasic.Math.Abs(n)
     98End Function
     99
     100Function Abs(n As Int64) As Int64
     101    Abs = ActiveBasic.Math.Abs(n)
     102End Function
     103
     104Function Abs(n As Long) As Long
     105    Abs = ActiveBasic.Math.Abs(n)
     106End Function
     107
     108Function Abs(n As Integer) As Integer
     109    Abs = ActiveBasic.Math.Abs(n)
     110End Function
     111
     112Function Abs(n As SByte) As SByte
     113    Abs = ActiveBasic.Math.Abs(n)
    179114End Function
    180115
    181116Function Exp(x As Double) As Double
    182     Exp = System.Math.Exp(x)
     117    Exp = ActiveBasic.Math.Exp(x)
    183118End Function
    184119
    185120Function Log(x As Double) As Double
    186     Log = System.Math.Log(x)
    187 End Function
    188 
    189 Function Sgn(number As Double) As Long
    190     Sgn = System.Math.Sign(number)
    191 End Function
    192 
    193 Function Sqr(number As Double) As Double
    194     Sqr = System.Math.Sqrt(number)
    195 End Function
    196 
    197 Function Atn(number As Double) As Double
    198     Atn = System.Math.Atan(number)
     121    Log = ActiveBasic.Math.Log(x)
     122End Function
     123*/
     124Function Sgn(n As Double) As Long
     125'   Sgn = ActiveBasic..Math.Sign(n)
     126End Function
     127
     128Function Sqr(x As Double) As Double
     129    Sqr = ActiveBasic.Math.Sqrt(x)
     130End Function
     131
     132Function Atn(x As Double) As Double
     133    Atn = ActiveBasic.Math.Atan(x)
    199134End Function
    200135
    201136Function Atn2(y As Double, x As Double) As Double
    202     Atn2 = System.Math.Atan2(y, x)
    203 End Function
    204 
    205 Function Sin(number As Double) As Double
    206     Sin = System.Math.Sin(number)
    207 End Function
    208 
    209 Function Cos(number As Double) As Double
    210     Cos = System.Math.Cos(number)
    211 End Function
    212 
    213 Function Tan(number As Double) As Double
    214     Tan = System.Math.Tan(number)
    215 End Function
    216 
     137    Atn2 = ActiveBasic.Math.Atan2(y, x)
     138End Function
     139/*
     140Function Sin(x As Double) As Double
     141    Sin = ActiveBasic.Math.Sin(x)
     142End Function
     143
     144Function Cos(x As Double) As Double
     145    Cos = ActiveBasic.Math.Cos(x)
     146End Function
     147
     148Function Tan(x As Double) As Double
     149    Tan = ActiveBasic.Math.Tan(x)
     150End Function
     151*/
    217152Const RAND_UNIT = (1.0 / (LONG_MAX + 1.0))
    218153Function Rnd() As Double
Note: See TracChangeset for help on using the changeset viewer.