Index: trunk/ab5.0/ablib/src/Classes/System/Math.ab
===================================================================
--- trunk/ab5.0/ablib/src/Classes/System/Math.ab	(revision 506)
+++ trunk/ab5.0/ablib/src/Classes/System/Math.ab	(revision 589)
@@ -24,5 +24,5 @@
 
 	Static Function Abs(value As SByte) As SByte
-		If value<0 then
+		If value<0 Then
 			return -value
 		Else
@@ -32,5 +32,5 @@
 
 	Static Function Abs(value As Integer) As Integer
-		If value<0 then
+		If value<0 Then
 			return -value
 		Else
@@ -40,5 +40,5 @@
 
 	Static Function Abs(value As Long) As Long
-		If value<0 then
+		If value<0 Then
 			return -value
 		Else
@@ -48,5 +48,5 @@
 
 	Static Function Abs(value As Int64) As Int64
-		If value<0 then
+		If value<0 Then
 			return -value
 		Else
@@ -56,65 +56,17 @@
 
 	Static Function Acos(x As Double) As Double
-		If x < -1 Or x > 1 Then
-			Acos = ActiveBasic.Math.Detail.GetNaN()
-		Else
-			Acos = _System_HalfPI - Asin(x)
-		End If
+		Acos = ActiveBasic.Math.Acos(x)
 	End Function
 
 	Static Function Asin(x As Double) As Double
-		If x < -1 Or x > 1 Then
-			Asin = ActiveBasic.Math.Detail.GetNaN()
-		Else
-			Asin = Math.Atan(x / Sqrt(1 - x * x))
-		End If
+		Asin = ActiveBasic.Math.Asin(x)
 	End Function
 
 	Static Function Atan(x As Double) As Double
-		If ActiveBasic.Math.IsNaN(x) Then
-			Atan = x
-			Exit Function
-		ElseIf ActiveBasic.Math.IsInf(x) Then
-			Atan = ActiveBasic.Math.CopySign(_System_PI, x)
-			Exit Function
-		End If
-		Dim i As Long
-		Dim sgn As Long
-		Dim dbl = 0 As Double
-
-		If x > 1 Then
-			sgn = 1
-			x = 1 / x
-		ElseIf x < -1 Then
-			sgn = -1
-			x = 1 / x
-		Else
-			sgn = 0
-		End If
-
-		For i = _System_Atan_N To 1 Step -1
-			Dim t As Double
-			t = i * x
-			dbl = (t * t) / (2 * i + 1 + dbl)
-		Next
-
-		If sgn > 0 Then
-			Atan = _System_HalfPI - x / (1 + dbl)
-		ElseIf sgn < 0 Then
-			Atan = -_System_HalfPI - x / (1 + dbl)
-		Else
-			Atan = x / (1 + dbl)
-		End If
+		Atan = ActiveBasic.Math.Atan(x)
 	End Function
 
 	Static Function Atan2(y As Double, x As Double) As Double
-		If x = 0 Then
-			Atan2 = Sgn(y) * _System_HalfPI
-		Else
-			Atan2 = Atn(y / x)
-			If x < 0 Then
-				Atan2 += ActiveBasic.Math.CopySign(_System_PI, y)
-			End If
-		End If
+		Atan2 = ActiveBasic.Math.Atan2(y, x)
 	End Function
 
@@ -131,21 +83,15 @@
 
 	Static Function Cos(x As Double) As Double
-		If ActiveBasic.Math.IsNaN(x) Then
-			Return x
-		ElseIf ActiveBasic.Math.IsInf(x) Then
-			Return ActiveBasic.Math.Detail.GetNaN()
-		End If
-
-		Return Math.Sin((_System_HalfPI - Math.Abs(x)) As Double)
+		Cos = ActiveBasic.Math.Cos(x)
 	End Function
 
 	Static Function Cosh(value As Double) As Double
 		Dim t = Math.Exp(value)
-		return (t + 1 / t) * 0.5
+		Return (t + 1 / t) * 0.5
 	End Function
 
 	Static Function DivRem(x As Long, y As Long, ByRef ret As Long) As Long
 		ret = x Mod y
-		return x \ y
+		Return x \ y
 	End Function
 
@@ -155,35 +101,6 @@
 	End Function
 
-	'Equals
-
 	Static Function Exp(x As Double) As Double
-		If ActiveBasic.Math.IsNaN(x) Then
-			Return x
-		Else If ActiveBasic.Math.IsInf(x) Then
-			If 0 > x Then
-				Return 0
-			Else
-				Return x
-			End If
-		End If
-		Dim k As Long
-		If x >= 0 Then
-			k = Fix(x / _System_LOG2 + 0.5)
-		Else
-			k = Fix(x / _System_LOG2 - 0.5)
-		End If
-
-		x -= k * _System_LOG2
-
-		Dim x2 = x * x
-		Dim w = x2 / 22
-
-		Dim i = 18
-		While i >= 6
-			w = x2 / (w + i)
-			i -= 4
-		Wend
-
-		Return ldexp((2 + w + x) / (2 + w - x), k)
+		Exp = ActiveBasic.Math.Exp(x)
 	End Function
 
@@ -216,27 +133,13 @@
 
 	Static Function Log(x As Double) As Double
-		If x = 0 Then
-			Log = ActiveBasic.Math.Detail.GetInf(True)
-		ElseIf x < 0 Or ActiveBasic.Math.IsNaN(x) Then
-			Log = ActiveBasic.Math.Detail.GetNaN()
-		ElseIf ActiveBasic.Math.IsInf(x) Then
-			Log = x
-		Else
-			Dim tmp = x * _System_InverseSqrt2
-			Dim p = VarPtr(tmp) As *QWord
-			Dim m = GetQWord(p) And &h7FF0000000000000
-			Dim k = ((m >> 52) As DWord) As Long - 1022
-			SetQWord(p, m + &h0010000000000000)
-			x /= tmp
-			Log = _System_LOG2 * k + ActiveBasic.Math.Detail.Log1p(x - 1)
-		End If
+		Log = ActiveBasic.Math.Log(x)
 	End Function
 
 	Static Function Log10(x As Double) As Double
-		Return Math.Log(x) * _System_InverseLn10
+		Log = ActiveBasic.Math.Log10(x)
 	End Function
 
 	Static Function Max(value1 As Byte, value2 As Byte) As Byte
-		If value1>value2 then
+		If value1>value2 Then
 			return value1
 		Else
@@ -246,5 +149,5 @@
 
 	Static Function Max(value1 As SByte, value2 As SByte) As SByte
-		If value1>value2 then
+		If value1>value2 Then
 			return value1
 		Else
@@ -254,5 +157,5 @@
 
 	Static Function Max(value1 As Word, value2 As Word) As Word
-		If value1>value2 then
+		If value1>value2 Then
 			return value1
 		Else
@@ -262,5 +165,5 @@
 
 	Static Function Max(value1 As Integer, value2 As Integer) As Integer
-		If value1>value2 then
+		If value1>value2 Then
 			return value1
 		Else
@@ -270,5 +173,5 @@
 
 	Static Function Max(value1 As DWord, value2 As DWord) As DWord
-		If value1>value2 then
+		If value1>value2 Then
 			return value1
 		Else
@@ -278,5 +181,5 @@
 
 	Static Function Max(value1 As Long, value2 As Long) As Long
-		If value1>value2 then
+		If value1>value2 Then
 			return value1
 		Else
@@ -286,5 +189,5 @@
 
 	Static Function Max(value1 As QWord, value2 As QWord) As QWord
-		If value1>value2 then
+		If value1>value2 Then
 			return value1
 		Else
@@ -294,5 +197,5 @@
 
 	Static Function Max(value1 As Int64, value2 As Int64) As Int64
-		If value1>value2 then
+		If value1>value2 Then
 			return value1
 		Else
@@ -302,5 +205,5 @@
 
 	Static Function Max(value1 As Single, value2 As Single) As Single
-		If value1>value2 then
+		If value1>value2 Then
 			return value1
 		Else
@@ -310,5 +213,5 @@
 
 	Static Function Max(value1 As Double, value2 As Double) As Double
-		If value1>value2 then
+		If value1>value2 Then
 			return value1
 		Else
@@ -318,5 +221,5 @@
 
 	Static Function Min(value1 As Byte, value2 As Byte) As Byte
-		If value1<value2 then
+		If value1<value2 Then
 			return value1
 		Else
@@ -326,5 +229,5 @@
 
 	Static Function Min(value1 As SByte, value2 As SByte) As SByte
-		If value1<value2 then
+		If value1<value2 Then
 			return value1
 		Else
@@ -334,5 +237,5 @@
 
 	Static Function Min(value1 As Word, value2 As Word) As Word
-		If value1<value2 then
+		If value1<value2 Then
 			return value1
 		Else
@@ -342,5 +245,5 @@
 
 	Static Function Min(value1 As Integer, value2 As Integer) As Integer
-		If value1<value2 then
+		If value1<value2 Then
 			return value1
 		Else
@@ -350,5 +253,5 @@
 
 	Static Function Min(value1 As DWord, value2 As DWord) As DWord
-		If value1<value2 then
+		If value1<value2 Then
 			return value1
 		Else
@@ -358,5 +261,5 @@
 
 	Static Function Min(value1 As Long, value2 As Long) As Long
-		If value1<value2 then
+		If value1<value2 Then
 			return value1
 		Else
@@ -366,5 +269,5 @@
 
 	Static Function Min(value1 As QWord, value2 As QWord) As QWord
-		If value1<value2 then
+		If value1<value2 Then
 			return value1
 		Else
@@ -374,5 +277,5 @@
 
 	Static Function Min(value1 As Int64, value2 As Int64) As Int64
-		If value1<value2 then
+		If value1<value2 Then
 			return value1
 		Else
@@ -382,5 +285,5 @@
 
 	Static Function Min(value1 As Single, value2 As Single) As Single
-		If value1<value2 then
+		If value1<value2 Then
 			return value1
 		Else
@@ -390,5 +293,5 @@
 
 	Static Function Min(value1 As Double, value2 As Double) As Double
-		If value1<value2 then
+		If value1<value2 Then
 			return value1
 		Else
@@ -404,7 +307,7 @@
 
 	Static Function Round(value As Double) As Double'他のバージョン、誰か頼む。
-		If value+0.5<>Int(value+0.5) then
+		If value+0.5<>Int(value+0.5) Then
 			value=Int(value+0.5)
-		ElseIf Int(value+0.5)=Int(value*2+1)/2 then
+		ElseIf Int(value+0.5)=Int(value*2+1)/2 Then
 			value=Int(value+0.5)
 		Else
@@ -414,17 +317,17 @@
 
 	Static Function Sign(value As Double) As Long
-		If value = 0 then
-			return 0
-		ElseIf value > 0 then
-			return 1
-		Else
-			return -1
-		End If
-	End Function
-
+		If value = 0 Then
+			return 0
+		ElseIf value > 0 Then
+			return 1
+		Else
+			return -1
+		End If
+	End Function
+/*
 	Static Function Sign(value As SByte) As Long
-		If value = 0 then
-			return 0
-		ElseIf value > 0 then
+		If value = 0 Then
+			return 0
+		ElseIf value > 0 Then
 			return 1
 		Else
@@ -434,7 +337,7 @@
 
 	Static Function Sign(value As Integer) As Long
-		If value = 0 then
-			return 0
-		ElseIf value > 0 then
+		If value = 0 Then
+			return 0
+		ElseIf value > 0 Then
 			return 1
 		Else
@@ -444,7 +347,7 @@
 
 	Static Function Sign(value As Long) As Long
-		If value = 0 then
-			return 0
-		ElseIf value > 0 then
+		If value = 0 Then
+			return 0
+		ElseIf value > 0 Then
 			return 1
 		Else
@@ -454,7 +357,7 @@
 
 	Static Function Sign(value As Int64) As Long
-		If value = 0 then
-			return 0
-		ElseIf value > 0 then
+		If value = 0 Then
+			return 0
+		ElseIf value > 0 Then
 			return 1
 		Else
@@ -464,135 +367,37 @@
 
 	Static Function Sign(value As Single) As Long
-		If value = 0 then
-			return 0
-		ElseIf value > 0 then
-			return 1
-		Else
-			return -1
-		End If
-	End Function
-
-	Static Function Sin(value As Double) As Double
-		If ActiveBasic.Math.IsNaN(value) Then
-			Return value
-		ElseIf ActiveBasic.Math.IsInf(value) Then
-			Return ActiveBasic.Math.Detail.GetNaN()
-			Exit Function
-		End If
-
-		Dim k As Long
-		Dim t As Double
-
-		t = urTan((value * 0.5) As Double, k)
-		t = 2 * t / (1 + t * t)
-		If (k And 1) = 0 Then 'k mod 2 = 0 Then
-			Return t
-		Else
-			Return -t
-		End If
+		If value = 0 Then
+			return 0
+		ElseIf value > 0 Then
+			return 1
+		Else
+			return -1
+		End If
+	End Function
+*/
+	Static Function Sin(x As Double) As Double
+		Sin = ActiveBasic.Math.Sin(x)
 	End Function
 
 	Static Function Sinh(x As Double) As Double
-		If Math.Abs(x) > _System_EPS5 Then
-			Dim t As Double
-			t = Math.Exp(x)
-			Return (t - 1 / t) * 0.5
-		Else
-			Return x * (1 + x * x * 0.166666666666667) ' x * (1 + x * x / 6)
-		End If
+		Sinh = ActiveBasic.Math.Sinh(x)
 	End Function
 
 	Static Function Sqrt(x As Double) As Double
-		If x > 0 Then
-			If ActiveBasic.Math.IsInf(x) Then
-				Sqrt = x
-			Else
-				Sqrt = x
-				Dim i = (VarPtr(Sqrt) + 6) As *Word
-				Dim jj = GetWord(i) As Long
-				Dim j = jj >> 5 As Long
-				Dim k = (jj And &h0000001f) As Long
-				j = (j + 511) << 4 + k
-				SetWord(i, j)
-				Dim last As Double
-				Do
-					last = Sqrt
-					Sqrt = (x / Sqrt + Sqrt) * 0.5
-				Loop While Sqrt <> last
-			End If
-		ElseIf x < 0 Then
-			Sqrt = ActiveBasic.Math.Detail.GetNaN()
-		Else
-			'x = 0 Or NaN
-			Sqrt = x
-		End If
+		Sqrt = ActiveBasic.Math.Sqrt(x)
 	End Function
 
 	Static Function Tan(x As Double) As Double
-		If ActiveBasic.Math.IsNaN(x) Then
-			Tan = x
-			Exit Function
-		ElseIf ActiveBasic.Math.IsInf(x) Then
-			Tan = ActiveBasic.Math.Detail.GetNaN()
-			Exit Function
-		End If
-
-		Dim k As Long
-		Dim t As Double
-		t = urTan(x, k)
-		If (k And 1) = 0 Then 'k mod 2 = 0 Then
-			Return t
-		ElseIf t <> 0 Then
-			Return -1 / t
-		Else
-			Return ActiveBasic.Math.CopySign(ActiveBasic.Math.Detail.GetInf(False), -t)
-		End If
+		Tan = ActiveBasic.Math.Tan(x)
 	End Function
 
 	Static Function Tanh(x As Double) As Double
-		If x > _System_EPS5 Then
-			Return 2 / (1 + Math.Exp(-2 * x)) - 1
-		ElseIf x < -_System_EPS5 Then
-			Return 1 - 2 / (Math.Exp(2 * x) + 1)
-		Else
-			Return x * (1 - x * x * 0.333333333333333) 'x * (1 - x * x / 3)
-		End If
-	End Function
-
-	'ToString
+		Tanh = ActiveBasic.Math.Tanh(x)
+	End Function
 
 	Static Function Truncate(x As Double) As Double
 		Return Fix(x)
 	End Function
-
-'Private
-	Static Function urTan(x As Double, ByRef k As Long) As Double
-		Dim i As Long
-		Dim t As Double, x2 As Double
-
-		If x >= 0 Then
-			k = ( Fix(x * _System_InverseHalfPI) + 0.5 ) As Long
-		Else
-			k = ( Fix(x * _System_InverseHalfPI) - 0.5 ) As Long
-		End If
-		x = (x - (3217.0 / 2048.0) * k) + _System_D * k
-		x2 = x * x
-		t = 0
-		For i = _System_UrTan_N To 3 Step -2
-			t = x2 / (i - t)
-		Next i
-		urTan =  x / (1 - t)
-	End Function
-Private
-	Static Const _System_Atan_N = 20 As Long
-	Static Const _System_UrTan_N = 17 As Long
-	Static Const _System_D = 4.4544551033807686783083602485579e-6 As Double
-	Static Const _System_EPS5 = 0.001 As Double
 End Class
 
 End Namespace
-
-Const _System_HalfPI = (_System_PI * 0.5)
-Const _System_InverseHalfPI = (2 / _System_PI) '1 / (PI / 2)
-Const _System_InverseLn10 = 0.43429448190325182765112891891661 '1 / (ln 10)
-Const _System_InverseSqrt2 = 0.70710678118654752440084436210485 '1 / (√2)
