[Release] CALCD.G4B - decimals, functions and more operators
#1
Posted 24 September 2022 - 10:27 PM
I solved my problems with the limitations of calc with respect to divisions: I surpassed the limit of 0x7FFFFFFF (2exp31-1) and extended division to the full range of calc: 07FFFFFFFFFFFFFF (2exp63-1) for dividend. For divider however max 0xCCCCCCCCCCCCCCC (about 1/10 of dividend).
If the dividend is too high for divisions and use of the remainder with calc, the script has a 'long division'-engine using substraction only.
If the number of digits of the dividend and/ or the divider exceeds the limits of calc another engine is used with a more complex 'long division' using decimals, 37-digit compare-functions and substraction + summation and comma-shifting.
New operators: exponentation, square root and cubic root (cubic root is limited to max 8-9 digits after rounding. Because of this limitation, CRT is only available as function).
Further a bunch of functions, one memory variable and various rounding possibilities.
Some print-screens (Main Help comes up with CALCD.G4B only, or CALCD.G4B help or CALCD.G4B /?:
Print-screens of some functions:
As can be seen on the second print-screen above, some functions can take their data from FILE. In the last example number of files+directories is counted, compare with output of FATLSDIR.G4B (still unpublished).
To make the story not too long a last print-screen with Help of quasi-operator INV together with calculation of the last Example. Showing more possibilities of using CALCD.G4B
BTW each operator or function has it's own help screen, just follow the lists in the main Help-screen.
For instance: CALCD.G4B help ^ or CALCD.G4B help COUNT
More general help: CALCD.G4B help mem and CALCD.G4B help syntax
Each screen gives some Examples too.
The script can be downloaded from https://github.com/deomsh/CALCD
Release v1.20: https://github.com/d...eases/tag/v1.20
#3
Posted 26 September 2022 - 09:34 PM
Thanks for testing.
You are right, not all Examples in help screen MEMORY are correct:
I tried to reconstruct my history of this part of HELP, but I am afraid there are some typo's.
Luckily the script is fully correct with message Abort: some argument is missing, check 'MR'
On the command-line of CALCD.G4B a number can only be used:
1) As first argument on the command-line, followed by an operator or followed by a quasi-operator
2) As first argument after a restart of calculation with '\\' (without quotes) followed by an operator/ quasi-operator
3) After an operator (NOT after a quasi-operator, because a new result will exist)
4) After a function, becoming an argument of that function
5) Only in case of MR (or R) as only argument on the command-line/ after restarting with '\\'
BTW placeholder MR is a number too.
Or should be: 1A + 2 is correctly identified as 'bad input' but 1A1 + 2 is not, I found out checkrange gives %@retval%=1 with 1A1 + 2 (in any range). Any solution? (See CALCD.G4B line 129)
So first Example CALCD.G4B MC 8 * 7 M+ MR + 1 is clearly wrong, should have been CALCD.G4B MC 8 * 7 M + MR + 1
Explanation what happens: if variable MR exist before use of CALCD.G4B, variable MR can has a value different from 0. To be sure I added MC, although M at the start should have the same effect: set MR=0
Second: 7 * 8 is same as in calc, only spaces are obligatory (reading-out the command-line with %~1, %~2 and so on - I learned from studying your terrific Ebook!). After the first calculation variable result is set to 56.
Third: with M variable MR is set too 56 too, but result is still 56, and + MR adds number 56 to existing result, and with + 1 the third calculation is completed. So echod result should be 113
Same for second example, only difference is M instead of MC (result should be 133 too).
Fourth example: CALCD.G4B /echoM 7 M + 8 * MR RM - 7 M+ is working (/echoM will show value of MR after all uses of M, RM and M+ (RM exchanges existing result and value of MR). Echod result should be 0 and last value of MR should be 105)
BTW2 sadly optional part in 'Use 2' is not correct. 'Use 3' is not correct too (I am afraid I was a bit too enthousiastic with Ctrl+V), will be 'repaired' in next version...
#4
Posted 26 September 2022 - 10:18 PM
Maybe check a variable is an integer like this?
calc %N1% ;; if not %N1%==%@retval% echo %N1% is an invalid integer
#5
Posted 27 September 2022 - 08:21 PM
Great idea, thanks a lot!
Seems to work for 'Bad input'.
Only numbers are limited with %@retval% to 0x7FFFFFFF (2exp31-1).
For instance with calcd.g4b 7 INV + 1 second calculation will start inevitable with 18 decimal digits in the intermediate result....
Is there a known memory address to read out the 64-bit values produced by calc ?
#6
Posted 27 September 2022 - 10:16 PM
How about
set N=TESTNUMBER set /A N1=%N% ;; if NOT %N1%==%N% echo %N% IS BAD NUMBER
#7
Posted 28 September 2022 - 08:19 PM
Thanks!
Also very useful.
I found out I can best use both of your approaches, last one for integers, first one (with my modification) in case of decimals
Integers (Approach II):
if not %N1%==0 && set /a N1=%N1% &; if %N1%==0 && set "message=Abort: bad input in '%~1'" && goto :eof
BTW typo's like 1 + 7M instead of 1 + 7 M are calculated without problems. And although the result will be bit higher than expected, still correct
Decimals (specific parts first, last Approach I):
if exist decimal1 &; if %decimal1%==0 && set decimal1= && set numdeci1=0 ! call Fn.11 "%decimal1%" "G" && set "message=Abort: bad input in '%~1'" && goto :eof ! call Fn.11 "%decimal1%" "g" && set "message=Abort: bad input in '%~1'" && goto :eof ! call Fn.11 "%decimal1%" "M" && set "message=Abort: bad input in '%~1'" && goto :eof ! call Fn.11 "%decimal1%" "m" && set "message=Abort: bad input in '%~1'" && goto :eof ! call Fn.11 "%decimal1%" "K" && set "message=Abort: bad input in '%~1'" && goto :eof ! call Fn.11 "%decimal1%" "k" && set "message=Abort: bad input in '%~1'" && goto :eof ! calc %decimal1% || set "message=Abort: bad input in '%~1'" && goto :eof
Some nice print-screens of debug in the newer versions of grub4dos (changed somewhere in 2020 ??):
Not possible: set /a decimal1=%decimal1%
Otherwise I will loose 'leading' zeros, if they exist. Calculations with decimals are already quite difficult
My script cannot process not-expanded g, m, and k in case of decimals because 'leading' zeros are counted too in variable numdeci (full count needed in all calculating subroutines).
#8
Posted 30 September 2022 - 09:41 AM
I have asked for calc to return 64 bit value in variable @retval64
https://github.com/c...4dos/issues/380
Can you test?
You can use set /A to get number in hex format or set /a to get number in decimal format.
#9
Posted 30 September 2022 - 10:35 PM
I tested the experimental version of GRLDR. Seems to be working good.
About divisioning numbers ABOVE 0x7FFFFFFF I didn't understand what Yaya ment in 'query: Is there a 64-bit variable for @retval #380'. Is this a new feature in the experimental GRLDR (and hopefully in next version of GRUB.EXE too), or was this division already possible with regular grub4dos versions?
I did two tests: next two print-sctreens show a division after booting from GRLDR (installed on a HD-image with BOOTLACE.COM 0x80). First print-screen with the experimental version of GRLDR, second with last regular version.
Last print-screens show booting GRLDR with chainloader from the grub4dos command-line and a 'high' division with the two GRLDR-versions.
If I am right, %@retval64% is not only an 'nice' addition in the new GRLDR, but if 'high' numbers can be divided too, also a change of what is possible with calc - so of fundamental importance.
BTW dates of GRLDR from 20221509 are not same in all print-screens because of different copying methods, one time from grub4dos with FAT, one time with Total Commander and IMdisk
#10
Posted 01 October 2022 - 08:10 AM
Yesterday's version is calculated as unsigned 64 bits.
Today's version is calculated in signed 64 bits.
Not sure what yaya means - best to test!
#12
Posted 01 October 2022 - 01:01 PM
P.S. I would suggest improving the initial help messages to make them clearer and add lots of examples.
Hopefully this will encourage others to test your calcd.g4b. At the moment it is quite hard to understand how to use it.
maybe if there is a syntax error you can just output a message on how to get more help on each function.
e.g. maybe
calcd Calculator for integer and decimal numbers (limits here) Functions: SUM PRODUCT Operators: + -Post-op: SORT INV Memory: MC M M+ M- MR RM Command separator: \\ More help: calcd help examples Syntax help: calcd help syntax Op/Func help: calcd help (function) - e.g. help memory, help +, help -, help sum
I would also suggest getting rid of "==" and replace with EQU LTE GTE
also use PERM COMB CUBERT
SQUARE and CUBE to be added (or SQU and CUB) ?
tip: You can use echo -e \xnn to output any ANSII character
e.g.
echo -e \x5c
\
colour can be temporarily changed using $[colour] and $[] to go back to default colour.
echo -e This is a white slash on a green background $[0x2f]\x5c$[] - now normal colour again.
\x7c is vertical pipe symbol
hth
#13
Posted 01 October 2022 - 10:30 PM
Thanks a lot for all your suggestions
I am already planning to reorganize the Help-part, but a small 'Reminder-help' after a message is a nice idea. It must fit however in my message-system. Originally developed for Loosely Linked Library (originally Wonko's ideas), I think they should be silent. I have plans for CALCD.LLL too, but for now it seems better to continue development of CALCD.G4B.
About CUBERT: I found CBRT is a used abbreviation and 'sound' matches nice with SQRT.
About X2 and X3 as 'Post-op' (your phrase sounds better than my 'quasi-operator): I added two sub-routines for now with names SQ and CB. I would be very greatful too if other readers have suggestions for SHORT names or good abbreviations.
Also I found FACT is used as an abbreviation for FACTORIAL, sounds better then my FAC
One print-screen with changes (together with use of switch /echo):
There is not much 'space' left however, unless I split up CALCD.G4B as you can see in next print-screen:
About echoing: thanks, I am aware of ASCII-codes but I only use them if I have to. Personally I found echo -e \\\\ nice.
About $[]: I studied the paragraphs about colors in your Ebook many times. I vaguely remember I had some problems using $[] in a script. But not for sure, can not reproduce on the command-line.
I tried to use colors and highlighting during the development of CALCD.G4B, but there is a problem I cannot solve. From the command-line this problem does not really exist, and from a script only if echoing with for instance $[0xF0]. The background color of one echo continues after a following echo.
Echoing with or without $[] and/ or -e and/ or -n makes no difference. Text-colors are not the problem, only background colors.
See the last print-screen:
Any ideas?
BTW on the command-line I found for instance same problem with echo $[0xF0]YES$[] ;; echo $[0x10]NO$[]
#15
Posted 02 October 2022 - 12:09 PM
The problem is more subtle, and NEVER exist with ONE echo including highlighting (some background color).
I extended your script a bit. On first print-screen everything is normal, like you expected:
Continuing on the command-line after reaching line 24 however gives a different picture:
As you can see there are artefacts.
These artefacts seem to disappear after the command clear.
Sadly this is not always possible OR desirable.
Can you reproduce?
BTW: I used Virtual Box Version 6.0.18 r136238 (Qt5.6.2)
#16
Posted 02 October 2022 - 01:11 PM
I had problems reproducing because you MUST have a space after NO$[] in your batch file otherwise it works OK!
The issue seems to occur in graphicsmode 3 which is the default text mode. I use 800 x 600 for my menu system.
If you type graphicsmode -1 800 first then it is OK
clear command seems to help but not cure!
I will report it as a bug.
https://github.com/c...4dos/issues/381
#17
Posted 02 October 2022 - 02:24 PM
I 'discovered' today start of problem from line 24 and using clear as a new possibility, so at least something.
However adding a space after $[] - so $[]\x20 - made no difference in my case.
I tried various combinations of Vbox (other chipset, less virtualization, other display, more video-memory), but no difference. Even if not-using-ImDisk to have access to my floppy-images
On the other hand: on Limbo x86 on my smartphone (android) the problem does not seem to exist.
Sadly I am 'sticked' to normal text-mode because three of my scripts are using 25 lines. And a 'real' colour-mode with 25 lines does not seem to exist (I have searched earlier if i remember well).
Earlier I found out switching graphicsmode from inside a script is not possible using grub4dos-commands (but once I succeeded using WENV - already long time ago).
BTW I can confirm with graphicsmode 0x142 and 0x143 there are no artifacts in Vbox.
#18
Posted 02 October 2022 - 05:07 PM
you can switch graphicsmode from a script as long as that mode it is supported by the graphics adaptor BIOS.
I use
graphicsmode -1 800
or
graphicsmode -1 1024
These days, as 1024x768 is the default mode for UEFI BIOSes, 1024 is pretty safe to use but you can always use both commands and if the last 1024 command fails then the 800 command should have worked. You should always follow it with a clear command to be safe.
but for a helper utility such as calcd it obviously should not change colours, mode or clear the screen.
#19
Posted 02 October 2022 - 06:58 PM
Thanks a lot.
I changed your TEXT.G4B a bit for testing
!BAT #graphicsmode 3 graphicsmode -1 640 > nul && pause graphicsmode set to -1 640 Key... #graphicsmode -1 800 > nul #graphicsmode -1 1024 > nul pager off set C=0 :LOOP if %C%==1 && graphicsmode -1 800 > nul && pause graphicsmode set to -1 800 Key... if %C%==2 && graphicsmode -1 1024 > nul && pause graphicsmode set to -1 1024 Key... set /a C=%C%+1 > nul (....)
Works, in (my current versions of) Vbox and Limbo x86 both!
Good to know, if needed I can read-out graphicsmode, force graphicsmode 3 and give original mode back.
Also your fall-back method sounds very good.
#20
Posted 03 October 2022 - 07:18 AM
Limbo x86 is based on QEMU.
As reported problems are on Virtual Box. When I am back home I will test on real hardware.
#21
Posted 11 January 2023 - 10:13 PM
New version of CALCD.G4B ready.
CALCD.G4B v0.2.1 (20221211)
Output Echood, if exists: in variables 'result' 'MR' 'R' 'resrnd' and 'message'
Prefix Functions: SUM PRODUCT MEAN VARP VARS STDEVP STDEVS FACT Pnr Cnr "==" ">=" "<=" COUNT
MIN MAX COUNTIF
Use CALCD.G4B [switch] function number1 [number2]|number1 number2|args
Infix Operators: + - * / ^ Functions: ROUND DECI DIGI FIX
Use CALCD.G4B [switch] number1 operator|function number2|NUMBER
Postfix Functions: INV SQRT SQ CBRT CB HEX THSEP
Use CALCD.G4B [switch] number function
Memory Functions: M M+ M- RM Clear: MC Placeholders for number: MR R
Numbers ± 10exp-18 - 2exp63-1, 0!-20!, MR, R (integers hex too, decimals: dot)
Help CALCD.G4B help|--help|/? [function|operator|mem|ver]
BTW After fatal errors text above is showed always - if you do not like it (anymore) use remarked-out line 89 instead of line 88 (and disable line 88)
New in v0.2.1
Bugfixes (especially in Cubic Root)
Cubic Root (CBRT) gives 18 decimals now (but not rounded!)
Function CRT renamed to CBRT
Function FAC renamed to FACT
Simpler handling of multiple calculations on command-line:
- Continue/ restart calculation with \\ only needed after COUNT
- Functions INV, SQRT and M cannot be used before there argument anymore
- Function CBRT must now be used after argument
- Single number on command-line allowed (including MR, R and 0!-20!)
Help has been rewritten, about 250 examples
New functions:
HEX: convert number/ result to hexa-decimal number (rounddown!)
THSEP: adds thousands-comma-separator to last number/ result (input with thousands-comma's allowed too)
SQ: Square of number
CB: Cubic of number
MIN: lowest number on command-line/ (md)
MAX: highest number on command-line/ (md)
COUNTIF: count of numbers on command-line/ (md) 'satisfying' if-condition
New switch: /Q for quiet operation
Display of 'smallhelp' after (syntax-)error
I hope new terminoloqy of function-types 'prefix', 'infix' and 'postfix' with placement of their arguments is helpful.
I found 'Post-op' is used in cases like '2!', the '!' is post-operator.
BTW: I'd like to thank steve6375 for his suggestions, although some Function names will not be altered.
Also I'd like to thank our teacher of Cambridge-English who helped with my abbreviation of Thousand Separator (THSEP). We didn't found any existing abbreviation.
#22
Posted 12 January 2023 - 11:52 PM
ADDITION to Post above
Some 'action' print-screens of new functionality in CALCD.G4B v0.2.1:
BTW on second print-screen can be seen that last result can be used as implicit argument, just like on a 'normal' calculator (as long variable R exists). WATCH: only if this argument comes before function/ operator, so not working in case of prefix functions (but R can be used as explicit argument too).
On last print-screen Abort-message after syntax-error with 'smallhelp':
Can't post anymore
SQL-error:
mySQL query error: SELECT COUNT(*) as topicviews FROM ibf_topic_views WHERE views_tid=22665
#23
Posted 12 January 2023 - 11:57 PM
To delete
#24
Posted 12 January 2023 - 11:58 PM
To delete
#25
Posted 13 January 2023 - 12:00 AM
To delete
Also tagged with one or more of these keywords: grub4dos
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users