Ignore:
Timestamp:
May 11, 2007, 11:45:18 PM (17 years ago)
Author:
イグトランス (egtra)
Message:

Math.Logでfrexp, ldexpを使わないようにした

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Include/Classes/System/Math.ab

    r239 r244  
    133133        If IsNaN(x) Then
    134134            Return x
    135                 ElseIf IsInf(x) Then
     135        ElseIf IsInf(x) Then
    136136            Return _System_GetNaN()
    137137        End If
     
    224224    Static Function Log(x As Double) As Double
    225225        If x = 0 Then
    226             Log = _System_GetInf(TRUE)
     226            Log = _System_GetInf(True)
    227227        ElseIf x < 0 Or IsNaN(x) Then
    228228            Log = _System_GetNaN()
     
    230230            Log = x
    231231        Else
    232             Dim i As Long, k As Long
    233             Dim s As Double, t As Double
    234             frexp(x / _System_SQRT2, k)
    235             x /= ldexp(1, k)
     232            Dim tmp = x * _System_InverseSqrt2
     233            Dim p = VarPtr(tmp) As *QWord
     234            Dim m = p[0] And &h7FF0000000000000
     235            Dim k = ((m >> 52) As DWord) As Long - 1022
     236            p[0] = m + &h0010000000000000
     237            x /= tmp
    236238
    237239            x--
    238             s = 0
    239             i = _System_Log_N
     240            Dim s = 0 As Double
     241            Dim i = _System_Log_N As Long
    240242            While i >= 1
    241                 t = i * x
     243                Dim t = (i * x) As Double
    242244                s = t / (2 + t / (2 * i + 1 + s))
    243245                i--
    244246            Wend
    245 
    246247            Log = _System_LOG2 * k + x / (1 + s)
    247248        End If
     
    249250
    250251    Static Function Log10(x As Double) As Double
    251         Return Math.Log(x) / _System_Ln10
    252     End Function
    253 
    254     Static Function Max(value1 As Byte,value2 As Byte) As Byte
    255         If value1>value2 then
    256             return value1
    257         Else
    258             return value2
    259         End If
    260     End Function
    261 
    262     Static Function Max(value1 As SByte,value2 As SByte) As SByte
    263         If value1>value2 then
    264             return value1
    265         Else
    266             return value2
    267         End If
    268     End Function
    269 
    270     Static Function Max(value1 As Word,value2 As Word) As Word
    271         If value1>value2 then
    272             return value1
    273         Else
    274             return value2
    275         End If
    276     End Function
    277 
    278     Static Function Max(value1 As Integer,value2 As Integer) As Integer
    279         If value1>value2 then
    280             return value1
    281         Else
    282             return value2
    283         End If
    284     End Function
    285 
    286     Static Function Max(value1 As DWord,value2 As DWord) As DWord
    287         If value1>value2 then
    288             return value1
    289         Else
    290             return value2
    291         End If
    292     End Function
    293 
    294     Static Function Max(value1 As Long,value2 As Long) As Long
    295         If value1>value2 then
    296             return value1
    297         Else
    298             return value2
    299         End If
    300     End Function
    301 
    302     Static Function Max(value1 As QWord,value2 As QWord) As QWord
    303         If value1>value2 then
    304             return value1
    305         Else
    306             return value2
    307         End If
    308     End Function
    309 
    310     Static Function Max(value1 As Int64,value2 As Int64) As Int64
    311         If value1>value2 then
    312             return value1
    313         Else
    314             return value2
    315         End If
    316     End Function
    317 
    318     Static Function Max(value1 As Single,value2 As Single) As Single
    319         If value1>value2 then
    320             return value1
    321         Else
    322             return value2
    323         End If
    324     End Function
    325 
    326     Static Function Max(value1 As Double,value2 As Double) As Double
    327         If value1>value2 then
    328             return value1
    329         Else
    330             return value2
    331         End If
    332     End Function
    333 
    334     Static Function Min(value1 As Byte,value2 As Byte) As Byte
    335         If value1<value2 then
    336             return value1
    337         Else
    338             return value2
    339         End If
    340     End Function
    341 
    342     Static Function Min(value1 As SByte,value2 As SByte) As SByte
    343         If value1<value2 then
    344             return value1
    345         Else
    346             return value2
    347         End If
    348     End Function
    349 
    350     Static Function Min(value1 As Word,value2 As Word) As Word
    351         If value1<value2 then
    352             return value1
    353         Else
    354             return value2
    355         End If
    356     End Function
    357 
    358     Static Function Min(value1 As Integer,value2 As Integer) As Integer
    359         If value1<value2 then
    360             return value1
    361         Else
    362             return value2
    363         End If
    364     End Function
    365 
    366     Static Function Min(value1 As DWord,value2 As DWord) As DWord
    367         If value1<value2 then
    368             return value1
    369         Else
    370             return value2
    371         End If
    372     End Function
    373 
    374     Static Function Min(value1 As Long,value2 As Long) As Long
    375         If value1<value2 then
    376             return value1
    377         Else
    378             return value2
    379         End If
    380     End Function
    381 
    382     Static Function Min(value1 As QWord,value2 As QWord) As QWord
    383         If value1<value2 then
    384             return value1
    385         Else
    386             return value2
    387         End If
    388     End Function
    389 
    390     Static Function Min(value1 As Int64,value2 As Int64) As Int64
    391         If value1<value2 then
    392             return value1
    393         Else
    394             return value2
    395         End If
    396     End Function
    397 
    398     Static Function Min(value1 As Single,value2 As Single) As Single
    399         If value1<value2 then
    400             return value1
    401         Else
    402             return value2
    403         End If
    404     End Function
    405 
    406     Static Function Min(value1 As Double,value2 As Double) As Double
     252        Return Math.Log(x) * _System_InverseLn10
     253    End Function
     254
     255    Static Function Max(value1 As Byte, value2 As Byte) As Byte
     256        If value1>value2 then
     257            return value1
     258        Else
     259            return value2
     260        End If
     261    End Function
     262
     263    Static Function Max(value1 As SByte, value2 As SByte) As SByte
     264        If value1>value2 then
     265            return value1
     266        Else
     267            return value2
     268        End If
     269    End Function
     270
     271    Static Function Max(value1 As Word, value2 As Word) As Word
     272        If value1>value2 then
     273            return value1
     274        Else
     275            return value2
     276        End If
     277    End Function
     278
     279    Static Function Max(value1 As Integer, value2 As Integer) As Integer
     280        If value1>value2 then
     281            return value1
     282        Else
     283            return value2
     284        End If
     285    End Function
     286
     287    Static Function Max(value1 As DWord, value2 As DWord) As DWord
     288        If value1>value2 then
     289            return value1
     290        Else
     291            return value2
     292        End If
     293    End Function
     294
     295    Static Function Max(value1 As Long, value2 As Long) As Long
     296        If value1>value2 then
     297            return value1
     298        Else
     299            return value2
     300        End If
     301    End Function
     302
     303    Static Function Max(value1 As QWord, value2 As QWord) As QWord
     304        If value1>value2 then
     305            return value1
     306        Else
     307            return value2
     308        End If
     309    End Function
     310
     311    Static Function Max(value1 As Int64, value2 As Int64) As Int64
     312        If value1>value2 then
     313            return value1
     314        Else
     315            return value2
     316        End If
     317    End Function
     318
     319    Static Function Max(value1 As Single, value2 As Single) As Single
     320        If value1>value2 then
     321            return value1
     322        Else
     323            return value2
     324        End If
     325    End Function
     326
     327    Static Function Max(value1 As Double, value2 As Double) As Double
     328        If value1>value2 then
     329            return value1
     330        Else
     331            return value2
     332        End If
     333    End Function
     334
     335    Static Function Min(value1 As Byte, value2 As Byte) As Byte
     336        If value1<value2 then
     337            return value1
     338        Else
     339            return value2
     340        End If
     341    End Function
     342
     343    Static Function Min(value1 As SByte, value2 As SByte) As SByte
     344        If value1<value2 then
     345            return value1
     346        Else
     347            return value2
     348        End If
     349    End Function
     350
     351    Static Function Min(value1 As Word, value2 As Word) As Word
     352        If value1<value2 then
     353            return value1
     354        Else
     355            return value2
     356        End If
     357    End Function
     358
     359    Static Function Min(value1 As Integer, value2 As Integer) As Integer
     360        If value1<value2 then
     361            return value1
     362        Else
     363            return value2
     364        End If
     365    End Function
     366
     367    Static Function Min(value1 As DWord, value2 As DWord) As DWord
     368        If value1<value2 then
     369            return value1
     370        Else
     371            return value2
     372        End If
     373    End Function
     374
     375    Static Function Min(value1 As Long, value2 As Long) As Long
     376        If value1<value2 then
     377            return value1
     378        Else
     379            return value2
     380        End If
     381    End Function
     382
     383    Static Function Min(value1 As QWord, value2 As QWord) As QWord
     384        If value1<value2 then
     385            return value1
     386        Else
     387            return value2
     388        End If
     389    End Function
     390
     391    Static Function Min(value1 As Int64, value2 As Int64) As Int64
     392        If value1<value2 then
     393            return value1
     394        Else
     395            return value2
     396        End If
     397    End Function
     398
     399    Static Function Min(value1 As Single, value2 As Single) As Single
     400        If value1<value2 then
     401            return value1
     402        Else
     403            return value2
     404        End If
     405    End Function
     406
     407    Static Function Min(value1 As Double, value2 As Double) As Double
    407408        If value1<value2 then
    408409            return value1
     
    610611Const _System_HalfPI = (_System_PI * 0.5)
    611612Const _System_InverseHalfPI = (2 / _System_PI) '1 / (PI / 2)
    612 Const _System_Ln10 = 2.3025850929940456840179914546844 '10の自然対数
     613Const _System_InverseLn10 = 0.43429448190325182765112891891661 '1 / (ln 10)
     614Const _System_InverseSqrt2 = 0.70710678118654752440084436210485 '1 / (√2)
     615
    613616
    614617#endif '__SYSTEM_MATH_AB__
Note: See TracChangeset for help on using the changeset viewer.