#include <stdio.h>
#include <math.h>

#define EPS 1e-5

double f(double x) {
    return x*x - 1 - sin(x);
}

// 二分法
double bisection(double a, double b) {
    double mid;

    while (1) {
        mid = (a + b) / 2.0;

        if (fabs(f(mid)) < EPS) return mid;

        if (f(a) * f(mid) < 0)
            b = mid;
        else
            a = mid;
    }
}

// はさみうち法（False Position）
double false_position(double a, double b) {
    double x;

    while (1) {
        x = (a * f(b) - b * f(a)) / (f(b) - f(a));

        if (fabs(f(x)) < EPS) return x;

        if (f(a) * f(x) < 0)
            b = x;
        else
            a = x;
    }
}

int main() {
    double r1, r2;

    printf("=== Bisection Method ===\n");
    r1 = bisection(-1.0, 0.0);
    r2 = bisection(1.0, 2.0);
    printf("Roots: %.6f, %.6f\n", r1, r2);

    printf("\n=== False Position Method ===\n");
    r1 = false_position(-1.0, 0.0);
    r2 = false_position(1.0, 2.0);
    printf("Roots: %.6f, %.6f\n", r1, r2);

    return 0;
}
