Calendar date and time calculations on GitHub at:
https://github.com/breacsealgaire/Cale ... Freebasic
cCalendar_Test_Script3.txt updated to remove lunar illumination function. This function returned inconsistent results using the algorithm from Jean Meeus's book Astronomical Algorithms, Chapter 48, page 345.
*** Update ***
Finally figured out the lunar illumination function. I had to 'normalize' the lunar phase to the range 0 - 180 degrees.
Version 1.01
1. Renamed cCalendar.inc to cCalendar.bi
2. FB include folder cCalendar added
3. Function LunarIllumination added
Calendar Calculations Class
Calendar Calculations Class
Last edited by rpkelly on Dec 05, 2017 5:18, edited 2 times in total.
Re: Calendar Calculations Class
Thank you for sharing. I just had a short look at the code and your examples, and it looks well structured and documented. It seems to implement nearly every common date operation (and also a lot of uncommon ones).
Re: Calendar Calculations Class
Your're welcome. I have had a 30 year interest in studying various calendars around the world. Along the way, I had my own algorithms from my employment with various commercial banks and have finally brought most of them all together in this class. As time permits, I'll add the rest during 2017.
This was how I chose to start my learning curve using FB.
I have plans for porting PDF, SMTP, Winsock, and TCP/UDP server classes. The windows applications I'm working on for commercial release all use SQLITE as the application file format and I use a true client/server design communicating over TCP/UDP.
This was how I chose to start my learning curve using FB.
I have plans for porting PDF, SMTP, Winsock, and TCP/UDP server classes. The windows applications I'm working on for commercial release all use SQLITE as the application file format and I use a true client/server design communicating over TCP/UDP.
Re: Calendar Calculations Class
rpkelly
Had a look at your code, nice piece work.
At the end of the file you have a function for ceiling a floating point.
My suggestion is to replace Function = cmFloor(x * -1) * -1 with Function = -cmFloor(-x).
This will replace two multiplications with two sign change instructions.
First: fmul is replaced with fchs, which is a simple sign flip
Second: imul is replaced with neg, which simple make a negative number positive or a positive number negative.
The routine becomes a little bit faster and a few bytes smaller, but in light of the hole program you would notice it.
Had a look at your code, nice piece work.
At the end of the file you have a function for ceiling a floating point.
My suggestion is to replace Function = cmFloor(x * -1) * -1 with Function = -cmFloor(-x).
This will replace two multiplications with two sign change instructions.
Code: Select all
' ========================================================================================
' Return largest integer less than or equal to x
' ========================================================================================
Function cmFloor(ByVal x as Double) as Long
Function = Int(x)
End Function
' ========================================================================================
' Return smallest integer greater than or equal to x
' ========================================================================================
Function cmCeiling(ByVal x as Double) as Long
Function = cmFloor(x * -1) * -1
End Function
' ========================================================================================
' Return smallest integer greater than or equal to x
' ========================================================================================
Function cmCeiling1(ByVal x as Double) as Long
Function = -cmFloor(-x)
End Function
For x As integer = -20 To 20 Step 3
Print x / 10, cmCeiling(x / 10), cmCeiling1(x / 10)
Next
Sleep
Code: Select all
## Function = cmFloor(x * -1) * -1 | ## Function = -cmFloor(-x)
fld qword ptr [_Lt_000C] | fld qword ptr [ebp+8]
fmul qword ptr [ebp+8] | fchs
sub esp,8 | sub esp,8
fstp qword ptr [esp] | fstp qword ptr [esp]
call _CMFLOOR@8 | call _CMFLOOR@8
imul eax, -1 | neg eax
mov dword ptr [ebp-4], eax | mov dword ptr [ebp-4], eax
Second: imul is replaced with neg, which simple make a negative number positive or a positive number negative.
The routine becomes a little bit faster and a few bytes smaller, but in light of the hole program you would notice it.
Re: Calendar Calculations Class
frisian wrote:rpkelly
Had a look at your code, nice piece work.
At the end of the file you have a function for ceiling a floating point.
My suggestion is to replace Function = cmFloor(x * -1) * -1 with Function = -cmFloor(-x).
This will replace two multiplications with two sign change instructions.
I ran numbers from -9000000 to 9000000 in a loop through both versions. The difference amount to about .23% increase. Not much, but heck, I'll take it. Just to be sure and assuage my programming paranoia, I ran the same numbers through a loop and compared the results from both versions, finding no exceptions.
Thank you for your contribution.