IEEERemainder: Unterschied zwischen den Versionen

Aus JACK Wiki
Zur Navigation springen Zur Suche springen
Keine Bearbeitungszusammenfassung
Keine Bearbeitungszusammenfassung
Zeile 173: Zeile 173:
}
}
</syntaxhighlight>
</syntaxhighlight>
=== Javadoc ===
<span class="mw-customtoggle-myDivision-Javadoc">[Anzeigen]</span>
<div class="mw-collapsible mw-collapsed" id="mw-customcollapsible-myDivision-Javadoc">
double java.lang.Math.IEEEremainder(double f1, double f2)
Computes the remainder operation on two arguments as prescribed by the IEEE 754 standard. The remainder value is mathematically equal to f1 - f2 × n, where n is the mathematical integer closest to the exact mathematical value of the quotient f1/f2, and if two mathematical integers are equally close to f1/f2, then n is the integer that is even. If the remainder is zero, its sign is the same as the sign of the first argument. Special cases:
If either argument is NaN, or the first argument is infinite, or the second argument is positive zero or negative zero, then the result is NaN.
If the first argument is finite and the second argument is infinite, then the result is the same as the first argument.
Parameters:
f1 the dividend.
f2 the divisor.
Returns:
the remainder when f1 is divided by f2.
</div>


[[Kategorie:Evaluatorfunktion]]
[[Kategorie:Evaluatorfunktion]]

Version vom 29. Januar 2018, 09:29 Uhr

Beschreibung

Die Funktion IEEEremainder berechnet die Remainder-Operation auf zwei Argumente, wie es in dem IEEE 745 Standtard beschrieben ist [1]. Die Funktion erwartet zwei Zahlen und gibt das entsprechende Ergebnis zurück.

Syntax

IEEEremainder(Gleitkommazahl f1, Gleitkommazahl f2)

Parameter

  • f1 - Zähler
  • f2 - Nenner

Return Value

  • Gibt den Rest-Wert zurück, wenn f1 durch f2 geteilt wird

Beispiele

Standardfälle

IEEEremainder(4,2)   --> returns 0
IEEEremainder(3,2)   --> returns -1

Benutzung mit Variablen

IEEEremainder([pos=1],[pos=2])
IEEEremainder([var=a],[var=b])

JUnit Tests

[Anzeigen]

@BeforeClass
public static void beforeTest() {
	
		fillInVariableMap.put(1, OMConverter.toObject("<OMOBJ><OMI>0</OMI></OMOBJ>"));
		fillInVariableMap.put(2, OMConverter.toObject("<OMOBJ><OMI>20</OMI></OMOBJ>"));
		fillInVariableMap.put(3, OMConverter.toObject("<OMOBJ><OMI>-10</OMI></OMOBJ>"));

		exerciseVariableMap.put("a", OMConverter.toObject("<OMOBJ><OMI>0</OMI></OMOBJ>"));
		exerciseVariableMap.put("b", OMConverter.toObject("<OMOBJ><OMI>20</OMI></OMOBJ>"));
		exerciseVariableMap.put("c", OMConverter.toObject("<OMOBJ><OMI>-10</OMI></OMOBJ>"));
	
}

@Test
public void testIEEERemainder1() {
	assertEquals(-1, Evaluator.getNumberResult("IEEEremainder(3, 2)", exerciseVariableMap, fillInVariableMap), 0);
}

@Test
public void testIEEERemainder2() {
	assertEquals(0, Evaluator.getNumberResult("IEEEremainder(4, 2)", exerciseVariableMap, fillInVariableMap), 0);
}

@Test
public void testIEEERemainder3() {
	assertEquals(1, Evaluator.getNumberResult("IEEEremainder(10, 3)", exerciseVariableMap, fillInVariableMap), 0);
}

@Test
public void testIEEERemainder4() {
	assertEquals(-1, Evaluator.getNumberResult("IEEEremainder(11, 3)", exerciseVariableMap, fillInVariableMap), 0);
}

@Test
public void testIEEERemainder5() {
	assertEquals(-1, Evaluator.getNumberResult("IEEEremainder(27, 4)", exerciseVariableMap, fillInVariableMap), 0);
}

@Test
public void testIEEERemainder6() {
	assertEquals(-2, Evaluator.getNumberResult("IEEEremainder(28, 5)", exerciseVariableMap, fillInVariableMap), 0);
}

@Test // It returns for Example 1.800000000XXX not 1.8
public void testIEEERemainderWithPointNumberResults1() {
	assertEquals(1.8, Evaluator.getNumberResult("IEEEremainder(17.8, 4)", exerciseVariableMap, fillInVariableMap),
			0.00001);
}

@Test
public void testIEEERemainderWithPointNumberResults2() {
	assertEquals(1.4, Evaluator.getNumberResult("IEEEremainder(17.8, 4.1)", exerciseVariableMap, fillInVariableMap),
			0.00001);
}

@Test
public void testIEEERemainderWithPointNumberResults3() {
	assertEquals(0.1,
			Evaluator.getNumberResult("IEEEremainder(-16.3, 4.1)", exerciseVariableMap, fillInVariableMap), 0.00001);
}

@Test
public void testIEEERemainderWithPointNumberResults4() {
	assertEquals(1.4,
			Evaluator.getNumberResult("IEEEremainder(17.8, -4.1)", exerciseVariableMap, fillInVariableMap), 0.00001);
}

@Test
public void testIEEERemainderWithPointNumberResults5() {
	assertEquals(-1.4,
			Evaluator.getNumberResult("IEEEremainder(-17.8, -4.1)", exerciseVariableMap, fillInVariableMap), 0.00001);
}

@Test
public void testIEEERemainderWithInput1() {
	assertEquals(0, Evaluator.getNumberResult("IEEEremainder([pos=1], 4)", exerciseVariableMap, fillInVariableMap),
			0);

}

@Test
public void testIEEERemainderWithInput2() {
	assertEquals(0,
			Evaluator.getNumberResult("IEEEremainder([pos=2], [pos=3])", exerciseVariableMap, fillInVariableMap),
			0);
}

@Test
public void testIEEERemainderWithVariables1() {
	assertEquals(0, Evaluator.getNumberResult("IEEEremainder([var=a], 4)", exerciseVariableMap, fillInVariableMap),
			0);
}

@Test
public void testIEEERemainderWithVariables2() {
	assertEquals(0,
			Evaluator.getNumberResult("IEEEremainder([var=b], [var=c])", exerciseVariableMap, fillInVariableMap),
			0);
}

@Test
public void testIEEERemainderWithExpressions1() {
	assertEquals(0, Evaluator.getNumberResult("IEEEremainder('15', 'IEEEremainder(10, 3)')", exerciseVariableMap,
			fillInVariableMap), 0);

}

@Test
public void testIEEERemainderWithExpressions2() {
	assertEquals(0, Evaluator.getNumberResult("IEEEremainder('IEEEremainder(10, 3)', 'IEEEremainder(10, 3)')",
			exerciseVariableMap, fillInVariableMap), 0);
}

@Test(expected = FunctionInvalidArgumentTypeException.class)
public void testIEEERemainderWithWrongInputCharacter() {
	Evaluator.getNumberResult("IEEEremainder(17.8, a)", exerciseVariableMap, fillInVariableMap);
}

@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testIEEERemainderWithOneArgument() {
	Evaluator.getNumberResult("IEEEremainder(8)", exerciseVariableMap, fillInVariableMap);
	fail();
}

@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testIEEERemainderWithThreeArguments() {
	Evaluator.getNumberResult("IEEEremainder(3, 2, 8)", exerciseVariableMap, fillInVariableMap);
	fail();
}

@Test(expected = UndefinedExerciseVariableException.class)
public void testIEEERemainderWithMissingExerciseVariable() {
	Evaluator.getNumberResult("IEEEremainder('[var=j]', '3')", exerciseVariableMap, fillInVariableMap);
	fail();
}

@Test(expected = UndefinedFillInVariableException.class)
public void testIEEERemainderWithMissingInput() {
	Evaluator.getNumberResult("IEEEremainder('[pos=42]', '3')", exerciseVariableMap, fillInVariableMap);
	fail();
}

@Test(expected = FunctionInvalidArgumentException.class)
public void testIEEERemainderAtZero() {
	Evaluator.getNumberResult("IEEEremainder(5, 0)", exerciseVariableMap, fillInVariableMap);
	fail();
}