float + modulo

Gast #1003335
Lesenswert?

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
Gast #3807084
Lesenswert?

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)."
#3807106
Lesenswert?

...
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.

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren