# Using Modulo in an Equation

So I’m trying to calculate sunrise and sunset for an application I’m doing and followed a formula I found online:
http://users.electromagnetic.net/bu/astro/sunrise-set.php

I’m having trouble however with two of the functions complaining about the modulo operator.

``````long mSA = (357.5291 + 0.98560028 * (jSNoon - 2451545)) % 360.0;
long Y = (mSA + 102.9372 + C + 180) % 360.0;
``````
``````sketch_dec24a.ino: In function 'int getSunrise()':
sketch_dec24a.ino:33:61: error: invalid operands of types 'double' and 'double' to binary 'operator%'
sketch_dec24a.ino:35:41: error: invalid operands of types 'double' and 'double' to binary 'operator%'
Error compiling.
``````

I originally had the variable set to float before reading online that modulo didn’t handle float variables, so I changed it to double and now long, but I still receive the same error. Is there a way around this?

You can use decimal numbers. Convert the numbers to int (or long) before the modulus operation. You can't use too the 360.0 use only 360.

360.0 is still a float and that's why you have the error. Use the function fmod instead guix:
360.0 is still a float and that’s why you have the error. Use the function fmod instead Sneaky! Awesome, it works now. Just need to get the formula to actually work now.

did some sunrise / sunset analysis a few years ago - http://forum.arduino.cc/index.php?topic=66426.0 -
might be interesting to compare the amount of math needed..

robtillaart:
did some sunrise / sunset analysis a few years ago - http://forum.arduino.cc/index.php?topic=66426.0 -
might be interesting to compare the amount of math needed..

I'm looking into it now. Hopefully it'll help more than the equation I'm using. Apparently I can't get it accurate since float only supports 6-7 digits and I need more. Is there anyway to get a better precision?

Double and float are the same thing on an 8 bit arduino.

Endevor:
I'm looking into it now. Hopefully it'll help more than the equation I'm using. Apparently I can't get it accurate since float only supports 6-7 digits and I need more. Is there anyway to get a better precision?

As the math I referred to uses less operations it is fairly accurate.
What is the precision you are after?

As stated before, an Arduino (AVR proc) 8 bit only has support for 32 bit float. Think the DUE (arm proc) has 64 bit double support, and probably the YUN too

An option might be to use the big number library - http://forum.arduino.cc/index.php/topic,85692.0.html -