Attribute VB_Name = "LogBase10"
' Copyright © 2019 John S. Philo
' This file is part of the program SEDNTERP 1. SEDNTERP 1 is free software: you can redistribute it and/or modify
' it under the terms of the GNU General Public License as published by the Free Software Foundation,
' either version 3 Of the License, or any later version. The author asks only that if you use any of
' this code in your own programs then please acknowledge that use and cite any appropriate publications.
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
' GNU General Public License for more details.
' You should have received a copy of the GNU General Public License
' along with this program (the file Copying.txt). If not, see
'**** LOG10 function and routines for rounding numbers ****
DefSng A-Z
Static Function LOG10(x As Single) As Single
If x > 0 Then
LOG10! = Log(x) * (1 / Log(10!))
Else
LOG10! = -6
End If
End Function
Static Sub Round(x, Places As Integer, y, Digits As Integer, Decade)
' rounds X to Places significant figures, returning
' rounded value Y, digits as value of significant figures,
' and Decade as factor to multiply digits by to get Y
Decade = 10! ^ (Int(LOG10(Abs(x))) - Places + 1)
Digits = CInt(x / Decade)
y = Digits * Decade
End Sub
Static Sub RoundDown(x, Places As Integer, y, Digits As Integer, Decade)
' rounds X DOWN to places significant figures, returning
' rounded value Y, digits as value of significant figures,
' and Decade as the factor to multiply digits by to get Y
Decade = 10! ^ (Int(LOG10(Abs(x))) - Places + 1)
Digits = Int(x / Decade)
y = Digits * Decade
End Sub
Static Sub RoundUp(x, Places As Integer, y, Digits As Integer, Decade)
' rounds X UP to places significant figures, returning
' rounded value Y, digits as value of significant figures,
' and Decade as the factor to multiply digits by to get Y
Decade = 10! ^ (Int(LOG10(Abs(x))) - Places + 1)
Digits = CInt(x / Decade + 0.4999999)
y = Digits * Decade
End Sub