Method: CGLM::Mat4#equalish
- Defined in:
- ext/cglm/rb_cglm_mat4.c
#=~(b) ⇒ Object Also known as: =~
Returns true if each member of a is very close to, but not necessarily
exactly equal to, each corresponding member of b. This is useful in many
circumstances because imprecision introduced by floating point calculations
can lead to two expressions which are otherwise mathematically equivalent
returning false.
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
# File 'ext/cglm/rb_cglm_mat4.c', line 234 VALUE rb_cglm_mat4_equalish(int argc, VALUE *argv, VALUE self) { VALUE other, epsilon; float feps = FLT_EPSILON; rb_scan_args(argc, argv, "11", &other, &epsilon); if (!NIL_P(epsilon)) feps = NUM2FLT(epsilon); mat4 *a = &VAL2MAT4(self); mat4 *b = &VAL2MAT4(other); for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { if (fabsf((*a)[i][j] - (*b)[i][j]) > feps) return Qfalse; } } return Qtrue; } |