serilib
読み取り中…
検索中…
一致する文字列を見つけられません
math.h
[詳解]
1
3
4#pragma once
5
6#include <complex.h>
7#include <stdbool.h>
8
9#ifdef __cplusplus
10extern "C" {
11#endif
12
13// 内部使用向け
15
23#ifdef __NO_LONG_DOUBLE_MATH
24 #define fpfallback(fn) fn
25#else
26 #define fpfallback(fn) fn##l
27#endif
28
36#define fpcall(fn, ...) \
37 (sizeof(SL_FP_T) == sizeof(double) ? fn(__VA_ARGS__) \
38 : sizeof(SL_FP_T) == sizeof(float) ? fn##f(__VA_ARGS__) \
39 : fpfallback(fn)(__VA_ARGS__))
40
42
51#define invlerp(from, to, value) (((value) - (from)) / ((to) - (from)))
52
65#define clamp(value, low, high) \
66 ((value) < (low) ? (low) : (high) < (value) ? (high) : (value))
67
69typedef struct {
71 SL_FP_T x;
73 SL_FP_T y;
74} cart_t;
75
77typedef struct {
79 SL_FP_T r;
81 SL_FP_T theta;
82} polar_t;
83
91bool approx(double a, double b);
92
94bool approxf(float a, float b);
95
97bool approxl(long double a, long double b);
98
105cart_t create_cart(SL_FP_T x, SL_FP_T y);
106
113polar_t create_polar(SL_FP_T r, SL_FP_T theta);
114
121polar_t cart2pol(SL_FP_T x, SL_FP_T y);
122
129cart_t pol2cart(SL_FP_T r, SL_FP_T theta);
130
137SL_FP_T dot(cart_t a, cart_t b);
138
145cart_t vec_scale(cart_t vec, SL_FP_T scaler);
146
147#ifdef __cplusplus
148}
149#endif
cart_t pol2cart(SL_FP_T r, SL_FP_T theta)
極座標を直交座標へ変換する。
cart_t create_cart(SL_FP_T x, SL_FP_T y)
直交座標型を作成する。
bool approxl(long double a, long double b)
bool approx(double a, double b)
2つの浮動小数点数の近似等価比較を行う。
bool approxf(float a, float b)
polar_t cart2pol(SL_FP_T x, SL_FP_T y)
直交座標を極座標へ変換する。
SL_FP_T dot(cart_t a, cart_t b)
二次元ベクトルの内積を計算する。
cart_t vec_scale(cart_t vec, SL_FP_T scaler)
ベクトルをスカラー倍する。
polar_t create_polar(SL_FP_T r, SL_FP_T theta)
極座標型を作成する。
直交座標
Definition math.h:69
SL_FP_T x
X座標(右が正)
Definition math.h:71
SL_FP_T y
Y座標(上が正)
Definition math.h:73
極座標
Definition math.h:77
SL_FP_T r
動径
Definition math.h:79
SL_FP_T theta
角度(右0・反時計回り) [rad]
Definition math.h:81