News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Hyper (precision) numeric data type

Started by i Z !, October 15, 2023, 07:38:52 PM

Previous topic - Next topic

jack

hello i Z !
I would be interested in testing you HyperLib but there several reasons that prevent that
1: prohibitive licence
2: closed source
3: binary distribution only, and worst, it comes as an installer

i Z !

Quote from: jack on August 31, 2024, 07:17:02 AMhello i Z !
I would be interested in testing you HyperLib but there several reasons that prevent that
1: prohibitive licence
2: closed source
3: binary distribution only, and worst, it comes as an installer

hi Jack,

points 1. and 2. are not preventing you from testing. For the 3rd, I silently hope that one day, you'll find the courage to just install the bloody thing :) it only takes a split second.
I'm planning to use this library in one of my bigger projects and I need to know whether the calculations are performed correctly 100% . I tested the boundaries, it appears to work well, but you never know :)

jack

iZ!
have you overloaded the basic arithmetic operators?
for example, how would you translate the following code to use your HyperLib ?
and set eps to something like 1e-1000
Dim As Double eps, Pi, x, y
x = 3
y = 1
Pi = x
eps = 1e-15

While (x > eps)
x = x * y / ((y + 1) * 4)
y += 2
Pi += x / y
Wend

Print Pi

jack

tried to compile the test solution found at your Git repo
QuoteSeverity   Code   Description   Project   File   Line   Suppression State   Details
Error (active)   BC30437   'Public Overrides Function NewFromString(S As String) As Integer' cannot override 'Public Overridable Function NewFromString(S As String) As String' because they differ by their return types.   Hyper Test   C:\Users\Admin\Desktop\Hyper-master\Hyper Test\Module1.vb   78      
if I remove "Overrides" then it compiles but the output are hexadecimal strings, the .toString method makes no difference
if you want the average person to try your Hyperlib then you need friendly input/output, who wants to see a bunch of hex strings?

i Z !

hey, thanks for trying it out,

Quote from: i Z ! on August 30, 2024, 07:29:57 AMP.S.: I recently noticed that full decimal representation has bugs, I removed the default property from it. Who needs it anyway :)

this is the reason why you can't see decimal by default, but you can change it with Hyper.displayMode = Hyper.displayModeType.inTrueDecimal
I know it's a bit tricky as you can't be sure about decimal output to do the checks, but you can try inputting pi just as Dim pi as new Hyper("3.14......") 'string can be of any length

I'm checking your code right now, it shouldn't take too much modification
 

i Z !

Quote from: jack on September 15, 2024, 12:14:49 AMand set eps to something like 1e-1000

to do this, I'd use something like
eps.Divide(10^18,precision) in a loop, after setting it to 1

EDIT:
Actually, Dim pi as New Hyper("1e-1000") should also work (with even aligning the buffer to least possible size as I remember, I'll check)

jack

I am sorry iz! but after all this time your Hyperlib doesn't have enough functionality for me to spend time on
I do my fun programming in FreeBasic which supports function and operator overloading, I wrote function and operator overloads for the LibBF Library, with that, the little Pi program looks like this
dim shared as long bf_digits = 1000 ' dim and set bf_digits before including bf.bi
#include "bf.bi"

Dim As bf eps, Pi, x, y
dim as double t=timer
x = 3
y = 1
Pi = x
eps = "1e-1000"

While (x > eps)
    x = x * y / ((y + 1) * 4)
    y += 2
    Pi += x / y
Wend
t=timer-t
Print Pi
Print "elapsed time in seconds = ";t
it completes in 0.0076 seconds
output
Quote3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511609433057270365759591953092186117381932611793105118548074462379962749567351885752724891227938183011949129833673362440656643086021394946395224737190702179860943702770539217176293176752384674818467669405132000568127145263560827785771342757789609173637178721468440901224953430146549585371050792279689258923542019956112129021960864034418159813629774771309960518707211349999998372978049951059731732816096318595024459455346908302642522308253344685035261931188171010003137838752886587533208381420617177669147303598253490428755468731159562863882353787593751957781857780532171226806613001927876611195909216420199

i Z !

try this:

  Hyper.displayMode = Hyper.displayModeType.inTrueDecimal

  Hyper.maxDigitsInString = 777 'display range

  Dim eps, Pi, x As Hyper

  prec% = 50
  Hyper.QuotientPrecision = prec 'defines for the '/' operator

  x = New Hyper("3")
  Dim y2& = 1
  Pi = New Hyper(x)
  eps = New Hyper("1")

  For i% = 0 To 90
      eps.Divide(10 ^ 18, prec)
  Next

  While x > eps
      x.Multiply(y2)
      x.Divide((y2 + 1) * 4, prec)
      y2 += 2
      Pi.Add(x / y2)
  End While

  Debug.WriteLine(Pi)

i Z !

i got

Quote3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511609433057270365759591953092186117381932611793105118548074462379962749567351885752724891227938183011949129833673362440656643086021394946395224737190702179860943702770539217176293176752384674818467669405132000568127145263560827785771342757789609173637178721468440901224953430146549585371050792279689258923542019956112129021960864034418159813629774771309960518707

with this, but you can play around with precision(s). Anyway, I'm not sure how much the decimal output can be relied upon...

Nice way of getting pi indeed :thumbsup:

i Z !

if you need only a small number for 'eps', you can do this by

Dim eps as New Hyper(-20,-20)
eps(-20) = 1

and set the (20*64)th bit after the decimal point. This way, the buffer size is only 1 QWORD

jack

iZ!
the point is, make the library function/behave as close as possible as if it were of type double, look how little I had to change to my little Pi program to make it's computations at high precision

i Z !

Quote from: jack on September 16, 2024, 12:05:27 AMiZ!
the point is, make the library function/behave as close as possible as if it were of type double, look how little I had to change to my little Pi program to make it's computations at high precision
yeah, it is kinda messy to work with Int64s. But it ensures that there's no unnecessary variable copying

mineiro

Quote from: jack on September 15, 2024, 07:48:26 PMI wrote function and operator overloads for the LibBF Library, with that, the little Pi program looks like this

Quote from: i Z ! on September 15, 2024, 10:11:18 PMNice way of getting pi indeed :thumbsup:

bellard it's a great programer, I suppose he's the creator of ffmpeg that most persons use today, also qemu, ..., . Also nncp data compression that uses neural network.
I'd rather be this ambulant metamorphosis than to have that old opinion about everything

i Z !

Quote from: mineiro on September 16, 2024, 01:23:21 AM
Quote from: jack on September 15, 2024, 07:48:26 PMI wrote function and operator overloads for the LibBF Library, with that, the little Pi program looks like this

Quote from: i Z ! on September 15, 2024, 10:11:18 PMNice way of getting pi indeed :thumbsup:

bellard it's a great programer, I suppose he's the creator of ffmpeg that most persons use today, also qemu, ..., . Also nncp data compression that uses neural network.

alright, useful info. But the pi procedure is something which Jack came up with, isn't it?

I've just noticed that we've got the same result, now I'm more confident in the decimal representation again :) idk, once I "caught it" when it changed the sign at a very small value

Jack, you can add operators I guess, in case you need them. Btw, I could write x /= (y2 + 1) * 4
Pi += x / y2
, but
x.Divide((y2 + 1) * 4, prec)
Pi.Add(x / y2)
is faster

NoCforMe

Quote from: i Z ! on September 15, 2024, 10:11:18 PMAnyway, I'm not sure how much the decimal output can be relied upon...

I really don't understand how you could feel confident about the results being shown in one radix (hex) but not in another (decimal). It's just a matter of character representation, no? Unless you have some kind of conversion routine in there that you're not sure about ...
Assembly language programming should be fun. That's why I do it.