File tree Expand file tree Collapse file tree 2 files changed +22
-0
lines changed
javalanglib/src/main/scala/java/lang
test-suite/shared/src/test/scala/org/scalajs/testsuite/javalib/lang Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -96,4 +96,10 @@ object Byte {
9696
9797 @ inline def compare (x : scala.Byte , y : scala.Byte ): scala.Int =
9898 x - y
99+
100+ @ inline def toUnsignedInt (x : scala.Byte ): scala.Int =
101+ x.toInt & 0xff
102+
103+ @ inline def toUnsignedLong (x : scala.Byte ): scala.Long =
104+ toUnsignedInt(x).toLong
99105}
Original file line number Diff line number Diff line change @@ -43,6 +43,22 @@ class ByteTest {
4343 assertEquals(0 , compare(3 .toByte, 3 .toByte))
4444 }
4545
46+ @ Test def toUnsignedInt (): Unit = {
47+ assertEquals(0 , JByte .toUnsignedInt(0 .toByte))
48+ assertEquals(42 , JByte .toUnsignedInt(42 .toByte))
49+ assertEquals(214 , JByte .toUnsignedInt(- 42 .toByte))
50+ assertEquals(128 , JByte .toUnsignedInt(Byte .MinValue ))
51+ assertEquals(127 , JByte .toUnsignedInt(Byte .MaxValue ))
52+ }
53+
54+ @ Test def toUnsignedLong (): Unit = {
55+ assertEquals(0L , JByte .toUnsignedLong(0 .toByte))
56+ assertEquals(42L , JByte .toUnsignedLong(42 .toByte))
57+ assertEquals(214L , JByte .toUnsignedLong(- 42 .toByte))
58+ assertEquals(128L , JByte .toUnsignedLong(Byte .MinValue ))
59+ assertEquals(127L , JByte .toUnsignedLong(Byte .MaxValue ))
60+ }
61+
4662 @ Test def parseString (): Unit = {
4763 def test (s : String , v : Byte ): Unit = {
4864 assertEquals(v, JByte .parseByte(s))
You can’t perform that action at this time.
0 commit comments