schnellerer Algorithmus
This commit is contained in:
parent
c1b92cad8f
commit
77c915ada1
1 changed files with 13 additions and 12 deletions
|
@ -1,17 +1,18 @@
|
||||||
#include <iostream>
|
#include<iostream>
|
||||||
|
|
||||||
long double Runden(long double Zahl, int NK=0, bool mathematisch=true)
|
long double round(long double number, long long digitsAfterDecimalPoint, bool mathematical)
|
||||||
{
|
{
|
||||||
//Rückgabe Zahl auf NK Nachkommastellen gerundet
|
short loop = digitsAfterDecimalPoint;
|
||||||
long long Schleife;
|
|
||||||
|
|
||||||
for(Schleife=NK;Schleife>0;Schleife--) Zahl*=10;
|
while(loop>0) number *= 10, loop--;
|
||||||
for(Schleife=NK;Schleife<0;Schleife++) Zahl/=10;
|
while(loop<0) number /= 10, loop++;
|
||||||
if(Zahl-(long long)Zahl>0.5 || Zahl-(long long)Zahl==0.5 && (mathematisch=false || (long long)Zahl%2!=0)) Zahl++;
|
|
||||||
|
|
||||||
Zahl=(long long)Zahl;
|
if(number-(long long)number>0.5 || number-(long long)number==0.5 && ((long long)number%2!=0 || mathematical==false)) number++;
|
||||||
for(Schleife=NK;Schleife>0;Schleife--) Zahl/=10;
|
|
||||||
for(Schleife=NK;Schleife<0;Schleife++) Zahl*=10;
|
|
||||||
|
|
||||||
return(Zahl);
|
number = (long long)number;
|
||||||
|
|
||||||
|
while(digitsAfterDecimalPoint>0) number /= 10, digitsAfterDecimalPoint--;
|
||||||
|
while(digitsAfterDecimalPoint<0) number *= 10, digitsAfterDecimalPoint++;
|
||||||
|
|
||||||
|
return(number);
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue