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 iZ!, October 15, 2023, 07:38:52 PM

Previous topic - Next topic

iZ!



- A bug in the Add procedure has been found, squashed and burnt alive
- Decimal exponent now supported in the input string, i.e. New Hyper("123.221e-5510")
- Add(Int64, Exp64) function added to perform addition on a single Digit.
- Incr, Decr operations added
- Intellisense descriptions now (finally) work


Quote from: jack on November 01, 2023, 06:19:08 AMPS I don't like installers, if it can be helped I would rather have zip archive
I see, we'll see :)

jj2007

Quote from: i Z ! on November 01, 2023, 07:15:38 PMbtw references with examples are also available now

Good, but even better would be a complete example that builds with the Masm64 SDK :thumbsup:

Quote from: i Z ! on November 02, 2023, 01:21:43 PMv1.1.0

Jotti reports it as Trojan.MSIL.Crypt. Nonetheless I tried to run the installer and got a few errors, see below (Win7-64). Re Access to path 'iZ!' denied.: I created C:\iZ! manually, no problem, but the installer still complains.

QuoteInformation on how to invoke JIT (Just-In-Time) debugging instead of this window
is given at the bottom of the message.

************** Exception text **************
System.UnauthorizedAccessException: Access to path 'iZ!' denied.
  in System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath).
  in System.IO.Directory.InternalCreateDirectory(String fullPath, String path, Object dirSecurityObj, Boolean checkHost)
  in System.IO.Directory.InternalCreateDirectoryHelper(String path, Boolean checkHost)
  in Install_Hyper_Data_Type.Form1.inst()
  in Install_Hyper_Data_Type.Form1.InstallBtn_Click(Object sender, EventArgs e)
  in System.Windows.Forms.Control.OnClick(EventArgs e)
  in System.Windows.Forms.Button.OnClick(EventArgs e)
  in System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
  in System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
  in System.Windows.Forms.Control.WndProc(Message& m)
  in System.Windows.Forms.ButtonBase.WndProc(Message& m)
  in System.Windows.Forms.Button.WndProc(Message& m)
  in System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


************** Assembly loaded **************
mscorlib
    Assembly version: 4.0.0.0
    Win32 version: 4.8.4110.0 built by: NET48REL1LAST_B
    Code base: file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/mscorlib.dll
----------------------------------------
Install Hyper Data Type
    Assembly Version: 1.0.5.0
    Win32 version: 1.0.5.0
    Code base: file:///C:/Users/Jochen/Downloads/Install_Hyper_Data_Type.exe
----------------------------------------
Microsoft.VisualBasic
    Assembly version: 10.0.0.0
    Win32 version: 14.8.3761.0 built by: NET48REL1
    Code base: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/Microsoft.VisualBasic/v4.0_10.0.0__b03f5f7f11d50a3a/Microsoft.VisualBasic.dll
----------------------------------------
System
    Assembly version: 4.0.0.0
    Win32 version: 4.8.4110.0 built by: NET48REL1LAST_B
    Code base: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Core
    Assembly version: 4.0.0.0
    Win32 version: 4.8.4110.0 built by: NET48REL1LAST_B
    Code base: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0__b77a5c561934e089/System.Core.dll
----------------------------------------
System.Windows.Forms
    Assembly version: 4.0.0.0
    Win32 version: 4.8.4110.0 built by: NET48REL1LAST_B
    Code base: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System.Drawing
    Assembly version: 4.0.0.0
    Win32 version: 4.8.3761.0 built by: NET48REL1
    Code base: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System.Configuration
    Assembly version: 4.0.0.0
    Win32 version: 4.8.3761.0 built by: NET48REL1
    Code base: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Xml
    Assembly version: 4.0.0.0
    Win32 version: 4.8.3761.0 built by: NET48REL1
    Code base: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
System.Runtime.Remoting
    Assembly version: 4.0.0.0
    Win32 version: 4.8.3761.0 built by: NET48REL1
    Code base: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Runtime.Remoting/v4.0_4.0.0__b77a5c561934e089/System.Runtime.Remoting.dll
----------------------------------------
mscorlib.resources
    Assembly version: 4.0.0.0
    Win32 version: 4.6.1055.0 built by: NETFXREL2
    Code base: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/mscorlib.resources/v4.0_4.0.0_en_b77a5c561934e089/mscorlib.resources.dll
----------------------------------------
System.Windows.Forms.resources
    Assembly version: 4.0.0.0
    Win32 version: 4.6.1055.0 built by: NETFXREL2
    Code base: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms.resources/v4.0_4.0.0_en_b77a5c561934e089/System.Windows.Forms.resources.dll
----------------------------------------

************** Debug JIT **************
To enable JIT debugging, you need to set the value
jitDebugging in the system.windows.forms section of the configuration file
of the application or computer (machine.config).
The application also must be compiled with debugging
enabled.

For example:

<configuration>
    <system.windows.forms jitDebugging="true" />
</configuration>

When JIT debugging is enabled, all unhandled exceptions

iZ!

#47
Quote from: jj2007 on November 02, 2023, 07:41:51 PMGood, but even better would be a complete example that builds with the Masm64 SDK :thumbsup:
I created C:\iZ! manually, no problem, but the installer still complains.

thanks JJ, the lib installs into 64bit %PROGRAMFILES% -> "C:\Program Files\iZ!\Hyper Data Type\", it puts in the dll, xml(for intellisense), licence.txt and uninstall.exe.  It also copies/overwrites Hyper Core.dll
in the System32 dir, so the native dll is accessible.

I just realized I forgot to change version in the installer itself. So it's still writing registry entries for v1.0.4.0. But that shouldn't be a problem.

Masm64 SDK? I don't know much about it.. Anyway only the algo's for arithmetics can be used from "Hyper Core", I'll soon write the documentation. It would be good I guess to have an entirely native lib too, if someone cares to write it.

iZ!

Be sure to run it as Administrator, if it doesn't automatically ask you to elevate rights after running it

jj2007

Quote from: i Z ! on November 02, 2023, 09:42:11 PMBe sure to run it as Administrator, if it doesn't automatically ask you to elevate rights after running it
Why should I run a program as administrator that just gives me a DLL??

iZ!

Quote from: jj2007 on November 02, 2023, 10:09:56 PMWhy should I run a program as administrator that just gives me a DLL??

To allow it access for registering as a Framework library (in registry) and allow creation of folders and copying into System32 dir (for the mentioned "Hyper Core.dll").

jack

#51
hi iZ!
if I were you, I would write the DLL in C, I wrote some MP code in FreeBasic and in C and just now in VB.net
I did a simple test, set the precision to 51200 and then
n = str2fp("7." + StrDup(precision, "7"))
m = str2fp("9." + StrDup(precision, "9"))

m = n / m
m = Sqr(m)

timing of the functions in red not counting conversions
VB.net in release build took .53 seconds
FB took .12 seconds
C took .03 seconds

but since this is an asm forum, why not write your code in masm?
or maybe in MasmBasic https://masm32.com/board/index.php?board=57.0

iZ!

Quote from: jack on November 03, 2023, 08:57:32 AMhi iZ!
if I were you, I would write the DLL in C
nope, that's a negative - if you were me, you couldn't stand a single line of C code in your projects  :smiley:

Quote from: jack on November 03, 2023, 08:57:32 AMn = str2fp("7." + StrDup(precision, "7"))
What does this function do? I thought that C# produces the same code as VB (at least for calling the common functions)

btw, you can now test out your MP Division procedure, since Hyper now does also accept strings as "1.1234e-50" ... Not the fastest Double->Hyper conversion, but it's good enough for 'proof of concept'

jj2007

Quote from: i Z ! on November 02, 2023, 10:55:09 PM
Quote from: jj2007 on November 02, 2023, 10:09:56 PMWhy should I run a program as administrator that just gives me a DLL??

To allow it access for registering as a Framework library (in registry) and allow creation of folders and copying into System32 dir (for the mentioned "Hyper Core.dll").

I will not allow that. None of my code published here writes to the registry or attempts to change C:\Windows\*

iZ!

Quote from: jj2007 on November 03, 2023, 08:46:48 PMI will not allow that. None of my code published here writes to the registry or attempts to change C:\Windows\*
Well, I don't think it's possible to register a .NET library in other way than in registry.
Also it writes (into separate registry entries) the uninstall info, so you can uninstall the library under Settings / Apps & Features
What I can offer is only the ability to choose the installation folder and put in there the native dll as well. But then, this folder would have to be put into the PATH variable, which would again require Admin rights

iZ!

#55
as some of you may know, the art of making a functional installer is making an uninstaller, which self-destructs (you can't do that in any language while .exe is running) and deletes the folder containing it at the end

stoo23

QuoteAttention, don't click the link. The new improved version of the SMF forum software adds links to known web extensions like garbage.net or garbage.inc, so you may randomly end up with strange pages like Windows.inc

I learnt to avoid that trap by using another "i": Windows.ìnc - no link :biggrin:
NB: Please NOTE, I have 'Fixed' this issue.
I had inadvertently selected a Check-Box in the Admin' controls to Automatically 'link' Posted URL's
This has now been De-selected, so you will need to utilize BBcode tags or the 'Link' Button in the Editor to Post an Actual URL.
Cheers
 :smiley:

NoCforMe

Quote from: i Z ! on November 03, 2023, 08:41:11 PM
Quote from: jack on November 03, 2023, 08:57:32 AMhi iZ!
if I were you, I would write the DLL in C
nope, that's a negative - if you were me, you couldn't stand a single line of C code in your projects  :smiley:

Hmm; I see I'm not the only one here ...
Assembly language programming should be fun. That's why I do it.

iZ!

Who wants, can now download the native library here (@ the main page)

references - native

iZ!

#59
Found a relatively quick way to divide. It's approximate, but close enough  :smiley:

VB
Option Explicit Off
Imports HyperLib

'!!! For this code to work, because of the numeric methods used, "Skip integer overflow checks" option must be checked in the Advanced compile settings

Public Class Form1

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        Hyper.displayMode = Hyper.displayModeType.inDecimalBase2_64
        Hyper.maxDigitsInString = 7 'display range

        ' input some random numbers for a and d ->
        Dim a As New Hyper(-251, -253)    'assign 3 * 8 bytes for a, with its least exponent (2^64)^(-253)                 
        a(-252) = -79786875757656175
        a(-253) = 79978687575765619 '
        a(-251) = 7978687575765619

        Dim d As New Hyper(-444, -444) 'reserve 8 bytes for the divisor
        d(-444) = 1 + (2 ^ 53)
        d(-5) = 1 + 2 ^ 44 'mantissa automatically gets extended when assigning values at exponents out of current range; now the size of "d" is ((444-5) * 8) bytes

        Debug.WriteLine("")

        Dim rdiv As Hyper = QuickDivide(a, d)

        Debug.WriteLine("=================== result:")
        Debug.WriteLine(rdiv)

        rdiv *= d

        Debug.WriteLine("=================== check:")
        Debug.WriteLine(rdiv)

    End Sub



    Private Function QuickDivide(dividend As Hyper, d As Hyper) As Hyper
        Return dividend * ReciprocalVal(d)
    End Function
    Private Function ReciprocalVal(d As Hyper) As Hyper

        precision% = 1444 'number of 64-bit digits to extract. Must be larger than exponent range
        precision2% = 222 'may be zero

        Dim r As New Hyper(precision, 0) ' New Hyper(0, 0)
        Dim bp, r1 As Hyper

        hiExp% = d.FindHighExponent
        lowExp% = d.FindLowExponent
        lowVal& = d(lowExp)
        If lowVal And 1 = 0 Then
            Debug.WriteLine("even nr")
            'if the least significant bit is 0, then we can help ourselves with dividing/multiplying the dividend, and then the result, by 2^n.

            d(lowExp - 1) = 1
            lowVal = 1
            lowExp -= 1
        End If
        mq& = GetMagicNr(lowVal)
        pos% = lowExp '
        d.Round(-pos)
        d.PartSize = 0
        bp = New Hyper("1")
        pos1% = 0

mainloop:
        ' get the sequence which, when multiplied by divisor, nullifies itself

        r1 = New Hyper(pos1, pos1)
        r1(pos1) = bp(pos1) * mq

        r(pos1) = r1(pos1)
        bp -= d * r1
        bp.Negate()

        pos1 += 1

        If pos1 > precision Then GoTo nx
        'reciprocal values of large numbers tend to repeat at very large intervals, so we'll be satisfied with our precision                

        GoTo mainloop

nx:
        r1 = r * d

        hi% = r1.FindHighExponent
        r.Divide(r1(hi), precision2)
        r.PartSize = hi + r1.PartSize + r.PartSize + lowExp  '.PartSize           
        d.PartSize = -lowExp

        Debug.WriteLine("--=-=-=-=- recip*d:")
        Debug.WriteLine(r * d) 'should output close to 1
        Debug.WriteLine(r)
        Debug.WriteLine("--=-=-=-=-")

        Return r
    End Function

    Private Function GetMagicNr&(a&)

        ' Magic number or "reciprocal integer" - GET THE 64-BIT NUMBER WHICH, when multiplied by the lowest digit, gives 1 as the remainder of 2^64              
        ' Only for odd numbers.

        bt& = 1 'bit tester
        d& = a 'bit mask

        r& = 0 : i& = 0 : r0& = 0

        For i = 0 To 63

            If bt And r Then GoTo skip

            r += d
            r0 = r0 Or bt
skip:
            bt <<= 1 : d <<= 1
        Next

        Return r0
    End Function

End Class

Also posted on github


P.S.: I recently noticed that full decimal representation has bugs, I removed the default property from it. Who needs it anyway :)