Skip to content

Commit bc5a06f

Browse files
authored
Update panchanga.h
1 parent aaa41cd commit bc5a06f

File tree

1 file changed

+12
-17
lines changed

1 file changed

+12
-17
lines changed

panchanga.h

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,24 @@
33

44
#include <cmath>
55
#include <string>
6+
#include <iostream>
67

78
#define PI 3.14159265358979323846
89
#define r2d 180.0 / PI
910
#define d2r PI / 180.0
1011

1112
// Tithi names in Nepali
1213
static const char tithi[][30] = { "प्रथमा", "द्वितीया", "तृतीया", "चतुर्थी", "पंचमी", "षष्ठी", "सप्तमी", "अष्टमी",
13-
"नवमी", "दशमी", "एकादशी", "द्वादशी", "त्रयोदशी", "चतुर्दशी", "पूर्णिमा", "प्रथमा",
14-
"द्वितीया", "तृतीया", "चतुर्थी", "पंचमी", "षष्ठी", "सप्तमी", "अष्टमी", "नवमी", "दशमी",
15-
"एकादशी", "द्वादशी", "त्रयोदशी", "चतुर्दशी", "अमावस्या" };
14+
"नवमी", "दशमी", "एकादशी", "द्वादशी", "त्रयोदशी", "चतुर्दशी", "पूर्णिमा", "प्रथमा",
15+
"द्वितीया", "तृतीया", "चतुर्थी", "पंचमी", "षष्ठी", "सप्तमी", "अष्टमी", "नवमी", "दशमी",
16+
"एकादशी", "द्वादशी", "त्रयोदशी", "चतुर्दशी", "अमावस्या" };
17+
1618
class Panchang {
1719
public:
1820
double tdays;
19-
double t, tithi_index/*, nakshatra_index, yoga_index*/;
21+
double t, tithi_index;
2022
std::string paksha;
2123

22-
2324
Panchang(double julianDate) {
2425
tdays = julianDate - 2451545.0; // Days since J2000.0
2526
t = tdays / 36525.0;
@@ -30,27 +31,24 @@ class Panchang {
3031
calculateTithi();
3132
}
3233

33-
3434
private:
3535
void calculateTithi() {
3636
double moon_longitude = getMoonLongitude();
3737
double sun_longitude = getSunLongitude();
3838

39-
4039
double difference = moon_longitude - sun_longitude;
4140
if (difference < 0) difference += 360.0;
4241

43-
tithi_index = std::floor(difference / 12.0);
44-
42+
// Round the tithi index according to the specified rules
43+
tithi_index = std::round(difference / 12.0);
44+
tithi_index = static_cast<int>(tithi_index) % 30; // Wrap around to ensure valid index
4545

4646
paksha = (tithi_index < 15) ? "शुक्ल पक्ष" : "कृष्ण पक्ष";
47-
//debug print
48-
//std::cout << "Tithi: " << tithi[(int)tithi_index] << " (" << paksha << ")" << std::endl;
47+
48+
// Debug print
49+
std::cout << "Tithi: " << tithi[static_cast<int>(tithi_index)] << " (" << paksha << ")" << std::endl;
4950
}
5051

51-
52-
53-
5452
double getSunLongitude() {
5553
double l0 = 280.4665 + 36000.7698 * t;
5654
double m = 357.5291 + 35999.0503 * t;
@@ -65,17 +63,14 @@ class Panchang {
6563
double getMoonLongitude() {
6664
double L1 = 218.316 + 481267.8813 * t;
6765
double M1 = 134.963 + 477198.8676 * t;
68-
// double F = 93.272 + 483202.0175 * t; the Moon's argument of latitude Not used now
6966

7067
L1 = fmod(L1, 360.0);
7168
M1 = fmod(M1, 360.0);
72-
// F = fmod(F, 360.0); the Moon's argument of latitude Not used now
7369

7470
double longitude = L1 + 6.289 * sin(M1 * d2r);
7571
longitude = fmod(longitude, 360.0);
7672
return longitude;
7773
}
78-
7974
};
8075

8176
double gregorianToJulian(int year, int month, int day);

0 commit comments

Comments
 (0)