Large(ish) Number Library - 2023/02/09 - v2.0.2

Post your working scripts, libraries and tools.
User avatar
TheArkive
Posts: 1027
Joined: 05 Aug 2016, 08:06
Location: The Construct
Contact:

Large(ish) Number Library - 2023/02/09 - v2.0.2

Post by TheArkive » 12 Jul 2022, 12:40

image.png
image.png (9.13 KiB) Viewed 1702 times

Handles numbers as strings, with few practical limits. My testing seems to indicate performance is decent. But I have yet to devise a decent "stress test" for mass computation and performance.

I'm actually not well versed in such things, so if someone can suggest a few links then I'll try to formulate the suggested stress test.

Features:
  • Addition
  • Subtraction
  • Multiplication
  • Division
  • Configurable decimal precision on division (with no rounding)
  • DivI() returns integer (Floor Division //)
  • Mod() returns remainder
  • DivIM() returns integer and remainder
  • Decimals are no problem
  • Exponents
  • Comparisons (> < >= <= =)
  • Rounding (like AHK Round())
  • Dec to Hex conversion
  • Hex to Dec conversion
  • Dec to Binary conversion
  • Binary to Dec conversion
============================================
Updates
============================================

To-Do List
  • check for more bugs, inaccuracies
:arrow: Download on GitHub
Last edited by TheArkive on 27 Mar 2023, 11:23, edited 6 times in total.

User avatar
TheArkive
Posts: 1027
Joined: 05 Aug 2016, 08:06
Location: The Construct
Contact:

Re: Large(ish) Number Library - 2022/07/14 - beta.6

Post by TheArkive » 14 Jul 2022, 10:23

2022/07/14
  • fixed DecToHex logic
  • fixed logic in DecToBin()
  • added bit_width param to conversion functions
    this is for either add zero-padding or truncating the number based on bit_width (kind of like casting)
  • Changed Div() to be variadic, needed for negative exponents
  • Changed Exp() to now support negative exponents
  • DecToHex(), HexToDec(), DecToBin(), and BinToDec() now handle negative numbers
Proper docs are next on my to-do list.

lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: Large(ish) Number Library - 2022/07/14 - beta.6

Post by lexikos » 15 Jul 2022, 01:37

You might consider removing the global dbg function in case someone who defines their own wants to use your library.

User avatar
TheArkive
Posts: 1027
Joined: 05 Aug 2016, 08:06
Location: The Construct
Contact:

Re: Large(ish) Number Library - 2022/07/14 - beta.6

Post by TheArkive » 15 Jul 2022, 01:41

You're right. Those are left overs. I'll do that soon.

User avatar
TheArkive
Posts: 1027
Joined: 05 Aug 2016, 08:06
Location: The Construct
Contact:

Re: Large(ish) Number Library - 2022/07/15 - beta.6

Post by TheArkive » 15 Jul 2022, 14:11

2022/07/15
  • docs added
... and the junky dbg() func is moved out of the lib file.

gmoises
Posts: 74
Joined: 18 Nov 2017, 16:43

Re: Large(ish) Number Library - 2022/07/15 - beta.6

Post by gmoises » 08 Feb 2023, 17:25

I tried Large(ish) Number Library - 2022/07/15 - beta.6
with AutoHotKey v2.0.2

I had to add the line _d_p := 0 just inside _div():

Code: Select all

	_div(x,y,&remain:=0) { ; x = dividend, y = divisor, remain = remainder
		_d_p := 0
The example script "Large Numbers Exampe.ahk" works
but I could not get the divisions right:

Code: Select all

; https://github.com/TheArkive/large_numbers_ahk2
#Requires AutoHotkey v2.0 64-bit
#Include Large Numbers.ahk
Obj := Math(16)
a := "799654708521478360985204793345804782146322647831036047852"
b := "1236504799654708521478360985204793345804782146328795"
MsgBox("Addition`n" . Obj.Add(a, b)
	. "`n`nSubstraction`n" . Obj.Sub(a, b)
	. "`n`nMultiplication`n" . Obj.Mult(a, b)
	. "`n`nDivision`n" . Obj.Div(a, b))

User avatar
TheArkive
Posts: 1027
Joined: 05 Aug 2016, 08:06
Location: The Construct
Contact:

Re: Large(ish) Number Library - 2022/07/15 - beta.6

Post by TheArkive » 10 Feb 2023, 04:20

Fixed in latest push to repo (yesterday)

gmoises
Posts: 74
Joined: 18 Nov 2017, 16:43

Re: Large(ish) Number Library - 2023/02/09 - AHK v2.0.2

Post by gmoises » 10 Feb 2023, 10:26

Thank you, it works great.

Post Reply

Return to “Scripts and Functions (v2)”