summaryrefslogtreecommitdiff
path: root/libstd/extremum.myr
diff options
context:
space:
mode:
Diffstat (limited to 'libstd/extremum.myr')
-rw-r--r--libstd/extremum.myr8
1 files changed, 8 insertions, 0 deletions
diff --git a/libstd/extremum.myr b/libstd/extremum.myr
index bf496ad..9675915 100644
--- a/libstd/extremum.myr
+++ b/libstd/extremum.myr
@@ -2,6 +2,7 @@ pkg std =
generic min : (a : @a::numeric, b : @a::numeric -> @a::numeric)
generic max : (a : @a::numeric, b : @a::numeric -> @a::numeric)
generic clamp : (a : @a::numeric, min : @a::numeric, max : @a::numeric -> @a::numeric)
+ generic abs : (a : @a::numeric -> @a::numeric)
;;
generic min = {a, b
@@ -30,3 +31,10 @@ generic clamp = {a, min, max
;;
}
+generic abs = {a : @a::numeric
+ if a < (0 castto(@a::numeric))
+ -> -a
+ else
+ -> a
+ ;;
+}