Browse Source

Changed Abs and Sgn keywords into Functions.

woollybah 6 years ago
parent
commit
ff45c4e62b
2 changed files with 65 additions and 10 deletions
  1. 0 10
      blitz.mod/blitz.bmx
  2. 65 0
      blitz.mod/builtin.bmx

+ 0 - 10
blitz.mod/blitz.bmx

@@ -1043,21 +1043,11 @@ bbdoc: Number of characters in a string or elements in an array
 keyword: "Len"
 keyword: "Len"
 End Rem
 End Rem
 
 
-Rem
-bbdoc: Numeric 'absolute value' unary operator
-keyword: "Abs"
-End Rem
-
 Rem
 Rem
 bbdoc: Numeric 'modulus' or 'remainder' binary operator
 bbdoc: Numeric 'modulus' or 'remainder' binary operator
 keyword: "Mod"
 keyword: "Mod"
 End Rem
 End Rem
 
 
-Rem
-bbdoc: Numeric 'sign' unary operator
-keyword: "Sgn"
-End Rem
-
 Rem
 Rem
 bbdoc: Find the address of a variable
 bbdoc: Find the address of a variable
 keyword: "Varptr"
 keyword: "Varptr"

+ 65 - 0
blitz.mod/builtin.bmx

@@ -180,3 +180,68 @@ Function Min:Size_T(a:Size_T, b:Size_T)
 	End If
 	End If
 	Return a
 	Return a
 End Function
 End Function
+
+Extern
+	Function bbIntAbs:Int(a:Int)
+	Function bbFloatAbs:Double(a:Double)
+	Function bbLongAbs:Long(a:Long)
+	Function bbIntSgn:Int(a:Int)
+	Function bbFloatSgn:Int(a:Double)="double bbFloatSgn(double)!"
+	Function bbLongSgn:Int(a:Long)="BBInt64 bbLongSgn(BBInt64)!"
+End Extern
+
+Rem
+bbdoc: Returns the absolute value of the #Int argument.
+End Rem
+Function Abs:Int(a:Int)
+	Return bbIntAbs(a)
+End Function
+
+Rem
+bbdoc: Returns the absolute value of the #Float argument.
+End Rem
+Function Abs:Float(a:Float)
+	Return bbFloatAbs(Double(a))
+End Function
+
+Rem
+bbdoc: Returns the absolute value of the #Double argument.
+End Rem
+Function Abs:Double(a:Double)
+	Return bbFloatAbs(a)
+End Function
+
+Rem
+bbdoc: Returns the absolute value of the #Long argument.
+End Rem
+Function Abs:Long(a:Long)
+	Return bbLongAbs(a)
+End Function
+
+Rem
+bbdoc: Returns the sign of the #Int argument.
+End Rem
+Function Sgn:Int(a:Int)
+	Return bbIntSgn(a)
+End Function
+
+Rem
+bbdoc: Returns the sign of the #Float argument.
+End Rem
+Function Sgn:Float(a:Float)
+	Return bbFloatSgn(Double(a))
+End Function
+
+Rem
+bbdoc: Returns the sign of the #Double argument.
+End Rem
+Function Sgn:Double(a:Double)
+	Return bbFloatSgn(a)
+End Function
+
+Rem
+bbdoc: Returns the sign of the #Long argument.
+End Rem
+Function Sgn:Long(a:Long)
+	Return bbLongSgn(a)
+End Function