1
1
Fork 0
mirror of https://github.com/boxgaming/qbjs.git synced 2024-05-12 08:00:12 +00:00

Implement remaining extended QB64 math functions

This commit is contained in:
boxgaming 2024-01-15 15:22:24 -06:00
parent 38ec714954
commit 25d146c8e4
4 changed files with 47 additions and 8 deletions

View file

@ -35,9 +35,11 @@ CodeMirror.defineMode("qbjs", function(conf, parserConf) {
// TODO: adjust for QB
var atomWords = ['true', 'false', 'nothing', 'empty', 'null'];
var builtinFuncsWords = ['_?acos', '_?acosh', '_?alpha', '_?alpha32', '_?asin', '_?asinh', '_?atan2', '_?atanh', '_?autodisplay',
var builtinFuncsWords = ['_?acos', '_?acosh', '_?alpha', '_?alpha32', '_?arccot', '_?arccsc', '_?arcsec',
'_?asin', '_?asinh', '_?atan2', '_?atanh', '_?autodisplay',
'_?backgroundcolor', '_?blue', '_?blue32', '_?capslock', '_?ceil', '_?commandcount', '_?continue', '_?copyimage',
'_?cosh', '_?coth', '_?csch', '_?cwd', '_?defaultcolor', '_?d2g', '_?d2r', '_?deflate', '_?desktopwidth', '_?desktopheight',
'_?cosh', '_?cot', '_?coth', '_?csc', '_?csch', '_?cwd',
'_?defaultcolor', '_?d2g', '_?d2r', '_?deflate', '_?desktopwidth', '_?desktopheight',
'_?delay', '_?dest', '_?dir', '_?direxists', '_?display', '_?echo', '_?fileexists', '_?font', '_?fontwidth', '_?fontheight',
'_?freeimage', '_?fullscreen', '_?g2d', '_?g2r', '_?green', '_?green32', '_?height', '_?hypot', "_?inflate",
'_?instrrev', '_?limit', '_?keyclear', '_?keydown', '_?keyhit', '_?loadfont', '_?loadimage',
@ -45,7 +47,8 @@ CodeMirror.defineMode("qbjs", function(conf, parserConf) {
'_?newimage', '_?numlock', '_?os', '_?palettecolor', '_?pi', '_?printstring', '_?printwidth', '_?printmode', '_?putimage',
'_?r2d', '_?r2g', '_?readbit', '_?red', '_?red32', '_?resetbit', '_?resize', '_?resizewidth',
'_?resizeheight', '_?rgb', '_?rgba', '_?rgb32', '_?rgba32', '_?round',
'_?screenexists', '_?screenmove', '_?screenx', '_?screeny', '_?scrolllock', '_?sech', '_?setbit', '_?shl', '_?shr', '_?sinh',
'_?screenexists', '_?screenmove', '_?screenx', '_?screeny', '_?scrolllock',
'_?sec', '_?sech', '_?setbit', '_?shl', '_?shr', '_?sinh',
'_?source', '_?sndclose', '_?sndopen', '_?sndplay', '_?sndloop', '_?sndpause', '_?sndstop', '_?sndvol', '_?startdir',
'_?strcmp', '_?stricmp', '_?tanh', '_?title', '_?trim', '_?togglebit', '_?width',
'abs', 'asc', 'atn', 'beep',

34
qb.js
View file

@ -247,6 +247,18 @@ var QB = new function() {
return Math.acosh(x);
};
this.func__Arccot = function(x) {
return 2 * Math.atan(1) - Math.atan(x);
};
this.func__Arccsc = function(x) {
return Math.sin(1 / x);
};
this.func__Arcsec = function(x) {
return Math.acos(1 / x);
};
this.func__Alpha = function(rgb, imageHandle) {
// TODO: implement corresponding logic when an image handle is supplied (maybe)
return _color(rgb).a;
@ -317,12 +329,20 @@ var QB = new function() {
return Math.cosh(x);
};
this.func__Cot = function(x) {
return 1 / Math.tan(x);
}
this.func__Coth = function(x) {
return 1/Math.tanh(x);
return 1 / Math.tanh(x);
};
this.func__Csc = function(x) {
return 1 / Math.sin(x);
};
this.func__Csch = function(x) {
return 1/Math.sinh(x);
return 1 / Math.sinh(x);
};
this.func__CWD = function() {
@ -330,11 +350,11 @@ var QB = new function() {
};
this.func__D2R = function(x) {
return x*Math.PI/180;
return x * Math.PI / 180;
};
this.func__D2G = function(x) {
return (x * 10/9);
return (x * 10 / 9);
};
this.func__DefaultColor = function(imageHandle) {
@ -1002,8 +1022,12 @@ var QB = new function() {
return _keyDownMap._ScrollLock ? -1 : 0;
};
this.func__Sec = function(x) {
return 1 / Math.cos(x);
};
this.func__Sech = function(x) {
return 1/Math.cosh(x);
return 1 / Math.cosh(x);
};
this.func__Setbit = function(x, y) {

View file

@ -3323,6 +3323,9 @@ if (QB.halted()) { return; };
await sub_AddQBMethod( "FUNCTION" , "_Alpha32" , False);
await sub_AddQBMethod( "FUNCTION" , "_Acos" , False);
await sub_AddQBMethod( "FUNCTION" , "_Acosh" , False);
await sub_AddQBMethod( "FUNCTION" , "_Arccot" , False);
await sub_AddQBMethod( "FUNCTION" , "_Arccsc" , False);
await sub_AddQBMethod( "FUNCTION" , "_Arcsec" , False);
await sub_AddQBMethod( "FUNCTION" , "_Atanh" , False);
await sub_AddQBMethod( "FUNCTION" , "_Asin" , False);
await sub_AddQBMethod( "FUNCTION" , "_Asinh" , False);
@ -3337,7 +3340,9 @@ if (QB.halted()) { return; };
await sub_AddQBMethod( "FUNCTION" , "_CommandCount" , False);
await sub_AddQBMethod( "FUNCTION" , "_CopyImage" , False);
await sub_AddQBMethod( "FUNCTION" , "_Cosh" , False);
await sub_AddQBMethod( "FUNCTION" , "_Cot" , False);
await sub_AddQBMethod( "FUNCTION" , "_Coth" , False);
await sub_AddQBMethod( "FUNCTION" , "_Csc" , False);
await sub_AddQBMethod( "FUNCTION" , "_Csch" , False);
await sub_AddQBMethod( "FUNCTION" , "_CWD$" , False);
await sub_AddQBMethod( "FUNCTION" , "_D2G" , False);
@ -3412,6 +3417,7 @@ if (QB.halted()) { return; };
await sub_AddQBMethod( "FUNCTION" , "_ScreenX" , False);
await sub_AddQBMethod( "FUNCTION" , "_ScreenY" , False);
await sub_AddQBMethod( "FUNCTION" , "_ScrollLock" , False);
await sub_AddQBMethod( "FUNCTION" , "_Sec" , False);
await sub_AddQBMethod( "FUNCTION" , "_Sech" , False);
await sub_AddQBMethod( "FUNCTION" , "_Setbit" , False);
await sub_AddQBMethod( "FUNCTION" , "_Shl" , False);

View file

@ -3544,6 +3544,9 @@ Sub InitQBMethods
AddQBMethod "FUNCTION", "_Alpha32", False
AddQBMethod "FUNCTION", "_Acos", False
AddQBMethod "FUNCTION", "_Acosh", False
AddQBMethod "FUNCTION", "_Arccot", False
AddQBMethod "FUNCTION", "_Arccsc", False
AddQBMethod "FUNCTION", "_Arcsec", False
AddQBMethod "FUNCTION", "_Atanh", False
AddQBMethod "FUNCTION", "_Asin", False
AddQBMethod "FUNCTION", "_Asinh", False
@ -3558,7 +3561,9 @@ Sub InitQBMethods
AddQBMethod "FUNCTION", "_CommandCount", False
AddQBMethod "FUNCTION", "_CopyImage", False
AddQBMethod "FUNCTION", "_Cosh", False
AddQBMethod "FUNCTION", "_Cot", False
AddQBMethod "FUNCTION", "_Coth", False
AddQBMethod "FUNCTION", "_Csc", False
AddQBMethod "FUNCTION", "_Csch", False
AddQBMethod "FUNCTION", "_CWD$", False
AddQBMethod "FUNCTION", "_D2G", False
@ -3633,6 +3638,7 @@ Sub InitQBMethods
AddQBMethod "FUNCTION", "_ScreenX", False
AddQBMethod "FUNCTION", "_ScreenY", False
AddQBMethod "FUNCTION", "_ScrollLock", False
AddQBMethod "FUNCTION", "_Sec", False
AddQBMethod "FUNCTION", "_Sech", False
AddQBMethod "FUNCTION", "_Setbit", False
AddQBMethod "FUNCTION", "_Shl", False