News:

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

Main Menu

How to output 128 bits to the screen?

Started by Mikl__, July 19, 2017, 10:51:33 PM

Previous topic - Next topic

jj2007

Quote from: aw27 on July 20, 2017, 05:26:34 PMIn my opinion there are already enough BigNum libraries out there. Probably the best one for Windows, is the MPIR

MPIR: Multiple Precision Integers and Rationals

Looks interesting, but sources only. How big are the lib or dll files, could you post them here?

There is a thread on The best cross platform (portable) arbitrary precision math library at SOF; they recommend GMP.

@Mikl: How would you declare a 128-bit float? Or do you read it from a file?

aw27

Quote from: jj2007 on July 20, 2017, 05:47:05 PM
Looks interesting, but sources only. How big are the lib or dll files, could you post them here?
The sources are in their website.
When I was interested in these matters, I bothered to produce all libs, static and dynamic, and dlls and posted them here. They are not big.

Quote
There is a thread on The best cross platform (portable) arbitrary precision math library at SOF; they recommend GMP.

MPIR is a fork of GMP, the guy that developed GMP really hates Windows and makes things extremely difficult to use GMP within Windows.

jj2007

Quote from: aw27 on July 20, 2017, 06:00:30 PMThey are not big.

MpfrMpir\Static\Lib32\mpfr.lib is 6MB, that is indeed small compared to all the stuff that M$ forces us to install.

aw27

Quote from: jj2007 on July 20, 2017, 06:14:13 PM
Quote from: aw27 on July 20, 2017, 06:00:30 PMThey are not big.

MpfrMpir\Static\Lib32\mpfr.lib is 6MB, that is indeed small compared to all the stuff that M$ forces us to install.
Static libraries don't use the dll. In a static library only the functions you need are taken out. Your .exe will not be over 6MB, can be pretty small indeed.
Dynamic libs, the ones that masm32 uses, contain just stubs to use the dll.

Mikl__

QuoteMikl: How would you declare a 128-bit float? Or do you read it from a file?
Until I didn't announce it, I'm interested in a bunch/Bundle of printf-function and xxm-registers. I spent many time searching on Google and therefore decided to ask on the forum. If I output the contents of an 80-bit memory cell, then how would it look at 64 bits MASM/FASM/NASM?.data
pi dt 3.14159265358979323846264338327
fmt db "%1.25llf",0 <-- Or not correct format ?
.code
         .....
        lea rcx,fmt
       lea rdx,pi  <-- ? Address don't work         or need two 64-bits registers (RDX+R8)  ?
       call printf

hutch--

I have a sneaking suspicion that it can be done with the a 128 bit memory operand if you read it 4 bytes at a time. I don't have time to play with it at the moment as I have too much 64 bit code to write but it should not be that big a deal.

jj2007

It isn't a big deal to print an xmm register, but it is limited to 64 bits. The CRT doesn't allow more.

include \Masm32\MasmBasic\Res\JBasic.inc        ; # console demo, builds in 32- or 64-bit mode with ML, AsmC, JWasm, HJWasm #
.data?
tmpQ    dq ?
tmpR8   REAL8 ?
.data
MyInt   dq 123456789012345
MyFloat         REAL8 123456789012345.6789
Init            ; OPT_64 1      ; put 0 for 32 bit, 1 for 64 bit assembly
  PrintLine Chr$("This code was assembled with ", @AsmUsed$(1), " in ", jbit$, "-bit format", 13, 10)

  movlps xmm0, MyInt            ; load data to xmm0
  usedeb=1      ; enable console debugging
  deb 4, "debug macro", xmm0
  movlps tmpQ, xmm0             ; store data in temporary qword
  jinvoke crt_printf, Chr$("xmm0=%lld", 13, 10), tmpQ
 
  movlps xmm0, MyFloat
  movlps tmpR8, xmm0
  jinvoke crt_printf, Chr$("xmm0=%f", 13, 10), tmpR8

  MsgBox 0, "Wow, it works!!!!", "Hi", MB_OK or MB_SETFOREGROUND
EndOfCode

aw27

#22
Unlike other vendors, when it is time to print, Microsoft considers "long double"="double".   :eusa_snooty:


jj2007

Quote from: aw27 on July 20, 2017, 09:45:16 PM
Unlike other vendors, when it is time to print, Microsoft considers "long long double"="double".   :eusa_snooty:

Which vendor supports a long long double? If yes, is that a REAL10? I've heard rumours that FORTRAN supports REAL16 ::)

#include <stdio.h>
#include <windows.h> // needs Gcc or Visual C and the Compile plugin
#include <conio.h>  // RichMasm: Hit Ctrl F5 to pick a commandline (afterwards, F5 is enough)

int main(int argc, char* argv[]) {
  long long q=1234567890123456789;
  printf("A long long:\t%lld\n", q);

  double nd=1234567890.1234567890;
  printf("A double:\t%9.9f\n", nd);
  long double ld=1234567890.1234567890;
  printf("A long double:\t%9.9f (ok with VC, no luck with Gcc)\n\n", ld);
  _getch();
}


Output:
  VS:
  A long long:    1234567890123456789
  A double:       1234567890.123456700
  A long double:  1234567890.123456700 (ok with VC, no luck with Gcc)

  GCC:
  A long long:    1234567890123456789
  A double:       1234567890.123456700
  A long double:  -0.000000000 (ok with VC, no luck with Gcc)

TWell

https://en.wikipedia.org/wiki/Long_double

Microsoft made a bad decision with long double with 32-bit compiler?
In 16-bit C they have it supporting 80-bits???

aw27

Quote from: jj2007 on July 20, 2017, 10:24:28 PM
Which vendor supports a long long double? If yes, is that a REAL10?
Intel compiler and GCC support long double (REAL10).


Quote
I've heard rumours that FORTRAN supports REAL16 ::)

I don't remember, I don't do FORTRAN since I left school.  :biggrin:

PS: I think GCC may not print them when using VS libraries, but I have not GCC installed at the moment to see.  :badgrin:

jack

as far as I know gcc's long double on Windows is the same as double.
for printing long double have a look at smldbl12.zip found here http://www.moshier.net/#Rubid_pc, it's in the public domain.

aw27

Quote from: jack on July 20, 2017, 11:04:39 PM
as far as I know gcc's long double on Windows is the same as double.
for printing long double have a look at smldbl12.zip found here http://www.moshier.net/#Rubid_pc, it's in the public domain.
You may need to run it in Cygwin for it to work as advertised. :icon_eek:

FORTRANS

Hi Jochen,

Quote from: jj2007 on July 20, 2017, 10:24:28 PM
I've heard rumours that FORTRAN supports REAL16 ::)

   That depends on the vendor and systems involved.  IIRC Cray
had 64-bit REAL and 128-bit DOUBLE PRECISION types.  And various
Unix minicomputers had the same.  (Long time ago though.)

   Here is some information from a X86 product typed in from a
set of help screens.

Compaq Visual Fortran 6.6 (1998)?

Real Data Types

Real data types can be specified as follows:

   REAL
   REAL([KIND=]n)
   REAL*n
   DOUBLE PRECISION

   n
   Is kind 4, 8, or 16.  Kind 16 is only available on
   OpenVMS, Tru64 UNIX, and Linux systems.


HTH,

Steve

jack

Quote from: aw27 on July 20, 2017, 11:11:52 PM
You may need to run it in Cygwin for it to work as advertised. :icon_eek:
have not checked the precision of gcc's long double on Cygwin, am not fond of the many dll dependencies.
as for the code linked above, it should be trivial to extend it to print 128-bit floats (I think the code is already there).