Calculating Sunrise/sunset Times Using Only Integer Math

I need a function (eg IsDark(time_t,lat,long))that returns boolean

whether its dark or not, when input with time(GMT), lat and long. And

it has to use only integer mathematics. The alogrithm has to be

implementable on a small processor, in the C language, and run

reasonably swiftly. Absolute accuracy is not required.

Request for Question Clarification byanswerguru-ga

Hi there,

Sorry to let you know that you cannot find out what you want with just

those parameters. Don't forget also that the earth revolves around the

sun, so sunset times will be different for the same place depending on

what time of year it is.


Request for Question Clarification byjeanluis-ga

Actually according to the man page for the C function time_t

time(time_t *t):

"time returns the time since the Epoch (00:00:00 UTC, January 1,

1970), measured in seconds."

So that should be sufficient input data, however the real question is,

how much memory can we use? Because this could be done quite fast with

a table lookup function, but it would use alot of memory… Using a

table would also satisify the other requirement, that this function be

all integer.

I am also just curious however, why must it be all integer? (Just

speed issues? or does the target platform not have floating point

functions?) and what is the target platform?

Let me know


Clarification of Question bykaptainkazoo-ga

This is for a small embedded system, and I dont have any requirement

(nor an available library) for floating point other than this one odd

requirement. Its on an 80188 processor, which has no FP support. I'd

like the target footprint (inc tables) to be < 5Kbyte. Ive seen

several solutions (eg,, but these

appear to need a lot of supporting math functions.

Clarification of Question bykaptainkazoo-ga

I'd have though ten minutes of error would be accepable.

Clarification of Question bykaptainkazoo-ga

Does it becomer easier if there is no performance requirement? Its

just occured I can run this as a background task at low priority one a

minute, rather than as an inline function, so any need to complete

swiftly goes away.

Leave a Reply

Your email address will not be published. Required fields are marked *