Format Fix64

TheBeginner
Schreiberling
Avatar
Gender: n/a
Location: Wunsiedel Bayern
Age: 67
Posts: 756
Registered: 06 / 2013
Subject:

Format Fix64

 · 
Posted: 07.02.2022 - 11:05  ·  #1
Guten morgen. eine kleine Frage an euch, gibts eine Möglichkeit bei der Berechnung
den stellenwert auf 3 nach komma anzugeben ? weil soviel nachkomma stellen brauche ich nicht
149.999086128 das sind ja 9 nachkomme stellen.

tmp:= Fix64SinD(a_winkel);



Gruß Frank
Merlin
Administrator
Avatar
Gender:
Age: 24
Posts: 1374
Registered: 03 / 2005
Subject:

Re: Format Fix64

 · 
Posted: 07.02.2022 - 12:11  ·  #2
Hi Frank

You mean for display purposes?

By its very nature a base 2 decimal cannot be represented exactly by a base 10 decimal and vice versa.

==================================================================

Sie meinen zu Anzeigezwecken?

Es liegt in der Natur der Sache, dass eine Dezimalzahl zur Basis 2 nicht exakt durch eine Dezimalzahl zur Basis 10 dargestellt werden kann und umgekehrt.
TheBeginner
Schreiberling
Avatar
Gender: n/a
Location: Wunsiedel Bayern
Age: 67
Posts: 756
Registered: 06 / 2013
Subject:

Re: Format Fix64

 · 
Posted: 07.02.2022 - 12:39  ·  #3
Hello Merlin, I didn't want to put 9 after the decimal point in the calculation, 3 is enough for me
I would like the calculation to be faster.


Hallo Merlin, ich wollte bei der Berechnung nicht 9 nach komma stellen haben, mir reichen 3
ich möchte das die berechnung schneller geht.


Gruß Frank
Merlin
Administrator
Avatar
Gender:
Age: 24
Posts: 1374
Registered: 03 / 2005
Subject:

Re: Format Fix64

 · 
Posted: 07.02.2022 - 13:16  ·  #4
Hi Frank

Speed won't be affected. A fix64 takes 8 bytes of data. End of story, really. Truncating won't help anything.

====================================================================

die Geschwindigkeit wird nicht beeinträchtigt. Ein fix64 benötigt 8 Bytes an Daten. Das war's eigentlich schon. Abschneiden wird nichts bringen.

Regards
TheBeginner
Schreiberling
Avatar
Gender: n/a
Location: Wunsiedel Bayern
Age: 67
Posts: 756
Registered: 06 / 2013
Subject:

Re: Format Fix64

 · 
Posted: 07.02.2022 - 14:31  ·  #5
That's what I wanted to know. Thank you Merlin

Genau das wollte ich wissen. Danke Merlin


Gruß Frank
Avra
Schreiberling
Avatar
Gender:
Location: Belgrade, Serbia
Age: 53
Homepage: rs.linkedin.com/in…
Posts: 653
Registered: 07 / 2002
Subject:

Re: Format Fix64

 · 
Posted: 08.02.2022 - 12:25  ·  #6
Quote by Merlin

Speed won't be affected. A fix64 takes 8 bytes of data. End of story, really. Truncating won't help anything.

Absolutelly correct.

However, before fix64 was created and embedded into AvrCo, I have played with 32 bits and arbitrary fixed point math. You might want to check it out (much simpler lib then fix64, but core is similar):
https://community.atmel.com/pr…-point-lib
Arbitrary fixed point means some speed is lost (that is why fix64 has fixed 32 bits for integer part and fixed 32 bits for fractional part), but on the other hand some speed is saved since AVR deals only with 32 bit instead of 64 bit numbers. I did not do any benchmarking, but for complex calc like trigonometry my guess would be that fix32 should be faster. Of course, fix32 range limit is much less then fix64.

For simple fix64 presentation in wanted number of digits, use this function:
Code
function  Fix64ToStrFmt(const a: TFix; const iDig, fDig: byte): TFixString;
Selected quotes for multi-quoting:   0

Registered users in this topic

Currently no registered users in this section

The statistic shows who was online during the last 5 minutes. Updated every 90 seconds.
MySQL Queries: 14 · Cache Hits: 14   105   119 · Page-Gen-Time: 0.024884s · Memory Usage: 2 MB · GZIP: on · Viewport: SMXL-HiDPI