Author Topic: how can I create floating point?  (Read 1499 times)

mineiro

  • Member
  • ****
  • Posts: 587
Re: how can I create floating point?
« Reply #15 on: January 13, 2020, 11:15:42 PM »
Yes, I know, pi is transcendental, we will never reach pi, we just approach pi. So I truncated the number, see it as pseudo_pi or another constant like plank, gravity, .... I suppose only pi and euler is transcedental.
jj2007, I used your example to clarify what I want. You said 3/7 can be represented exactly with 8 bits. See that we can represent it as 0. and then 3 repetitive bits. That can give, can be represented with less than 8 bits.

3/7 =
0,42857142857142857142857142857143
0,85714285714285714285714285714286
1,7142857142857142857142857142857
1,4285714285714285714285714285714
0,85714285714285714285714285714286
1,7142857142857142857142857142857

3/7=0.011011...

---edited---
I forgot to say, thank you sir JonasS; thank you sir jj2007.
« Last Edit: January 14, 2020, 01:23:02 AM by mineiro »
I'd rather be this ambulant metamorphosis than to have that old opinion about everything

daydreamer

  • Member
  • *****
  • Posts: 1314
  • building nextdoor
Re: how can I create floating point?
« Reply #16 on: January 15, 2020, 01:10:59 AM »
Yes, I know, pi is transcendental, we will never reach pi, we just approach pi. So I truncated the number, see it as pseudo_pi or another constant like plank, gravity, .... I suppose only pi and euler is transcedental.
jj2007, I used your example to clarify what I want. You said 3/7 can be represented exactly with 8 bits. See that we can represent it as 0. and then 3 repetitive bits. That can give, can be represented with less than 8 bits.

3/7 =
0,42857142857142857142857142857143
0,85714285714285714285714285714286
1,7142857142857142857142857142857
1,4285714285714285714285714285714
0,85714285714285714285714285714286
1,7142857142857142857142857142857

3/7=0.011011...

---edited---
I forgot to say, thank you sir JonasS; thank you sir jj2007.
dont forgot sqrt(2) is endless decimals too
RCPSS sse instruction performs 1/x for you with 1024 bit lut
Quote from Flashdance
Nick  :  When you give up your dream, you die
*wears a flameproof asbestos suit*
Gone serverside programming p:  :D
I love assembly,because its legal to write
princess:lea eax,luke
:)

dedndave

  • Member
  • *****
  • Posts: 8827
  • Still using Abacus 2.0
    • DednDave
Re: how can I create floating point?
« Reply #17 on: January 15, 2020, 02:43:03 AM »
in the "real world", you rarely need more digits than can be represented with 80 bit reals

the problem often lies with entering a value as decimal digits, converting it to binary real, then back to decimal
add a little OCD (common with programmers), and you have an issue

if you really want to maintain the original decimal digits for fractions, you may want to consider storing it in the form
of two reals, numerator and denominator

another approach might be to use an 80 bit real, but round off some of the displayed digits

i sometimes want to store large values with precise digits, such as time or frequency values
manipulation speed is not always that critical
there are other formats that may be better suited, such as BCD, or even the original ASCII strings

jj2007

  • Member
  • *****
  • Posts: 10444
  • Assembler is fun ;-)
    • MasmBasic
Re: how can I create floating point?
« Reply #18 on: January 15, 2020, 03:16:19 AM »
if you really want to maintain the original decimal digits for fractions, you may want to consider storing it in the form
of two reals, numerator and denominator

Or as integers:
Code: [Select]
FourteenBy15 db 14+15*16
FifteenBy14 db 15+14*16
Code: [Select]
14/15           0.933333039151814980
as REAL10:      0.9333333333333333482
15/14           1.071428537152574500
as REAL10:      1.0714285714285714

The representation is exact, the visualisation cannot be exact. And the range is 1/15...15/1 for a one-byte format.

nidud

  • Member
  • *****
  • Posts: 1972
    • https://github.com/nidud/asmc
Re: how can I create floating point?
« Reply #19 on: January 15, 2020, 03:55:30 AM »
The approximation of PI is 22/7

%echo @CatStr(<3/7: >, %(3.0/7.0))
%echo @CatStr(<15/14:  >, %(15.0/14.0))
%echo @CatStr(<22/7:     >, %(22.0/7.0))

3/7: 0.4285714285714285714285714285714
15/14:  1.0714285714285714285714285714286
22/7:     3.1428571428571428571428571428571

mineiro

  • Member
  • ****
  • Posts: 587
Re: how can I create floating point?
« Reply #20 on: January 15, 2020, 03:59:18 AM »
Oh yeah, square root of 2 is a 1by1 square and we take the diagonal. I prefer romantic era instead of modern era.

Do you know any way to know how many bits are needed to store the result? Which takes up less space on the device, numerator and denominator or just the result of splitting?
In the previous example, if I were to store the numerator 3 (2 bits) and the denominator 7 (3 bits) this would give 5 bits the gross mode. The result showed me with the hidden 0. that fits in the smallest space. I am currently treating infinity as a supposed infinite series of ones, updated after each operation.
Can I assume that the biggest number (numerator or denominator) holds the space to store the division result? If no, why?

It would be something like factorials, I know there is a very crazy formula that I little understood about how many digits are needed for the result of a factorial, without having to calculate the factorial itself.
But I want to know about divisions.

I appreciate your answers gentlemen daydreamer,dedndave, jj2007 and nidud. Thanks.
I'd rather be this ambulant metamorphosis than to have that old opinion about everything

nidud

  • Member
  • *****
  • Posts: 1972
    • https://github.com/nidud/asmc
Re: how can I create floating point?
« Reply #21 on: January 15, 2020, 04:17:52 AM »
Floating numbers are by design compressed so you may skip all lower zero-bits. The smallest standard is HALF (REAL2: 16-bit) and often used for storing large arrays.

HSE

  • Member
  • *****
  • Posts: 1342
  • <AMD>< 7-32>
Re: how can I create floating point?
« Reply #22 on: January 15, 2020, 05:00:53 AM »
I appreciate your answers gentlemen daydreamer,dedndave, jj2007 and nidud. Thanks.
Hey...  not me!!

 :biggrin: You are wright.

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 7440
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: how can I create floating point?
« Reply #23 on: January 15, 2020, 06:47:12 AM »
There is a solution, stop using base 10 and use a flexible base number system like the old fashioned fraction we did at school long ago.

A fraction like 3/7 is perfectly precise if you use a base 7 number system. Using a decimal system is more than adequate in most instances as a fraction like 3/7 to even 8 decimal places easily exceeds the precision required for ordinary tasks. There are of course calculations that require far higher precision but in ordinary circumstances, high decimal point counts are of little use..
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

mineiro

  • Member
  • ****
  • Posts: 587
Re: how can I create floating point?
« Reply #24 on: January 15, 2020, 07:35:36 AM »
sorry sir HSE, I forgot you. Thank you too. A beer to you.

sir hutch, I was looking to other bases, like 60, 20, 5, ... . Pythagoras suggested that best base was 10, like a harmony base, to music that changes to octaves, but to minimal losses I suppose the better was base 2. Entropy formula by Shannon is calculated using log2. I also think in unary base.
Well, If i can calculate the factor of both numbers I can calculate the better base.
I'd rather be this ambulant metamorphosis than to have that old opinion about everything

jj2007

  • Member
  • *****
  • Posts: 10444
  • Assembler is fun ;-)
    • MasmBasic
Re: how can I create floating point?
« Reply #25 on: January 15, 2020, 08:08:43 AM »
Code: [Select]
include \masm32\include\masm32rt.inc
include division.inc   ; see attachment
.code
Division FourteenBy15=14/15
Division FifteenBy14=15/14
Division negative=-66/77
Division Pi=22/7
Division HundredBy123=100/123
start:
  PushDiv FourteenBy15
  fstp REAL8 ptr [esp]
  invoke crt_printf, cfm$("14/15\t\t%0.18f\nas REAL10:      0.9333333333333333482", 13, 10), REAL8 ptr [esp]

  PushDiv FifteenBy14
  fstp REAL8 ptr [esp]
  invoke crt_printf, cfm$("15/14\t\t%0.18f\nas REAL10:      1.0714285714285714", 13, 10, 10), REAL8 ptr [esp]

  PushDiv negative
  fstp REAL8 ptr [esp]
  invoke crt_printf, cfm$("-66/77   \t%0.17f", 13, 10), REAL8 ptr [esp]

  PushDiv HundredBy123
  fstp REAL8 ptr [esp]
  invoke crt_printf, cfm$("100/123  \t%0.17f", 13, 10), REAL8 ptr [esp]

  PushDiv Pi
  fstp REAL8 ptr [esp]
  invoke crt_printf, cfm$("Pi as 22/7\t%0.17f", 13, 10), REAL8 ptr [esp]
  inkey chr$(0)
  exit
end start

mineiro

  • Member
  • ****
  • Posts: 587
Re: how can I create floating point?
« Reply #26 on: January 15, 2020, 10:40:13 AM »
Sir hutch, sorry to post an image in your server, I know that spends a lot of bandwidth, but without this image this will be hard to explain. Well, I suppose can be usefull to your eletrical deals.

I am tired, after a long journey of study I see only disappointments. I will reveal the secret behind this topic. The best I can do is keep weeding and growing food.
Public domain.

I could feel arithmetic compression but couldn't explain it. I tried mental regressions but in vain. Take your beer, your cigarette, sit down comfortably.

PART 1: PHYSICS, ELECTRICITY
I find it strange that the electron charge is 1.6. Being Catholic and believing in the golden or divine number, I wondered if there was any relationship between the electron charge and Fibonacci. And here came the crack.

In electrical we study circuits with resistors in series, parallel and mixed. I think it is Thevenin who said that every resistive circuit can be shortened with only one voltage source (voltage) and only one resistor called the equivalent resistance.
No matter how many resistors I have in a circuit, no matter if they are in series and parallel, it just matters that we can represent the entire circuit with only 1 resistor.
The formula used is: Voltage = Resistance * Amps
If the resistance is equal to 1ohm, then the voltage is equal to the intensity of the electric current (amps).


PART 2: FIBONACCI
The fibonacci sequence is known to everyone:
1,1,2,3,5,8,13,21,34,55,89, ....
If we take two sequential numbers and divide them we tend to find the golden number.
55/34 = 1.6176470588235294117647058823529
89/55 = 1.618181818181818181818181818181818
But something curious happens when we reverse the division, see:
34/55 = 0.61818181818181818181818181818182

Did you notice that the ratio between 89/55 and 34/55 is the same? Same floating points except for one detail: One starts with 0 and the other with 1 for the entire part.
Joining mixed electrical circuits with fibonacci. If all resistors are 1 ohm, strangely I can fit fibonacci into the electrical circuit.


PART 3: ARITHMETIC DATA COMPRESSION - fibonacci compression or sunflower compression.
Joining the useful with the pleasant. If we think of equivalent resistance as a form of data compression and the electrical circuit (resistors) as an abstract representation of the fibonacci sequence then it can be done. But in digital circuits we deal with the binary base. Then I should combine the 3 themes into one. Mathematicians do not compress data, mathematicians model data.

Imagine the following electrical circuit of figure 3:
we have arranged the resistors: 3,4,2,3,1
Series = numerator, parallel = denominator
Series = 1, parallel = 0

34231
Converting the circuit to binary:
1110000110001
Starting from right to left we do:
1/3
3 * 2 + 1 = 7/3
7 * 4 + 3 = 7/31
31 * 3 + 7 = 100/31

The equivalent pseudo resistance or the compressed circuit or the compressed binary digits can be represented by the division 100/31 = 3,2258064516129032258064516129032
Note that the nonzero integer (the number 3) corresponds to the circuit starting with ones instead of zeros (starting in series), and changing to 0 (parallel), then to 1, to 0, to 1, .. .

As seen in fibonacci, the data are sequences of parallels and series, or series and parallels, or if viewed in binary, a sequence of 01010101 ... or 10101010 ...

How will we have the digits again only with 3,2258064516129032258064516129032? Through inversion and subtraction of whole parts:
We already know that the circuit has 3 equal elements repeated and that starts with one's, let's subtract the whole part 3 and continue:
3.2258064516129032258064516129032 - 3 = 0.22580645161290322580645161290323
Now we invert the result:
1 / 0.22580645161290322580645161290323 = 4.4285714285714285714285714285714
subtract the whole part 4 and invert
1 / 0.42857142857142857142857142857143 = 2.3333333333333333333333333333333
subtract the whole part 2 and invert
1 / 0.33333333333333333333333333333333 = 3
and here we reach the end. If you wonder why we didn't get to resistor 1 or the first resistor was because I started the sequence from 1 and not 2 which would be the proper fibonacci number to be the initial one. I mean, I didn't do the math operation for the first resistor, just from the second resistor.

Reducing equivalent resistance at its lowest lossless representation? This was the question I raised in this topic.
3,2258064516129032258064516129032
trying by brute force the operations have to 3.2258 can represent the lossless circuit (i'm ignoring the 1st ohm resistor).
3.2258 in binary equals 11.001110011100111000000 ... in single words 11.00111 (times 3)

Well, if I enter as information that the circuit starts in series or parallel, just one bit, then I can reverse the number 3,2258 and get:
1 / 3.2258 = 0.31000062000124000248000496000992
Now the number is more palatable and compact: 0.31 is the number representing that electrical circuit, or the sequence 34231
Continue inverting and subtracting the entire part and you will see:
1 / 0.31 = 3.2258064516129032258064516129032
1 / 0.22580645161290322580645161290323 = 4.428571428
...
I'd rather be this ambulant metamorphosis than to have that old opinion about everything

Mikl__

  • Member
  • ****
  • Posts: 976
Re: how can I create floating point?
« Reply #27 on: January 15, 2020, 10:53:52 AM »
Hi mineiro!
Binary fractions

mineiro

  • Member
  • ****
  • Posts: 587
Re: how can I create floating point?
« Reply #28 on: January 15, 2020, 11:04:21 AM »
thank you sir Mikl__

Time to members here that need some money to run into the gold.
http://prize.hutter1.net/
I'd rather be this ambulant metamorphosis than to have that old opinion about everything

jj2007

  • Member
  • *****
  • Posts: 10444
  • Assembler is fun ;-)
    • MasmBasic
Re: how can I create floating point?
« Reply #29 on: January 15, 2020, 11:31:03 AM »
89/55 = 1.618181818181818181818181818181818
But something curious happens when we reverse the division, see:
34/55 = 0.61818181818181818181818181818182

Did you notice that the ratio between 89/55 and 34/55 is the same? Same floating points except for one detail: One starts with 0 and the other with 1 for the entire part.

Not so surprising: 89/55=34/55+55/55=0.618+1=1.618