Browse Source

Added Round and Trunc functions.

woollybah 5 years ago
parent
commit
a0550cae9b
2 changed files with 36 additions and 1 deletions
  1. 22 1
      math.mod/math.bmx
  2. 14 0
      math.mod/math.c

+ 22 - 1
math.mod/math.bmx

@@ -6,12 +6,14 @@ bbdoc: Math/Math
 End Rem
 Module BRL.Math
 
-ModuleInfo "Version: 1.06"
+ModuleInfo "Version: 1.07"
 ModuleInfo "Author: Mark Sibly"
 ModuleInfo "License: zlib/libpng"
 ModuleInfo "Copyright: Blitz Research Ltd"
 ModuleInfo "Modserver: BRL"
 
+ModuleInfo "History: 1.07"
+ModuleInfo "History: Added Round and Trunc."
 ModuleInfo "History: 1.06"
 ModuleInfo "History: Added Float versions."
 ModuleInfo "History: 1.05 Release"
@@ -113,6 +115,15 @@ bbdoc: Largest integral value not greater than @x
 End Rem
 Function Floor:Double( x:Double )="bbFloor"
 
+Rem
+bbdoc: Nearest integral value to @x.
+End Rem
+Function Round:Double( x:Double )="bbRound"
+
+Rem
+bbdoc: Nearest integral not greater in magnitude than @x.
+End Rem
+Function Trunc:Double( x:Double )="bbTrunc"
 
 
 Rem
@@ -195,4 +206,14 @@ bbdoc: Largest integral value not greater than @x
 End Rem
 Function FloorF:Float( x:Float )="bbFloorf"
 
+Rem
+bbdoc: Nearest integral value to @x.
+End Rem
+Function RoundF:Float( x:Float )="bbRoundf"
+
+Rem
+bbdoc: Nearest integral not greater in magnitude than @x.
+End Rem
+Function TruncF:Float( x:Float )="bbTruncf"
+
 End Extern

+ 14 - 0
math.mod/math.c

@@ -58,6 +58,12 @@ double bbLog10( double x ){
 double bbCeil( double x ){
 	return ceil( x );
 }
+double bbRound( double x ){
+	return round( x );
+}
+double bbTrunc( double x ){
+	return trunc( x );
+}
 
 // fallback for pre C99 versions
 #ifndef __STDC_VERSION__
@@ -84,6 +90,8 @@ double bbCeil( double x ){
 	#define logf log
 	#define log10f log10
 	#define ceilf ceil
+	#define roundf round
+	#define truncf trunc
 #else
 	#define RAD_TO_DEGF 57.2957795
 	#define DEG_TO_RADF 0.0174532
@@ -137,3 +145,9 @@ float bbLog10f( float x ){
 float bbCeilf( float x ){
 	return ceilf( x );
 }
+float bbRoundf( float x ){
+	return roundf( x );
+}
+float bbTruncf( float x ){
+	return truncf( x );
+}