Autor Beitrag
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Sa 26.08.06 20:25 
Ich wollte eine Berechnung weiterführen, die wir in Mathe hatten. Es geht um das Verhältnis der Seite eines Quadrates zur Diagonalen dieses Quadrates. Das ist Wurzel von 2. Dann haben wir diesen Wert quadriert. Es kommt aber nicht genau 2 heraus, sondern ein Näherungswert. Aber wenn man z.B. 100 Berechnungen durchführen lässt, kommt zum Schluss im Browser doch 2 heraus, weil dann der Wert, der quadriert wird, immer 1.41421356237 beträgt. Irgendwie schneidet PHP immer die noch folgenden Kommmastellen ab. Warum und was kann man dagegen tun?
//Edit: Hier kann man es ausprobieren: www.fewo-wolgast.de/zwei/index.php

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Sa 26.08.06 20:32 
Das ist nicht nur in php so, sondern liegt an der Art und weise wie Dezimalzahlen im Computer gespeichert werden, nämlich als Gleitkommazahlen. Das heißt vereinfacht, da0 die Zahl und die Position des Kommas unabhängig gespeichert werden. Und je nachdem wie groß die Mantisse gewählt wird, kann eine Genauigkeit auf eine bestimmte Anzahl von Stellen ereicht werden. In deinem Beispiel 12 Stellen.

_________________
Markus Kinzler.
Marco D. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Sa 26.08.06 20:37 
Das heißt, ich kann da nichts gegen machen, oder doch? :gruebel:
Was heißt überhaupt 'Mantisse'?

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Sa 26.08.06 20:48 
In deinem Fall ist die Mantisse 141421356237 was als 0,141... aufzufassen ist. Der Exponent wäre dann 1

als 0,141421356237 * 10^1 = 1,41421356237

Der Prozessor arbeitet aber nich auf basis 10 sonder 16 (Hex). Um negative Exponenten zu verhindern, wird 49 hinzugezahl.

Zitat:
Das heißt, ich kann da nichts gegen machen, oder doch? :gruebel:
Selber ne Floatklasse mit größerer Genauigkeit oder fixed-Point schreiben ( oder suchen, ob es sowas vielleicht schon gibt).

_________________
Markus Kinzler.
Marco D. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Sa 26.08.06 20:51 
user profile iconmkinzler hat folgendes geschrieben:
Selber ne Floatklasse mit größerer Genauigkeit oder fixed-Point schreiben ( oder suchen, ob es sowas vielleicht schon gibt).

Selber machen? :P Ich glaube, da brauch ich etwas Hintergrundwissen was float angeht. Hast du mal einen (am besten mehrere) Link?

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Sa 26.08.06 21:11 
In meinem Delphi-Crashkurs findet man auch einen Abschnitt zur Zahlendarstellung im Rechner:
www.christian-stelzm...tm#zahlendarstellung
Der gilt nicht nur für Delphi

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: So 27.08.06 08:22 

_________________
Markus Kinzler.