Vad är golvfunktion i matematik?
En golvfunktion som också är känd som den största heltalsfunktionen i matematik tar ett reellt tal "x" som indata. Det returnerar det största heltal som är mindre än eller lika med inmatat nummer x. Det betecknas normalt som golv(x) eller ⌊x⌋. Det används för att omvandla ett reellt tal med bråkdel till ett heltal utan bråkdel. För att förstå det bättre låt oss ta en snabb titt på exemplen nedan.floor(5) = 5
floor (1.3) = 1
floor (7.9) = 7
Vad är metoden Math.floor() i Java?
Java ger en motsvarighet till matematisk golvfunktion. Så här kan du förstå det.Metodhuvud
public static double floor(double x)
Metoden tar ett dubbelt värde ( dubbel x ) som en parameter vars golv måste bestämmas. Det kräver inte att importera något externt paket.
Retur Skriv math.floor
Metoden returnerar ett dubbelt ( dubbelt golv ) värde som är mindre än eller lika med den givna parametern.Exempel
public class Driver1 {
public static void main(String[] args) {
double x = 50; // floor for whole number (Integer value)
double floorValue = Math.floor(x);
System.out.println("floor⌊" + x + "⌋ = " + floorValue);
x = 21.7; // floor for positive decimal
floorValue = Math.floor(x);
System.out.println("floor⌊" + x + "⌋ = " + floorValue);
x = -21.7; // floor for negative decimal
floorValue = Math.floor(x);
System.out.println("floor⌊" + x + "⌋ = " + floorValue);
x = 0; // floor for zero (Integer value)
floorValue = Math.floor(x);
System.out.println("floor⌊" + x + "⌋ = " + floorValue);
// Boundary Cases
x = +3.3/0; // Case I - floor for +Infinity
floorValue = Math.floor(x);
System.out.println("floor⌊" + x + "⌋ = " + floorValue);
x = -3.3/0; // Case II - floor for -infinity
floorValue = Math.floor(x);
System.out.println("floor⌊" + x + "⌋ = " + floorValue);
x = -0.0/0; // Case III - floor for NaN
floorValue = Math.floor(x);
System.out.println("floor⌊" + x + "⌋ = " + floorValue);
}
}
Produktion
våning⌊50,0⌋ = 50,0 våning⌊21,7⌋ = 21,0 våning⌊-21,7⌋ = -22,0 våning⌊0,0⌋ = 0,0 våning⌊Oändlighet⌋ = Oändligt golv⌊-Oändlighet⌋ = -Oändligt golv