Calendar Calculations Class

User projects written in or related to FreeBASIC.
rpkelly
Posts: 52
Joined: Sep 03, 2016 22:36

Calendar Calculations Class

Postby rpkelly » Jan 10, 2017 3:52

Calendar date and time calculations on GitHub at:

[url]
https://github.com/breacsealgaire/Calen ... -Freebasic
[/url]

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
Last edited by rpkelly on Dec 05, 2017 5:18, edited 2 times in total.
St_W
Posts: 1507
Joined: Feb 11, 2009 14:24
Location: Austria
Contact:

Re: Calendar Calculations Class

Postby St_W » Jan 10, 2017 15:53

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).
rpkelly
Posts: 52
Joined: Sep 03, 2016 22:36

Re: Calendar Calculations Class

Postby rpkelly » Jan 11, 2017 5:50

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.
frisian
Posts: 249
Joined: Oct 08, 2009 17:25

Re: Calendar Calculations Class

Postby frisian » Jan 12, 2017 21:07

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.

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

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.
rpkelly
Posts: 52
Joined: Sep 03, 2016 22:36

Re: Calendar Calculations Class

Postby rpkelly » Jan 13, 2017 1:28

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.

Return to “Projects”

Who is online

Users browsing this forum: No registered users and 8 guests