News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Hyper (precision) numeric data type

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

Previous topic - Next topic

jj2007

Quote from: jack on October 17, 2023, 02:19:44 AMsuit yourself, MIT is one the most simplest licenses, if you can't understand that then I doubt your ability to code a decent MP library

IMHO before accusing others to be unable to code, you should start coding yourself


i Z !

Quote from: jack on October 17, 2023, 12:21:36 AMnot really, I also have dabbled in writing my own multi precision arithmetic routines, just for fun.

It's fun that's for sure, I think I enjoyed writing it the most from all my projects 'til now


NoCforMe

Quote from: jack on October 17, 2023, 02:19:44 AMsuit yourself, MIT is one the most simplest licenses, if you can't understand that then I doubt your ability to code a decent MP library

My friend, it's you who seems not to understand: the author doesn't want to grant free use for commercial purposes. What don't you get about that?

It's got nothing to do with simplicity.
Assembly language programming should be fun. That's why I do it.

i Z !

#20
ok, here's an example code (also updated on GitHub), if it makes it more attractive  :smiley:
    Dim a As New Hyper(5, 0) ' initialize an integer with 6 * 64 bits
        Dim b As New Hyper(-1, -4) ' float with 4 * 64 bits
        a(5) = 50000 : a(3) = 50000 ' this is 50000*(2^64)^5 + 50000*(2^64)^3
        b(-1) = -50000 : b(-3) = 50000 ' = -50000*(2^64)^(-1) + 50000*(2^64)^(-3)

        Dim precision% = 914 'we need high precision since we're dividing with a multiple of 5, which results in a repetitive non-integral value in binary system
        Dim c As New Hyper(0, -precision)
        c(0) = 1

        'get value of 1e-60 into c
        For i = 1 To 4
            c.Divide(10 ^ 15, precision)
        Next

        Hyper.maxDigitsInString = 255 'this number gets aligned to a multiple of 18 in the decimal ToString method's output
        Console.WriteLine(c) : Console.WriteLine()

        Console.WriteLine(a)
        Console.WriteLine(a * c) : Console.WriteLine()

        Console.WriteLine(b)
        Console.WriteLine(b * c) : Console.WriteLine()

        Console.WriteLine(a * b)
        Console.WriteLine(a * b * c)

        Console.ReadKey()


    ' output:
    ' 0.000001 e-54
    '
    ' 106799351796 045504119751085308 477605730449081204 601972535543869862 271369609837145273 371306072473600000
    ' 106799351796045504119751085308477605730449.081204601972535543869862271369609837145273371306072473600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
    '
    ' -0.00000000000000271050543121376108501863200217485427855648766544433773861485559801116144097204447722403690606963057073306918549243470919528455062639908657029508276536944322288036346435546875
    ' -0.00271050543121376108501863200217485427855648766544433773861485559801116144097204447722403690606963057073306918549243470919528455062639908657029508276536944322288036346435546875 e-72
    '
    ' -289480223093290 488558927462521719 769633174961664101 410098643960019782 824099837500000000
    ' -289480223093290488558927462.521719769633174961664101410098643960019782824099837500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

NoCforMe

So how do we know that result is correct?

(Ha ha, just kidding ...)
Assembly language programming should be fun. That's why I do it.

i Z !

oh, you mean for a * b... we assume that  :smiley:

NoCforMe

But doing that makes an ASS out of U and ME ...
Assembly language programming should be fun. That's why I do it.

i Z !

No it only presents us AS SUM of E  :smiley:
My thinking is, if it multiplies by 1e-60 with no error, which is in binary quite an odd repetitive number, then it has no alibi to fail with anything else

NoCforMe

But seriously, have you actually checked those results? (I have no friggin' idea how you would even do that. Calculator's not gonna help you here.)

Kind of like the satellite, the Mars Climate Orbiter that burned up because someone didn't check their number system (metric vs. "imperial"). Or something like that.

I suppose you could feed the results back into another program which does the inverse operation that was done, see if you get the original values?
Assembly language programming should be fun. That's why I do it.

i Z !

i tried adding this code
c = a * b

        a = New Hyper(0, 0)
        While c.IsNegative  '.IsNotZero
            c.Subtract(b)
            a.Incr()
        End While
        Console.WriteLine(a)

as you can imagine, that WHILE block was taking quite a WHILE  :smiley: so I stopped it after a few minutes

i Z !

Quote from: NoCforMe on October 18, 2023, 07:31:52 PMI suppose you could feed the results back into another program which does the inverse operation that was done, see if you get the original values?

When I was writing the procedure for division by Int64, i think i knew how to include other int64 digits while performing the operation. At the time I thought to myself, it won't be needed... Then I later tried to implement it another way but without success.

I have to write at least the 1/x function

raymond

Quotethen it has no alibi to fail with anything else

... unless you try to compute the circumference of a circle from that diameter (or the opposite).
Whenever you assume something, you risk being wrong half the time.
http://www.ray.masmcode.com

i Z !

Quote from: raymond on October 19, 2023, 02:10:20 AM
Quotethen it has no alibi to fail with anything else

... unless you try to compute the circumference of a circle from that diameter (or the opposite).

 'fail' was referring to multiplication. You mean because there's no pi? You'd need to calculate pi first... after you wrote the procedure for sqrt :)