Jump to content











Photo
- - - - -

[Release] CALCD.G4B - decimals, functions and more operators

grub4dos

  • Please log in to reply
19 replies to this topic

#1 deomsh

deomsh

    Frequent Member

  • Advanced user
  • 196 posts
  •  
    Netherlands

Posted 24 September 2022 - 10:27 PM

My script CALCD.G4B supports the use of decimals and contains a set of functions and some extra operators too (max 19 integers + 18 decimals). In some cases I had to use 'high precision methods', which is just a phrase for elementary arithmetics using 'carrying' etcetera.

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 /?:

CALCD.G4B help.jpg CALCD.G4B Operators and quasi-operators I.jpg CALCD.G4B Operators and quasi-operators II.jpg

Print-screens of some functions:

CALCD.G4B Functions I.jpg CALCD.G4B Functions II.jpg

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

CALCD.G4B help INV + last Example with echoR.jpg

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

#2 steve6375

steve6375

    Platinum Member

  • Developer
  • 7566 posts
  • Location:UK
  • Interests:computers, programming (masm,vb6,C,vbs), photography,TV,films
  •  
    United Kingdom

Posted 26 September 2022 - 10:57 AM

Great work. Looks good.

The examples for memory don't seem to work ??

Do I need to add \\   ??

 

Attached Thumbnails

  • calcex1.JPG


#3 deomsh

deomsh

    Frequent Member

  • Advanced user
  • 196 posts
  •  
    Netherlands

Posted 26 September 2022 - 09:34 PM

Thanks for testing.

 

You are right, not all Examples in help screen MEMORY are correct:

 

CALCD.G4B THREE Erronous Examples in HELP MEM.jpg

 

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 steve6375

steve6375

    Platinum Member

  • Developer
  • 7566 posts
  • Location:UK
  • Interests:computers, programming (masm,vb6,C,vbs), photography,TV,films
  •  
    United Kingdom

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 deomsh

deomsh

    Frequent Member

  • Advanced user
  • 196 posts
  •  
    Netherlands

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).

 

Steve6375's idea filtering non-numbers by using calc %N1% ;; if not %N1%==%@retval% echo %N1% is an invalid integer I.jpg

 

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 steve6375

steve6375

    Platinum Member

  • Developer
  • 7566 posts
  • Location:UK
  • Interests:computers, programming (masm,vb6,C,vbs), photography,TV,films
  •  
    United Kingdom

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 deomsh

deomsh

    Frequent Member

  • Advanced user
  • 196 posts
  •  
    Netherlands

Posted 28 September 2022 - 08:19 PM

Thanks!

Also very useful. :rolleyes:

 

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 :blink:

 

 

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 ??):

 

CALCD.G4B debug view filtering decimals using Steve6375's ideas I.jpg CALCD.G4B debug view filtering decimals using Steve6375's ideas II.jpg

 

Not possible: set /a decimal1=%decimal1%

Otherwise I will loose 'leading' zeros, if they exist. Calculations with decimals are already quite difficult :wacko:

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 steve6375

steve6375

    Platinum Member

  • Developer
  • 7566 posts
  • Location:UK
  • Interests:computers, programming (masm,vb6,C,vbs), photography,TV,films
  •  
    United Kingdom

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.

Attached Thumbnails

  • calc64.JPG
  • calc64K.JPG


#9 deomsh

deomsh

    Frequent Member

  • Advanced user
  • 196 posts
  •  
    Netherlands

Posted 30 September 2022 - 10:35 PM

I tested the experimental version of GRLDR. Seems to be working good. :D

 

TEST calc with %@retval64% = experimental GRLDR 20223009 320237 byte I.jpg

 

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.

 

TEST calc after booting from GRLDR installed on (hd0,0) with bootlace.com 0x80 (experimental GRLDR 20220930 320237 byte) high division OKE VII.jpg TEST calc after booting from GRLDR installed on (hd0,0) with bootlace.com 0x80 (normal GRLDR 20220915 319845 byte) NO high division VIII.jpg

 

Last print-screens show booting GRLDR with chainloader from the grub4dos command-line and a 'high' division with the two GRLDR-versions.

 

Booting GRLDR with chainloader from grub4dos I.jpg TEST calc after loading GRLDR from GRUB.EXE with chainload (normal GRLDR 20220915 319845 byte) NO high division III.jpg TEST calc after loading GRLDR from GRUB.EXE with chainload (experimental GRLDR 20220930 320237 byte) high division OKE VI.jpg

 

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 :ph34r:



#10 steve6375

steve6375

    Platinum Member

  • Developer
  • 7566 posts
  • Location:UK
  • Interests:computers, programming (masm,vb6,C,vbs), photography,TV,films
  •  
    United Kingdom

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!



#11 deomsh

deomsh

    Frequent Member

  • Advanced user
  • 196 posts
  •  
    Netherlands

Posted 01 October 2022 - 12:05 PM

Nice, but I do not see any difference, IMHO both versions are signed 64-bit

I also tested CALCD.G4B, being a big script, and FAT to see if it's compatible

GRLDR_20220930_TEST_SIGNED_64BIT+FAT_COPY.png GRLDR_20221001_TEST_SIGNED_64BIT+CALCD_v121.png

BTW a preview on new functionality of CALCD.G4B v0.1.21 too

#12 steve6375

steve6375

    Platinum Member

  • Developer
  • 7566 posts
  • Location:UK
  • Interests:computers, programming (masm,vb6,C,vbs), photography,TV,films
  •  
    United Kingdom

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 deomsh

deomsh

    Frequent Member

  • Advanced user
  • 196 posts
  •  
    Netherlands

Posted 01 October 2022 - 10:30 PM

Thanks a lot for all your suggestions  :rolleyes:

 

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 Xas '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):

 

CALCD.G4B possible changes in v1.21 = CBRT CB SQ and FACT I.jpg

 

There is not much 'space' left however, unless I split up CALCD.G4B as you can see in next print-screen:

 

TEXTSTAT CALCD.G4B v.0.1.21D_Vbox (20221001).jpg

 

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:

 

CALCD.G4B problems AFTER echo $0xF0 - with and without -n and or -e I.jpg

 

Any ideas?

 

BTW on the command-line I found for instance same problem with echo $[0xF0]YES$[] ;; echo $[0x10]NO$[]



#14 steve6375

steve6375

    Platinum Member

  • Developer
  • 7566 posts
  • Location:UK
  • Interests:computers, programming (masm,vb6,C,vbs), photography,TV,films
  •  
    United Kingdom

Posted 01 October 2022 - 10:36 PM

Re. Colours
 

Attached Thumbnails

  • texttest.JPG
  • texttest2.JPG


#15 deomsh

deomsh

    Frequent Member

  • Advanced user
  • 196 posts
  •  
    Netherlands

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:

 

Echo Colortest I.jpg

 

Continuing on the command-line after reaching line 24 however gives a different picture:

 

Echo Colortest II.jpg

 

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 steve6375

steve6375

    Platinum Member

  • Developer
  • 7566 posts
  • Location:UK
  • Interests:computers, programming (masm,vb6,C,vbs), photography,TV,films
  •  
    United Kingdom

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 deomsh

deomsh

    Frequent Member

  • Advanced user
  • 196 posts
  •  
    Netherlands

Posted 02 October 2022 - 02:24 PM

Thanks a lot for your efforts.

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.

Echo Colortest III.jpg Echo Colortest IV.jpg

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.

Colortest_Limbox86_no_artefacts_after_line_24.png

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 steve6375

steve6375

    Platinum Member

  • Developer
  • 7566 posts
  • Location:UK
  • Interests:computers, programming (masm,vb6,C,vbs), photography,TV,films
  •  
    United Kingdom

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 deomsh

deomsh

    Frequent Member

  • Advanced user
  • 196 posts
  •  
    Netherlands

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 deomsh

deomsh

    Frequent Member

  • Advanced user
  • 196 posts
  •  
    Netherlands

Posted 03 October 2022 - 07:18 AM

I saw yaya's comment.

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 deomsh

deomsh

    Frequent Member

  • Advanced user
  • 196 posts
  •  
    Netherlands

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. :rolleyes:

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 deomsh

deomsh

    Frequent Member

  • Advanced user
  • 196 posts
  •  
    Netherlands

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 deomsh

deomsh

    Frequent Member

  • Advanced user
  • 196 posts
  •  
    Netherlands

Posted 12 January 2023 - 11:57 PM

To delete



#24 deomsh

deomsh

    Frequent Member

  • Advanced user
  • 196 posts
  •  
    Netherlands

Posted 12 January 2023 - 11:58 PM

To delete



#25 deomsh

deomsh

    Frequent Member

  • Advanced user
  • 196 posts
  •  
    Netherlands

Posted 13 January 2023 - 12:00 AM

To delete







Also tagged with one or more of these keywords: grub4dos

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users