package com.oracle.truffle.llvm.tests.types.floating;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import com.oracle.truffle.llvm.runtime.floating.LLVM80BitFloat;
public class LLVM80BitFromIntTest extends LLVM80BitTest {
@Test
public void testZero() {
LLVM80BitFloat val = LLVM80BitFloat.fromInt(0);
LLVM80BitFloat expected = LLVM80BitFloat.fromRawValues(false, 0, 0);
assertEquals(expected, val);
}
@Test
public void testOne() {
LLVM80BitFloat val = LLVM80BitFloat.fromInt(1);
LLVM80BitFloat expected = LLVM80BitFloat.fromRawValues(false, 0x3fff, Long.reverse(1));
assertEquals(expected, val);
}
@Test
public void testPositiveInfinity() {
LLVM80BitFloat test = LLVM80BitFloat.fromRawValues(false, 0b111111111111111, 1L << 63);
assertTrue(test.isPositiveInfinity());
assertTrue(test.isInfinity());
assertFalse(test.isNegativeInfinity());
}
@Test
public void testNegativeInfinity() {
LLVM80BitFloat test = LLVM80BitFloat.fromRawValues(true, 0b111111111111111, 1L << 63);
assertTrue(test.isNegativeInfinity());
assertTrue(test.isInfinity());
assertFalse(test.isPositiveInfinity());
}
@Test
public void testQNan() {
LLVM80BitFloat test = nan();
assertTrue(!test.isInfinity());
assertFalse(test.isOrdered());
}
@Test
public void testTen() {
LLVM80BitFloat val = LLVM80BitFloat.fromInt(10);
LLVM80BitFloat expected = LLVM80BitFloat.fromRawValues(false, 0x4002, Long.reverse(5));
assertEquals(expected, val);
}
@Test
public void testMaxInt() {
LLVM80BitFloat val = LLVM80BitFloat.fromInt(Integer.MAX_VALUE);
LLVM80BitFloat expected = LLVM80BitFloat.fromRawValues(false, 0x401d, 0xfffffffe00000000L);
assertEquals(expected, val);
}
@Test
public void testMinInt() {
LLVM80BitFloat val = LLVM80BitFloat.fromInt(Integer.MIN_VALUE);
LLVM80BitFloat expected = LLVM80BitFloat.fromRawValues(true, 0x401e, 0x8000000000000000L);
assertEquals(expected, val);
}
@Test
public void testMinusOne() {
LLVM80BitFloat val = LLVM80BitFloat.fromInt(-1);
LLVM80BitFloat expected = LLVM80BitFloat.fromRawValues(true, 0x3fff, Long.reverse(1));
assertEquals(expected, val);
}
@Test
public void testNegative() {
LLVM80BitFloat val = LLVM80BitFloat.fromInt(-1234);
LLVM80BitFloat expected = LLVM80BitFloat.fromRawValues(true, 0x4009, 0x9a40000000000000L);
assertEquals(expected, val);
}
@Test
public void testHighValue() {
LLVM80BitFloat val = LLVM80BitFloat.fromInt(1234567);
LLVM80BitFloat expected = LLVM80BitFloat.fromRawValues(false, 0b100000000010011, 0x96b4380000000000L);
assertEquals(expected, val);
}
}