8c3b7d24bbcf — Leonard Ritter 22 days ago
* implemented `distance` in core
3 files changed, 11 insertions(+), 1 deletions(-)

M lib/scopes/core.sc
M src/symbol_enum.inc
M testing/test_intrinsics.sc
M lib/scopes/core.sc +7 -0
@@ 7710,6 7710,13 @@ fn hex (value)
     integer->string value (16 as (typeof value))
 
 #-------------------------------------------------------------------------------
+# extensions to intrinsics
+#-------------------------------------------------------------------------------
+
+inline distance (a b)
+    length (a - b)
+
+#-------------------------------------------------------------------------------
 # constants
 #-------------------------------------------------------------------------------
 

          
M src/symbol_enum.inc +1 -1
@@ 391,7 391,7 @@ namespace scopes {
     T(FN_Frexp, "frexp") \
     T(FN_Ldexp, "ldexp") \
     T(FN_Length, "length") \
-    T(FN_Distance, "distance") \
+    /*T(FN_Distance, "distance")*/ \
     T(FN_Cross, "cross") \
     T(FN_Normalize, "normalize") \
 

          
M testing/test_intrinsics.sc +3 -0
@@ 33,6 33,9 @@ test
     (length (normalize (vectorof f32 2.0 6.0 9.0))) == 1.0
 
 test
+    (distance (vectorof f32 10.0 10.0 10.0) (vectorof f32 8.0 4.0 1.0)) == 11.0
+
+test
     all?
         (cross (vectorof f32 0 0 1) (vectorof f32 0 1 0)) == (vectorof f32 -1 0 0)