@@ -33,6 +33,8 @@ import {
3333 toPercentFloat ,
3434 formatPercent ,
3535 percentSqrt ,
36+ percentSqrtUp ,
37+ percentSqrtDown ,
3638} from "./percent" ;
3739import {
3840 wadAdd ,
@@ -54,6 +56,8 @@ import {
5456 toWadFloat ,
5557 formatWad ,
5658 wadSqrt ,
59+ wadSqrtUp ,
60+ wadSqrtDown ,
5761} from "./wad" ;
5862import {
5963 rayAdd ,
@@ -75,6 +79,8 @@ import {
7579 toRayFloat ,
7680 formatRay ,
7781 raySqrt ,
82+ raySqrtUp ,
83+ raySqrtDown ,
7884} from "./ray" ;
7985
8086declare global {
@@ -92,6 +98,8 @@ declare global {
9298 mulDivDown : ( other : bigint , scale : bigint ) => bigint ;
9399
94100 sqrt : ( ) => bigint ;
101+ sqrtUp : ( ) => bigint ;
102+ sqrtDown : ( ) => bigint ;
95103
96104 compMul : ( other : bigint ) => bigint ;
97105 compDiv : ( other : bigint ) => bigint ;
@@ -110,6 +118,8 @@ declare global {
110118 percentPowDown : ( exponent : bigint ) => bigint ;
111119 percentExpN : ( exponent : bigint ) => bigint ;
112120 percentSqrt : ( ) => bigint ;
121+ percentSqrtUp : ( ) => bigint ;
122+ percentSqrtDown : ( ) => bigint ;
113123 percentToDecimals : ( decimals : number ) => bigint ;
114124 percentToWad : ( ) => bigint ;
115125 percentToRay : ( ) => bigint ;
@@ -130,6 +140,8 @@ declare global {
130140 wadPowDown : ( exponent : bigint ) => bigint ;
131141 wadExpN : ( exponent : bigint ) => bigint ;
132142 wadSqrt : ( ) => bigint ;
143+ wadSqrtUp : ( ) => bigint ;
144+ wadSqrtDown : ( ) => bigint ;
133145 wadToDecimals : ( decimals : number ) => bigint ;
134146 wadToPercent : ( ) => bigint ;
135147 wadToRay : ( ) => bigint ;
@@ -150,6 +162,8 @@ declare global {
150162 rayPowDown : ( exponent : bigint ) => bigint ;
151163 rayExpN : ( exponent : bigint ) => bigint ;
152164 raySqrt : ( ) => bigint ;
165+ raySqrtUp : ( ) => bigint ;
166+ raySqrtDown : ( ) => bigint ;
153167 rayToDecimals : ( decimals : number ) => bigint ;
154168 rayToPercent : ( ) => bigint ;
155169 rayToWad : ( ) => bigint ;
@@ -205,8 +219,14 @@ BigInt.prototype.mulDivDown = function (other: bigint, scale: bigint) {
205219 return mulDivDown ( this as bigint , other , scale ) ;
206220} ;
207221
208- BigInt . prototype . sqrt = function ( ) {
209- return sqrt ( this as bigint ) ;
222+ BigInt . prototype . sqrt = function ( scale = 1n ) {
223+ return sqrt ( this as bigint , scale , mulDivHalfUp ) ;
224+ } ;
225+ BigInt . prototype . sqrtUp = function ( scale = 1n ) {
226+ return sqrt ( this as bigint , scale , mulDivUp ) ;
227+ } ;
228+ BigInt . prototype . sqrtDown = function ( scale = 1n ) {
229+ return sqrt ( this as bigint , scale , mulDivDown ) ;
210230} ;
211231
212232BigInt . prototype . compMul = function ( other : bigint ) {
@@ -258,6 +278,12 @@ BigInt.prototype.percentExpN = function (N: bigint) {
258278BigInt . prototype . percentSqrt = function ( ) {
259279 return percentSqrt ( this as bigint ) ;
260280} ;
281+ BigInt . prototype . percentSqrtUp = function ( ) {
282+ return percentSqrtUp ( this as bigint ) ;
283+ } ;
284+ BigInt . prototype . percentSqrtDown = function ( ) {
285+ return percentSqrtDown ( this as bigint ) ;
286+ } ;
261287BigInt . prototype . percentToDecimals = function ( decimals : number ) {
262288 return percentToDecimals ( this as bigint , decimals ) ;
263289} ;
@@ -316,6 +342,12 @@ BigInt.prototype.wadExpN = function (N: bigint) {
316342BigInt . prototype . wadSqrt = function ( ) {
317343 return wadSqrt ( this as bigint ) ;
318344} ;
345+ BigInt . prototype . wadSqrtUp = function ( ) {
346+ return wadSqrtUp ( this as bigint ) ;
347+ } ;
348+ BigInt . prototype . wadSqrtDown = function ( ) {
349+ return wadSqrtDown ( this as bigint ) ;
350+ } ;
319351BigInt . prototype . wadToDecimals = function ( decimals : number ) {
320352 return wadToDecimals ( this as bigint , decimals ) ;
321353} ;
@@ -374,6 +406,12 @@ BigInt.prototype.rayExpN = function (N: bigint) {
374406BigInt . prototype . raySqrt = function ( ) {
375407 return raySqrt ( this as bigint ) ;
376408} ;
409+ BigInt . prototype . raySqrtUp = function ( ) {
410+ return raySqrtUp ( this as bigint ) ;
411+ } ;
412+ BigInt . prototype . raySqrtDown = function ( ) {
413+ return raySqrtDown ( this as bigint ) ;
414+ } ;
377415BigInt . prototype . rayToDecimals = function ( decimals : number ) {
378416 return rayToDecimals ( this as bigint , decimals ) ;
379417} ;
0 commit comments