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

i Z !

Quote from: NoCforMe on September 16, 2024, 08:17:17 AM
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 ...


hey noCforme,
yes, quite a lot of computing needs to be done to convert from one another. The hex output shows bits as they are in memory, for decimal I need to convert. I think I'll post the procedures here, see if anyone can spot the bugs...

jack

iZ!
I played with your library for a bit, the hexadecimal printout of Pi seem to be right
QuotePi
(0)     0000000000000003
(-1)    243F6A8885A308D3
...
but Pi/4 seems off
QuotePi/4
(0)     0000000000000001
(-1)    C90FDAA22168C235
...
why is there a 1 in (0) element?
also, setting eps = New Hyper("1e-1000") doesn't work right, had to use eps = New Hyper("1e-1018")
but when setting eps = New Hyper("1e-2018") the Pi program only gives 718 correct digits
I think that you need to fix/fine tune your conversion routines, also you need to implement MP division, currently you only have division by Integer

i Z !

Quote from: jack on September 16, 2024, 10:53:00 PMiZ!
I played with your library for a bit, the hexadecimal printout of Pi seem to be right
QuotePi
(0)    0000000000000003
(-1)    243F6A8885A308D3
...
it prints out pi correctly in decimal too

Quote from: jack on September 16, 2024, 10:53:00 PMwhy is there a 1 in (0) element?

Ha! :) because it is a balanced numeral system => 0.5 is represented as ...00001.100000... every top bit in QWORD is negative

i Z !

Quote from: jack on September 16, 2024, 10:53:00 PMalso, setting eps = New Hyper("1e-1000") doesn't work right, had to use eps = New Hyper("1e-1018")
but when setting eps = New Hyper("1e-2018") the Pi program only gives 718 correct digits

I know these don't work for some reason... Please use

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

or

Quote from: i Z ! on September 15, 2024, 10:38:36 PMif 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


if the value doesn't need to be a divisor of 10.


Quote from: jack on September 16, 2024, 10:53:00 PMto implement MP division, currently you only have division by Integer

For now, I'm leaving this to the user to help himself with the QuickDivide procedure :) but yeah, you're right, I'll have to look into it, to optimally adjust the precision

jack

Quote from: i Z ! on September 16, 2024, 11:35:55 PMHa! :) because it is a balanced numeral system => 0.5 is represented as ...00001.100000... every top bit in QWORD is negative
is there any advantage to using this "balanced numeral system" ?
the output is confusing, the hex value of Pi is exactly the same as Pi in base 16, same with Pi/4 except that you have a 1 in (0)
I did some timing comparison of HyperLib vs my binary floating point package using my little Pi program with eps=1e-1018
I compiled your Hyper version to x64 release and it didn't fare well against mine
but seriously, good input and output is essential, entering numbers using Hyper(-20,-20) is only acceptable to you the developer

i Z !

Quote from: jack on September 17, 2024, 12:52:07 AMis there any advantage to using this "balanced numeral system" ?

Yes.  No rounding error + no need of filling bits when expanding mantissa's size

Quote from: jack on September 17, 2024, 12:52:07 AMI did some timing comparison of HyperLib vs my binary floating point package using my little Pi program with eps=1e-1018
I compiled your Hyper version to x64 release and it didn't fare well against mine

I'm almost sure that by playing with precision (now it's 50*64 bits), you could pimp it to perform faster than yours

i Z !

just make sure you're using the same value for eps in both tests. And, I would measure time only for the computational part, skipping the time taken for assigning the variables

jack

to be fair, my binary FP is written in FreeBasic using the gcc backend, it would be too painful to rewrite in VB.Net
one problem with your HyperLib is that precision control is not accurate, after some trial and error I found that if Precision = 9000, eps = "10018" then Pi is calculated to 10005 correct digits
FB has reliable and easy constructor/destructor mechanisms whereas I found it impossible for VB.Net to invoke the destructor or Finalize, I finally gave up in disgust
I don't care to pursue this topic any further, good luck

i Z !

Quote from: jack on September 17, 2024, 03:22:17 AMit would be too painful to rewrite in VB.Net
why'd you want to do that anyway?

Quote from: jack on September 17, 2024, 03:22:17 AMone problem with your HyperLib is that precision control is not accurate, after some trial and error I found that if Precision = 9000, eps = "10018" then Pi is calculated to 10005 correct digits
Please explain further, what do you mean "precision control is not accurate"? Precision in hyperlib is expressed as negated lowest exponent (which is 2^64 based, not 10)

Quote from: jack on September 17, 2024, 03:22:17 AMFB has reliable and easy constructor/destructor mechanisms whereas I found it impossible for VB.Net to invoke the destructor or Finalize, I finally gave up in disgust
I'm not sure, but maybe you're looking for something like "x = Nothing" and then, if needed, "GC.Collect" ?

TimoVJL

VB.Net modules should test in many CPUs, as it isn't native code and sometimes locally optimized in target system.
May the source be with you

jack

Q1: to make a fair comparison on the performance of your Hyper vs my FP, but it's not practical to convert to VB.Net
Q2: I think it's stated clearly enough
Q3: I placed a Console.WriteLine("Finalize()") in Sub Finalize() to see whether it would get called but it never does
when a variable created by Sub New() that allocates memory goes out of scope it needs to de-allocate said memory but finalize never gets called

i Z !

Quote from: jack on September 18, 2024, 02:23:09 AMwhen a variable created by Sub New() that allocates memory goes out of scope it needs to de-allocate said memory but finalize never gets called

you got me there, Sub Finalize is my weak spot, I never use/implement it... but don't you think "x = Nothing" and "GC.Collect" would do the job? You could also unassign the buffer by "x = New Hyper(0,0)"
Also, it is possible to have an external array as buffer
Dim ar&(30)
 Dim h as New Hyper(ar) 'or maybe an extra argument for the exponent
and then you can dispose of that array which ever way you want

i Z !

@jack, I haven't tried, but I guess you could reference hyperlib from outside of VS environment. The dll is located in "Program Files\iZ!"