Browse Source

Compare floats with a tolerance

windows-imgui
Macoy Madson 3 months ago
parent
commit
c32483cc6c
  1. 5
      src/Introspection.cake

5
src/Introspection.cake

@ -1102,6 +1102,8 @@
(free-introspect-field-handle-override
(introspect-override-invocation-args 'free)))))))
(var introspect-floating-point-compare-tolerance (const float) 0.00001f)
;; TODO: Make const correct
(defun compare-introspect-struct-internal (struct-metadata (* (const metadata-struct))
struct-a (* void)
@ -1131,7 +1133,8 @@
(offset-pointer-to-type struct-a value-offset (* float)))
(var float-b (* float)
(offset-pointer-to-type struct-b value-offset (* float)))
(when (!= (deref float-a) (deref float-b))
(when (> (- (deref float-a) (deref float-b))
introspect-floating-point-compare-tolerance)
(when print-difference
(fprintf stderr "structs differ by field '%s' [%d] (%f vs %f)\n"
(path field > name)

Loading…
Cancel
Save