From aa882c10fbc832150c932a8cdcf9926f2fa6c9fe Mon Sep 17 00:00:00 2001 From: DiamondNether90 Date: Fri, 12 Sep 2025 19:59:53 +1000 Subject: [PATCH] Using the Error Function --- packages/math/math.grnd | 8 ++++++-- packages/strings/strings.grnd | 8 +++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/packages/math/math.grnd b/packages/math/math.grnd index 4455ea1..22f1db6 100644 --- a/packages/math/math.grnd +++ b/packages/math/math.grnd @@ -62,7 +62,7 @@ fun -int !factorial -int &in return $ans @error - divide 1 0 &store + error "Cannot find factorial of a negative integer" endfun fun -double !cos -double &in @@ -206,4 +206,8 @@ fun -double !sqrt -double &in return $ans @error -endfun \ No newline at end of file + error "Cannot find square root of a negative double" +endfun + +pusharg -0.5 +call !sqrt &store \ No newline at end of file diff --git a/packages/strings/strings.grnd b/packages/strings/strings.grnd index 376ced5..a92cb10 100644 --- a/packages/strings/strings.grnd +++ b/packages/strings/strings.grnd @@ -46,14 +46,11 @@ endfun fun -string !mid -string &str -int &idx -int &len set &ans "" lesser $idx 0 &store - if $store %end + if $store %negend greater $len 0 &store if $store %loop return "" @loop - getstrsize $str &store - equal $store $idx &store - if $store %end getstrcharat $str $idx &store add $ans $store &ans add $idx 1 &idx @@ -65,7 +62,8 @@ fun -string !mid -string &str -int &idx -int &len @return return $ans - @end + @negend + error "Cannot start mid at a negative index" endfun fun -string !inBrackets -string &str -char &left -char &right -int &instance