News:

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

Main Menu

floating point math?

Started by daydreamer, July 25, 2021, 04:45:57 AM

Previous topic - Next topic

daydreamer

there is signbit and exponent and number
so is there a simple way to check exponent to tell the size of the number is between for example
10 million and one million,1 million and 100000,100000 and 10000...........?in decimal

use display in 16bit unicode instead,I want to exchange the display "INF" to "∞" =221Eh,when infinity
   
my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

raymond

From the FPU tutorial, you could find the following:

The relationship between a logarithm base 2 and a logarithm using some other base b is as follows:
logbx = log2x*(log2b)-1 = log2x*logb2

The FPU has both the log(2) and ln(2) as hard-coded constants which can be loaded with the FLDLG2 and FLDLN2 instructions respectively. As an example, the following code could be used to compute the common logarithm of a positive REAL number zzz located in memory.

fldlg2         ;ST(0)=log10(2), ST(1)=zzz
fld  real_var  ;ST(0)=real_var, ST(1)=log10(2), ST(2)=zzz
fyl2x          ;log2(real_var)*log10(2)=>ST(1) and ST(0) is POPed
               ;ST(0)=log10(real_var), ST(1)=zzz


The log(zzz) would then be in ST(0). You could store the integer portion with the FISTTP instruction (http://www.ray.masmcode.com/tutorial/fpuchap5.htm#fisttp) or use other means. This will give you the lower limit of the range you are looking for.
Whenever you assume something, you risk being wrong half the time.
https://masm32.com/masmcode/rayfil/index.html

daydreamer

Thanks raymond  :thumbsup:
I am working on AVX calculator, and other exercises to do things in AVX
This is for Double2 ascii conversion proc


my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

daydreamer

Movss xmm0,z
Movd eax,xmm0
Mov string,'+'
Test eax,8000 0000h
Je L1
Mov string,'-'
L1: sar eax,23
And eax,7fh
Here I get strange results
When z 987654321, eax=25, when z -1000, eax is 8 =range 256?
After this I want to start with the range I detect above
To start toascii conversion loop
my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

raymond

Unfortunately, I am not at all familiar with the SSE instructions.

Furthermore, I don't know which assembler you may be using. And, for that reason, I would not know if an instruction such as "sar eax,23" would be interpreted by the assembler as meaning 23h or 23d without the specification. Similarly, would "eax=25" be a binary or decimal value of eax???
Whenever you assume something, you risk being wrong half the time.
https://masm32.com/masmcode/rayfil/index.html

HSE

I think is:
.data
  r4t real4 0.0
.code
  fild z
  fstp r4t
  mov eax, r4t
  shr eax, 23d
  and eax, 0FFh  ; mantissa is 8 bit
  sub eax, 127d  ; mantissa is biased
Equations in Assembly: SmplMath

raymond

Quote from: HSE on July 27, 2021, 09:05:37 AM
I think is:
.data
  r4t real4 0.0
.code
  fild z
  fstp r4t
  mov eax, r4t
  shr eax, 23d
  and eax, 0FFh  ; mantissa is 8 bit
  sub eax, 127d  ; mantissa is biased


I can understand that but this would give the range in the binary system. His first post indicated he wants to know the range in the decimal system.
Whenever you assume something, you risk being wrong half the time.
https://masm32.com/masmcode/rayfil/index.html

HSE

Hi Raymond!!

Quote from: raymond link=topic=9464.msg103615#msg103615
I can understand that but this would give the range in the binary system.

His first post indicated he wants to know the range in the decimal system.

Just following Daydreamer's code.

I don't know what he want  :biggrin:
Equations in Assembly: SmplMath

daydreamer

#8
Quote from: raymond on July 27, 2021, 11:05:39 AM
Quote from: HSE on July 27, 2021, 09:05:37 AM
I think is:
.data
  r4t real4 0.0
.code
  fild z
  fstp r4t
  mov eax, r4t
  shr eax, 23d
  and eax, 0FFh  ; mantissa is 8 bit
  sub eax, 127d  ; mantissa is biased


I can understand that but this would give the range in the binary system. His first post indicated he wants to know the range in the decimal system.
I want todo it with a LUT,  from binary, speed like in converting lots of primes or other numbers, solving it with SSE/AVX  I am limited to +,-,*,/,,sqrt and without fpu fully equipped math functions

my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

daydreamer

Quote from: HSE on July 27, 2021, 09:05:37 AM
I think is:
.data
  r4t real4 0.0
.code
  fild z
  fstp r4t
  mov eax, r4t
  shr eax, 23d
  and eax, 0FFh  ; mantissa is 8 bit
  sub eax, 127d  ; mantissa is biased

Thanks Héctor  :thumbsup:
my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

HSE

Quote from: daydreamer on July 27, 2021, 05:10:53 PM
[ I am limited to +,-,*,/,,sqrt

Sorry to know your machine FPU is broken, but I think Raymond explanation will work even in your phone!
Equations in Assembly: SmplMath

daydreamer

Quote from: HSE on July 28, 2021, 12:08:14 AM
Quote from: daydreamer on July 27, 2021, 05:10:53 PM
[ I am limited to +,-,*,/,,sqrt

Sorry to know your machine FPU is broken, but I think Raymond explanation will work even in your phone!
Seem I need to add some checking nan's and infinity., same float or double independent of instruction set
I have partly working float2ascii, sometimes cvtss2si eax,xmm0 gets very high number,character becomes 0ffh+'0'
One divss maxrange and Multiple mulss 10.0,causes precision loss,causes this infinity,or nan?


my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

hutch--

Magnus,

The hardest part of a calculator is the interface, the calculations in SSE2 are trivial. If you want higher precision you would use the FP unit.

daydreamer

Quote from: hutch-- on July 28, 2021, 09:00:51 AM
Magnus,

The hardest part of a calculator is the interface, the calculations in SSE2 are trivial. If you want higher precision you would use the FP unit.
this has been a nice avx exercise,singlestepping,because register usage is different from SSE
also exercise to SIMD version of ascii to double works
my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

daydreamer

Quote from: hutch-- on July 28, 2021, 09:00:51 AM
Magnus,

The hardest part of a calculator is the interface, the calculations in SSE2 are trivial. If you want higher precision you would use the FP unit.
I am trying to get unicode gui working in asm
But test button shows only ascii?
Whole create main window needs to be unicode first?
Newer. Inc files for createwindowW needed?
Different flags in invoke to treat string as 16bit unicode instead?
my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding