ich habe eine frage, ist es möglich eine flaot variable mit einer modulo division zu verarbeiten? ich meine zB: float a,b; a=b%100; ist dies möglich? mein compiler beschwert sich in einer tour... danke für eure hilfe! mfg
@ Rumpelstilzchen 123 (billson) >ist dies möglich? Nein. > mein compiler beschwert sich in einer tour... Das hat seine Gründe. Modulo ist nur für Integer definiert. Siehe Festkommaarithmetik. MFG Falk
danke für deine schnelle antwort... wie kann ich das umgehen? ich bräucht nämlich den rest um die ganzen- und nachkommazahlen auszugeben?!? emefge
da gibts sicherlich funtionen für, weiss im moment nur nicht welche (evtl trunc oder frac...) im norfall macht ein dstrf und suchst im str das komma
double Floatwert = Irgendwas; uint32 Ganzzahl = Floatwert; double Rest = Floatwert - Ganzzahl; Evtl. noch ein paar Warnings wegcasten.
Modulo entspricht eigentlich dem Restanteil bei einer Division. Natürlich kann man sowas auch mit Fliesskomma machen es wurde oft als "fraction" auf Taschenrechnern bezeichnet. Wenn so eine Funktion in der Bibliothek nicht drin ist, kann man sie versuchen nachzubilden: fraction:=floor(n/d)-(n/d) für positive und fraction:=ceil(n/d)-(n/d) für negative Zahlen, so in etwa. Das Ergebnis ist aber nicht 100% genau und darin unterscheidet es sich vom Modulus. Es gibt auch die "round" Funktion noch so ein Scherz. http://de.wikipedia.org/wiki/Gaußklammer
Mensch Leute, stellt euch nicht so an! Dafür gibts in der Mathebibliothek eine Funktion: double fmod( double x, double y );
http://www.cplusplus.com/reference/cmath/fmod/ "Compute remainder of division Returns the floating-point remainder of numer/denom (rounded towards zero): fmod = numer - tquot * denom Where tquot is the truncated (i.e., rounded towards zero) result of: numer/denom. A similar function, remainder, returns the same but with the quotient rounded to the nearest integer (instead of truncated)."
... CONFORMING TO The functions remainder(), remainderf(), and remainderl() are specified in C99 and POSIX.1-2001. The function drem() is from 4.3BSD. The float and long double variants dremf() and dreml() exist on some systems, such as Tru64 and glibc2. Avoid the use of these functions in favor of remainder() etc.
Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.