/*
 * interpolation.c
 *
 *　Interpolation　operations
 *
 *  Created on: 2023/06/09
 *      Author: BestTechnology
 */

#pragma GCC push_options
#pragma GCC optimize ("O3")

#include <stdint.h>

#include "interpolation.h"

// Interpolation
//-----------------------------
int32_t interp1dim (const int32_t x, const int32_t *ar, const int32_t w) {
    int32_t i;
    if (x <= ar[0]) return ar[w];
    else if (x >= ar[w - 1]) return ar[w * 2 - 1];
    for (i = 1; i < w; i++) if (ar[i] >= x) break;
    return INTERP (ar[i - 1], ar[i], ar[i + w - 1], ar[i + w], x);
}

#pragma GCC pop_options
