int Triangle(char *argv[] , double *pole) { int i=0; if(Body_stran(argv, pole)==NAN) return EXIT_FAILURE; double a2=Strana(pole[i+0], pole[i+1], pole[i+2], pole[i+3]); double b2=Strana(pole[i+0], pole[i+1], pole[i+4], pole[i+5]); double c2=Strana(pole[i+2], pole[i+3], pole[i+4], pole[i+5]); double a=my_sqrt(a2); double b=my_sqrt(b2); double c=my_sqrt(c2); if ((Zostrojitelnost(a, b, c)==false)) return EXIT_FAILURE; double A= pi_pol-my_asin((a2+b2-c2)/(2.0*a*b)); double C= pi_pol-my_asin((b2+c2-a2)/(2.0*b*c)); double B= pi-A-C; if(B>=pi) return EXIT_FAILURE; printf("%.10e\n%.10e\n%.10e\n", A, B, C); return EXIT_SUCCESS; }
double my_asin(double x) { double x2=x*x; if(x>mag_cislo) x=pi_pol - my_asin(my_sqrt(1-x2)); else if(x<(-mag_cislo)) x=-(pi_pol - my_asin(my_sqrt(1-x2))); else x=Vypocet_asin(x, x2); return x; }
void asin_clicked(GtkButton*w, GtkEntry *entry){ first_operand = atof(gtk_entry_get_text(entry)); result = my_asin(first_operand); char str[10]; snprintf(str,10,"%f",result); gtk_entry_set_text(entry,str); }
int main() { /** Testovani souctu */ // test 1 - celych cisel SHOULD_BE_EQUAL_FLOAT(122.0+105.0,sucet(122.0,105.0),"soucet_1"); // test 2 - desetinnych cisel SHOULD_BE_EQUAL_FLOAT(36514.515+3652.525, sucet(36514.515,3652.525),"soucet_2"); // test 3 - desetinnych cisel s vetsi presnosti SHOULD_BE_EQUAL_FLOAT(9.8+3.1, sucet(9.8,3.1),"soucet_3"); // test 4 - zapornych cisel SHOULD_BE_EQUAL_FLOAT(-1.5811111+6.5252525, sucet(-1.5811111,6.5252525),"soucet_4"); /** Testovani rozdilu */ // test 5 - celych cisel SHOULD_BE_EQUAL_FLOAT(55.0-20.0, rozdil(55.0,20.0), "rozdil_5"); // test 6 - desetinnych cisel SHOULD_BE_EQUAL_FLOAT( 358.49-258.4, rozdil(358.49,258.4),"rozdil_6"); // test 7 - desetinnych cisel s vetsi presnosti SHOULD_BE_EQUAL_FLOAT(256.12357-128.999999, rozdil(256.12357,128.999999),"rozdil_7"); // test 8 - zapornych desetinnych cisel SHOULD_BE_EQUAL_FLOAT(-2.555555-(-3.595959), rozdil(-2.555555,-3.595959), "rozdil_8"); /** Testovani nasobeni */ // test 9 - celych cisel SHOULD_BE_EQUAL_FLOAT(11.0*3.0, nasobeni(11.0,3.0),"nasobeni_9"); // test 10 - desetinnych cisel SHOULD_BE_EQUAL_FLOAT(35.555*211.652, nasobeni(35.555,211.652),"nasobeni_10"); // test 11 - nasobeni nulou SHOULD_BE_EQUAL_FLOAT(5.5*0.0, nasobeni(5.5,0.0),"nasobeni_11"); // test 12 - nasobeni zapornym cislem SHOULD_BE_EQUAL_FLOAT(36.56*(-4.123), nasobeni(36.56,-4.123),"nasobeni_12"); /** Testovani podilu */ // test 13 - celych cisel SHOULD_BE_EQUAL_FLOAT( 8.0/4.0, podil(8.0,4.0),"podil_13"); // test 14 - desetinnych cisel SHOULD_BE_EQUAL_FLOAT(64.5/28.244, podil(64.5,28.244),"podil_14"); // test 15 - zapornych cisel SHOULD_BE_EQUAL_FLOAT(-96.2/16.5, podil(-96.2,16.5),"podil_15"); // test 16 - podil nulou SHOULD_BE_EQUAL_INF(45.136/0.0,podil(45.136,0.0),"podil_16"); // using isnan() function /** Testovani mocniny */ // test 17 - umocneni celeho cisla SHOULD_BE_EQUAL_FLOAT(pow(5.0,3.0), my_pow(5.0,3.0),"mocnina_17"); // test 18 - umocneni desetinneho cisla SHOULD_BE_EQUAL_FLOAT(pow(25.684,6.0), my_pow(25.684,6),"mocnina_18"); // test 19 - umocneni zapornym cislem SHOULD_BE_EQUAL_NAN(NAN, my_pow(11.6545,-8),"mocnina_19"); // test 20 - umocneni nulou SHOULD_BE_EQUAL_FLOAT(pow(78.1111,0.0), my_pow(78.1111,0),"mocnina_20"); /** Testovani druhe odmocniny */ // test 21 - odmocneni celeho cisla SHOULD_BE_EQUAL_FLOAT(pow(64.0,1/2.0), my_sqrt(64.0), "odmocnina_21"); // test 22 - odmocneni desetinneho cisla SHOULD_BE_EQUAL_FLOAT(pow(235.154787,1/2.0), my_sqrt(235.154787),"odmocnina_22"); // test 23 - odmocneni zaporneho cisla SHOULD_BE_EQUAL_NAN(pow(-81.154787,1/2.0),my_sqrt(-81.154787),"odmocnina_23"); // test 24 - odmocneni nuly SHOULD_BE_EQUAL_FLOAT(pow(0,1/2.0),my_sqrt(0),"odmocnina_24"); /** Testovani arcus sinu */ // test 25 - krajnich hodnot Df SHOULD_BE_EQUAL_FLOAT(asin(1.0), my_asin(1.0),"arcus_sinus_25"); // test 26 - krajnich hodnot Df SHOULD_BE_EQUAL_FLOAT(asin(-1.0), my_asin(-1.0),"arcus_sinus_26"); // test 27 - hodnot z intervalu (-1;1) SHOULD_BE_EQUAL_FLOAT(asin(0.56), my_asin(0.56),"arcus_sinus_27"); // test 28 - hodnot z intervalu (-1;-0.9) a (0.9;1) SHOULD_BE_EQUAL_FLOAT(asin(-0.96), my_asin(-0.96),"arcus_sinus_28"); //test 29 - hodnot mimo definicni obor SHOULD_BE_EQUAL_NAN(NAN,my_asin(-2.56),"arcus_sinus_29"); /** Testovani faktorialu */ // test 30 - kladneho celeho cisla SHOULD_BE_EQUAL_FACT(120.0,factorial(5),"factorial_33"); // test 31 - kladneho celeho cisla SHOULD_BE_EQUAL_FACT(40320.0,factorial(8),"factorial_34"); //test 32 - zaporneho cisla SHOULD_BE_EQUAL_NAN(NAN,factorial(-6),"factorial_35"); // test 33 - cisla s vysledkem nad limit hodnot promenne integer SHOULD_BE_EQUAL_NAN(NAN,factorial(100.0),"factorial_36"); // test 34 - desetinneho cisla SHOULD_BE_EQUAL_NAN(NAN,factorial(29.99),"factorial_37"); /** Testovani absolutni hodnoty */ // test 37 - kladneho celeho cisla SHOULD_BE_EQUAL_FLOAT(fabs(11.0), my_abs(11.0),"my_abs_38"); // test 38 - zaporneho cisla SHOULD_BE_EQUAL_FLOAT(fabs(-222.0), my_abs(-222.0),"my_abs_39"); // test 39 - desetinneho cisla SHOULD_BE_EQUAL_FLOAT(fabs(-55.666), my_abs(-55.666),"my_abs_40"); // test 40 - nuly SHOULD_BE_EQUAL_FLOAT(fabs(0), my_abs(0),"my_abs_41"); printf("\nTest failed: %d\n", errors); printf("Test passed: %d\n",passed); return 0; }
int main(int argc, char *argv[]) { double pole[6]; char* pEnd; if (Argumenty(argc) == EXIT_FAILURE) return EXIT_FAILURE; if (argc == 2 && strcmp("--help", argv[1]) == 0) { Ukoncenie(HELP); return EXIT_SUCCESS; } if(strcmp(argv[1], "--triangle")== 0 && argc==8) { if(Triangle(argv, pole)==EXIT_FAILURE) { printf("%.10e\n%.10e\n%.10e\n", NAN, NAN, NAN); return EXIT_FAILURE; } else return EXIT_SUCCESS; } if(strcmp(argv[1], "--sqrt")== 0 && argc==3) { double x= strtod(argv[2], &pEnd); if(*pEnd == 0) { if(x>=0) { printf("%.10e\n", my_sqrt(x)); return EXIT_SUCCESS; } else printf("%.10e\n", NAN); } else if(strcmp(argv[2], "inf")== 0) { printf("%.10e\n", INF); return EXIT_SUCCESS; } else printf("%.10e\n", NAN); return EXIT_FAILURE; } if(strcmp(argv[1], "--asin")== 0&& argc==3) { double x= strtod(argv[2], &pEnd); if(*pEnd == 0) { if (ab_h(x)<=1.0) /// iba interval x= <-1.0&&x>=-1.0) { printf("%.10e\n", my_asin(x)); return EXIT_SUCCESS; } } printf("%.10e\n", NAN); return EXIT_FAILURE; } Ukoncenie(Args); return EXIT_FAILURE; }
float calcSun(int year, int month, int day, float latitude, float longitude, int sunset, float zenith) { int N1 = my_floor(275 * month / 9); int N2 = my_floor((month + 9) / 12); int N3 = (1 + my_floor((year - 4 * my_floor(year / 4) + 2) / 3)); int N = N1 - (N2 * N3) + day - 30; float lngHour = longitude / 15; float t; if (!sunset) { //if rising time is desired: t = N + ((6 - lngHour) / 24); } else { //if setting time is desired: t = N + ((18 - lngHour) / 24); } float M = (0.9856 * t) - 3.289; //calculate the Sun's true longitude //L = M + (1.916 * sin(M)) + (0.020 * sin(2 * M)) + 282.634 float L = M + (1.916 * my_sin((M_PI/180.0f) * M)) + (0.020 * my_sin((M_PI/180.0f) * 2 * M)) + 282.634; if (L<0) L+=360.0f; if (L>360) L-=360.0f; //5a. calculate the Sun's right ascension //RA = atan(0.91764 * tan(L)) float RA = (180.0f/M_PI) * my_atan(0.91764 * my_tan((M_PI/180.0f) * L)); if (RA<0) RA+=360; if (RA>360) RA-=360; //5b. right ascension value needs to be in the same quadrant as L float Lquadrant = (my_floor( L/90)) * 90; float RAquadrant = (my_floor(RA/90)) * 90; RA = RA + (Lquadrant - RAquadrant); //5c. right ascension value needs to be converted into hours RA = RA / 15; //6. calculate the Sun's declination float sinDec = 0.39782 * my_sin((M_PI/180.0f) * L); float cosDec = my_cos(my_asin(sinDec)); //7a. calculate the Sun's local hour angle //cosH = (cos(zenith) - (sinDec * sin(latitude))) / (cosDec * cos(latitude)) float cosH = (my_cos((M_PI/180.0f) * zenith) - (sinDec * my_sin((M_PI/180.0f) * latitude))) / (cosDec * my_cos((M_PI/180.0f) * latitude)); if (cosH > 1) { return 0; } else if (cosH < -1) { return 0; } //7b. finish calculating H and convert into hours float H; if (!sunset) { //if rising time is desired: H = 360 - (180.0f/M_PI) * my_acos(cosH); } else { //if setting time is desired: H = (180.0f/M_PI) * my_acos(cosH); } H = H / 15; //8. calculate local mean time of rising/setting float T = H + RA - (0.06571 * t) - 6.622; //9. adjust back to UTC float UT = T - lngHour; if (UT<0) {UT+=24;} if (UT>24) {UT-=24;} time_t now = time(NULL); struct tm *tick_time = localtime(&now); struct tm *gm_time = gmtime(&now); int timezoneoffset = 60 * (60 * (24 * (tick_time->tm_wday - gm_time->tm_wday) + tick_time->tm_hour - gm_time->tm_hour) + tick_time->tm_min - gm_time->tm_min); // Correct for transitions at the end of the week. int SECONDS_IN_WEEK=604800; if (timezoneoffset > SECONDS_IN_WEEK/2) timezoneoffset -= SECONDS_IN_WEEK; if (timezoneoffset < -SECONDS_IN_WEEK/2) timezoneoffset += SECONDS_IN_WEEK; timezoneoffset /= 3600; APP_LOG(APP_LOG_LEVEL_DEBUG, "timezone offset %d", timezoneoffset); APP_LOG(APP_LOG_LEVEL_DEBUG, "other timezone offset %d", (tick_time-gm_time)); // return UT+(tick_time-gm_time); return UT; }
float calcSun(int year, int month, int day, float latitude, float longitude, int sunset, float zenith) { int N1 = my_floor(275 * month / 9); int N2 = my_floor((month + 9) / 12); int N3 = (1 + my_floor((year - 4 * my_floor(year / 4) + 2) / 3)); int N = N1 - (N2 * N3) + day - 30; float lngHour = longitude / 15; float t; if (!sunset) { //if rising time is desired: t = N + ((6 - lngHour) / 24); } else { //if setting time is desired: t = N + ((18 - lngHour) / 24); } float M = (0.9856 * t) - 3.289; //calculate the Sun's true longitude //L = M + (1.916 * sin(M)) + (0.020 * sin(2 * M)) + 282.634 float L = M + (1.916 * my_sin((M_PI/180.0f) * M)) + (0.020 * my_sin((M_PI/180.0f) * 2 * M)) + 282.634; if (L<0) L+=360.0f; if (L>360) L-=360.0f; //5a. calculate the Sun's right ascension //RA = atan(0.91764 * tan(L)) float RA = (180.0f/M_PI) * my_atan(0.91764 * my_tan((M_PI/180.0f) * L)); if (RA<0) RA+=360; if (RA>360) RA-=360; //5b. right ascension value needs to be in the same quadrant as L float Lquadrant = (my_floor( L/90)) * 90; float RAquadrant = (my_floor(RA/90)) * 90; RA = RA + (Lquadrant - RAquadrant); //5c. right ascension value needs to be converted into hours RA = RA / 15; //6. calculate the Sun's declination float sinDec = 0.39782 * my_sin((M_PI/180.0f) * L); float cosDec = my_cos(my_asin(sinDec)); //7a. calculate the Sun's local hour angle //cosH = (cos(zenith) - (sinDec * sin(latitude))) / (cosDec * cos(latitude)) float cosH = (my_cos((M_PI/180.0f) * zenith) - (sinDec * my_sin((M_PI/180.0f) * latitude))) / (cosDec * my_cos((M_PI/180.0f) * latitude)); if (cosH > 1) { // no sunrise here on this day return 100; // watchface won't draw indicator if this value is found } else if (cosH < -1){ // no sunset here on this day return 100; // watchface won't draw indicator if this value is found } //7b. finish calculating H and convert into hours float H; if (!sunset) { //if rising time is desired: H = 360 - (180.0f/M_PI) * my_acos(cosH); } else { //if setting time is desired: H = (180.0f/M_PI) * my_acos(cosH); } H = H / 15; //8. calculate local mean time of rising/setting float T = H + RA - (0.06571 * t) - 6.622; //9. adjust back to UTC float UT = T - lngHour; if (UT<0) {UT+=24;} if (UT>24) {UT-=24;} return UT; }