summaryrefslogtreecommitdiff
path: root/libstd/extremum.myr
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2014-09-17 02:07:54 -0400
committerOri Bernstein <ori@eigenstate.org>2014-09-17 02:07:54 -0400
commitacb375efc5fc5c7e52f12e48dcf7e0410e68f5e7 (patch)
treee553e96e32f72192b35defa357bb7039fcdca0fb /libstd/extremum.myr
parent2f2e574cc824695de2d5e2b233063afd6e7814bb (diff)
downloadmc-acb375efc5fc5c7e52f12e48dcf7e0410e68f5e7.tar.gz
Add support for absolute cutoffs.
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
+ ;;
+}