File tree Expand file tree Collapse file tree 4 files changed +44
-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 4 files changed +44
-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 @@ -98,4 +98,10 @@ object Short {
9898
9999 def reverseBytes (i : scala.Short ): scala.Short =
100100 (((i >>> 8 ) & 0xff ) + ((i & 0xff ) << 8 )).toShort
101+
102+ @ inline def toUnsignedInt (x : scala.Short ): scala.Int =
103+ x.toInt & 0xffff
104+
105+ @ inline def toUnsignedLong (x : scala.Short ): scala.Long =
106+ toUnsignedInt(x).toLong
101107}
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))
Original file line number Diff line number Diff line change @@ -43,6 +43,22 @@ class ShortTest {
4343 assertEquals(0 , compare(3 .toShort, 3 .toShort))
4444 }
4545
46+ @ Test def toUnsignedInt (): Unit = {
47+ assertEquals(0 , JShort .toUnsignedInt(0 .toShort))
48+ assertEquals(42 , JShort .toUnsignedInt(42 .toShort))
49+ assertEquals(65494 , JShort .toUnsignedInt(- 42 .toShort))
50+ assertEquals(32768 , JShort .toUnsignedInt(Short .MinValue ))
51+ assertEquals(32767 , JShort .toUnsignedInt(Short .MaxValue ))
52+ }
53+
54+ @ Test def toUnsignedLong (): Unit = {
55+ assertEquals(0L , JShort .toUnsignedLong(0 .toShort))
56+ assertEquals(42L , JShort .toUnsignedLong(42 .toShort))
57+ assertEquals(65494L , JShort .toUnsignedLong(- 42 .toShort))
58+ assertEquals(32768L , JShort .toUnsignedLong(Short .MinValue ))
59+ assertEquals(32767L , JShort .toUnsignedLong(Short .MaxValue ))
60+ }
61+
4662 @ Test def parseString (): Unit = {
4763 def test (s : String , v : Short ): Unit = {
4864 assertEquals(v, JShort .parseShort(s))
You can’t perform that action at this time.
0 commit comments