' Collection of code snippets by Arne Vajhøj 
' (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
﻿Imports System

Namespace E
    Public Class MyMath
        Private Const LOG2 As Double =  0.69314718055994530941
        Public Shared Function Log(x As Double) As Double
            If x > 1 Then
                Return LOG2 + Log(x / 2)
            ElseIf x < 0.5 Then
                Return Log(2 * x) - LOG2
            Else
                Dim res As Double = 0
                Dim q As Double = 1
                For i As Integer = 1 To 50
                    q *= (x - 1)
                    res += If(i Mod 2 = 1, 1, -1) * q / i
                Next
                Return res
            End If
        End Function
    End Class
    Public Class Program
        Public Shared Sub Main(args As String())
            Dim rng As New Random()
            For i As Integer = 0 To 9
                Dim x As Double = Math.Pow(10, i - 4) * rng.NextDouble()
                Console.WriteLine(x)
                Console.WriteLine(Math.Log(x))
                Console.WriteLine(MyMath.Log(x))
            Next
        End Sub
    End Class
End Namespace
