Author Topic: Large integers and floats  (Read 18068 times)

raymond

  • Member
  • ***
  • Posts: 271
    • Raymond's page
Re: Large integers and floats
« Reply #75 on: October 04, 2021, 01:22:08 PM »
Let's take your example of the sum of multiples of 1/2 (0.5 in the decimal format).

In binary, that fraction would be represented as 0.1, and the next one (i.e. 1/4) would be represented as 0.01 with their sum (1/2+1/4) being 0.11 in binary. At some point, the sum may look like 0.111111111111111111 and eventually, that sum would have the zero followed by 64 1's which is the current limit of the current fpu in its most precision. Attempting to add the next fraction would trigger rounding and the sum would become 1.0 in the fpu.

Try it out using a debugger. If you need some code, I'll post it for your perusal.

Obviously, if you use big numbers in the decimal format, I agree with you that the 1.0 would never be reached. But the fpu will always have its limit.
Whenever you assume something, you risk being wrong half the time.
http://www.ray.masmcode.com/

jj2007

  • Member
  • *****
  • Posts: 11768
  • Assembler is fun ;-)
    • MasmBasic
Re: Large integers and floats
« Reply #76 on: October 04, 2021, 07:26:30 PM »
I always appreciate all the help ´m getting in this forum, but even at the risk of appearing arrogant or ungrateful:
My question was not about WHY i would do something or IF i should do something, it was about HOW i could do something.

Fair enough :thumbsup:

Here is a macro solution, it works with Masm, UAsm and AsmC:

include \masm32\MasmBasic\MasmBasic.inc         ; download

InitR8 MACRO dest, srcR4
  .data?
  dest REAL8 ?
  .code
  fld FP4(srcR4)
  fstp dest
ENDM

  Init
  InitR8 MyReal8, 17.6
  Fcmp MyReal8, 17.6
  .if Zero?
        Inkey "equal"
  .else
        Inkey "not equal"
  .endif
EndOfCode


The output is "equal" but, of course, the Real8 initialises as 17.60000038146973. There is no other way to achieve what you want, sorry.

mineiro

  • Member
  • ****
  • Posts: 810
Re: Large integers and floats
« Reply #77 on: October 04, 2021, 09:09:48 PM »
Thank you for answering sir raymond.
Thanks, it's not necessary code, but I appreciate your help.
I have second intention with this talk that deals with large integers and floats.

I understood about 0.0 being a lot of zeros and 1.0 being a lot of ones or nines in decimal base. We need pay attention to range that a register can hold.
I took the point of trigger, its like a number in a specific range. Range is measure by low and high, or minimum value and maximum value that a register can hold. If I choose byte as range, so, minimum value reach 7fh and high value is 80h they are converging. This in binary is solved when first and second left most bit (1/2,(1/4,3/4))(MSB) are not the same. Like a magnitude problem.
01111111
10000000
Or in decimal words, when I have a range between 4.9 and 5.0.

Now a second intention. SSE don't have an instruction to give result of log2.
What do you think is the best way? A constant? Well, one log2 constant to real4, other to real8, ... ?
Should I calculate log2 until register size gets fully filled with usefull log2 numbers?
I'd rather be this ambulant metamorphosis than to have that old opinion about everything

raymond

  • Member
  • ***
  • Posts: 271
    • Raymond's page
Re: Large integers and floats
« Reply #78 on: October 05, 2021, 02:18:35 AM »
Now a second intention. SSE don't have an instruction to give result of log2.
What do you think is the best way? A constant? Well, one log2 constant to real4, other to real8, ... ?
Should I calculate log2 until register size gets fully filled with usefull log2 numbers?
Sorry, I don't have the slightest idea about SSE. I never felt the need for it, in addition to the fact that it was not even available with the MASM32 package during my 'good' years.

You may want to start a separate thread on this subject; otherwise it may get buried in this one which is really on a totally different subject.
Whenever you assume something, you risk being wrong half the time.
http://www.ray.masmcode.com/

daydreamer

  • Member
  • *****
  • Posts: 1813
  • green elevator
Re: Large integers and floats
« Reply #79 on: October 05, 2021, 11:49:33 PM »
Now a second intention. SSE don't have an instruction to give result of log2.
What do you think is the best way? A constant? Well, one log2 constant to real4, other to real8, ... ?
Should I calculate log2 until register size gets fully filled with usefull log2 numbers?
Sorry, I don't have the slightest idea about SSE. I never felt the need for it, in addition to the fact that it was not even available with the MASM32 package during my 'good' years.

You may want to start a separate thread on this subject; otherwise it may get buried in this one which is really on a totally different subject.
Search for Taylor series
In 32bit mode,use of fpu or comisd to check if 64bit integer number = zero, better when zero in both float/int happens to be same number?
SIMD fan and macro fan
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."

mineiro

  • Member
  • ****
  • Posts: 810
Re: Large integers and floats
« Reply #80 on: October 06, 2021, 04:35:20 AM »
I learned with your tutorials sir raymond, I understand fpu power and not necessity to switch to new technologies.
I'm talking this because exist rumors that fpu will not be avaliable in next processors generation. Some instructions buil-in fpu don't exist in SSE/AVX and need be re-done. I think the log, geometric sin, cos, ... .

Thanks sir daydreamer; I'm checking now Taylor series; I have seen that in superfitial way in past.
In previous example of a number with 99 zeros and 1 one; entropy to represent that number reach 8,0793136 bits or 9 bits.
Now, if I do this with factorial (all possible combinations, thanks sir raymond, I remember that post).
100!/99!*1! == 100 or 1100100 in binary form. So, only 7 bits.
This intrigates me along years, was Shannon right!? Answer is yes, industry followed Shannon entropy formula. But not only this, when more data/digits to represent a number/string is given, that factorial will converge very close to Shannon entropy thats more easy to be calculated.


ps: sorry to answer only now, without internet because rain times.
Shannon: Math theory of comunication or information theory.
I'd rather be this ambulant metamorphosis than to have that old opinion about everything

daydreamer

  • Member
  • *****
  • Posts: 1813
  • green elevator
Re: Large integers and floats
« Reply #81 on: October 07, 2021, 07:51:45 PM »
I learned with your tutorials sir raymond, I understand fpu power and not necessity to switch to new technologies.
I'm talking this because exist rumors that fpu will not be avaliable in next processors generation. Some instructions buil-in fpu don't exist in SSE/AVX and need be re-done. I think the log, geometric sin, cos, ... .
thats no problem if you program fpu code,old masm has setting so it instead generate calls to fpu emulator,so it could run on old cpus without fpu,dont know about newer assembler support it
SSE/AVX has rcpss and rsqrtss functions builtin,capability to perform 4 or 8 real4 operations simultanously,later SSE have horizontal add and other things
I think there already exist SSE math libraries
SIMD fan and macro fan
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."

mineiro

  • Member
  • ****
  • Posts: 810
Re: Large integers and floats
« Reply #82 on: October 09, 2021, 04:09:05 AM »
SSE/AVX has rcpss and rsqrtss functions builtin
I will check these instructions; but I think that before I need understand how to do log2 using pen and paper, just to get other approaches.
Agner Fog release a nice library, with high precision to this log problem. I prefer understand instead of apply.
Again, thanks sir daydreamer.
I'd rather be this ambulant metamorphosis than to have that old opinion about everything