Scala long to java long

Scala long to java long DEFAULT
packagejava.langimportscalanative.runtime.Intrinsics.{divULong, remULong}importscalanative.runtime.LLVMIntrinsicsfinalclassLong(val_value: scala.Long) extendsNumberwithComparable[Long] {@inline defthis(s: String) =this(Long.parseLong(s))@inline overridedefbyteValue(): scala.Byte= _value.toByte@inline overridedefshortValue(): scala.Short= _value.toShort@inline overridedefintValue(): scala.Int= _value.toInt@inline overridedeflongValue(): scala.Long= _value@inline overridedeffloatValue(): scala.Float= _value.toFloat@inline overridedefdoubleValue(): scala.Double= _value.toDouble@inline overridedefequals(that: Any): scala.Boolean= that match {casethat: Long=> _value == that._valuecase _ =>false }@inline overridedefhashCode():Int=Long.hashCode(_value)@inline overridedefcompareTo(that: Long):Int=Long.compare(_value, that._value)@inline overridedeftoString():String=Long.toString(_value)@inline overridedef__scala_==(other: _Object): scala.Boolean= other match {caseother: java.lang.Long=> _value == other._valuecaseother: java.lang.Byte=> _value == other._valuecaseother: java.lang.Short=> _value == other._valuecaseother: java.lang.Integer=> _value == other._valuecaseother: java.lang.Float=> _value == other._valuecaseother: java.lang.Double=> _value == other._valuecaseother: java.lang.Character=> _value == other._valuecase _ =>super.__scala_==(other) }@inline overridedef__scala_##: scala.Int= {vallv= _valuevaliv= _value.toIntif (iv == lv) ivelseLong.hashCode(lv) }/* * Ported from ScalaJS * * Methods on scala.Long * The following methods are only here to properly support reflective calls * on boxed primitive values. YOU WILL NOT BE ABLE TO USE THESE METHODS, since * we use the true javalib to lookup symbols, this file contains only * implementations.*/protecteddeftoByte: scala.Byte= _value.toByteprotecteddeftoShort: scala.Short= _value.toShortprotecteddeftoChar: scala.Char= _value.toCharprotecteddeftoInt: scala.Int= _value.toIntprotecteddeftoLong: scala.Long= _valueprotecteddeftoFloat: scala.Float= _value.toFloatprotecteddeftoDouble: scala.Double= _value.toDoubleprotecteddefunary_~: scala.Long=~_valueprotecteddefunary_+: scala.Long= _valueprotecteddefunary_-: scala.Long=-_valueprotecteddef+(x: String):String=""+ _value + xprotecteddef<<(x: scala.Int): scala.Long= _value << xprotecteddef<<(x: scala.Long): scala.Long= _value << xprotecteddef>>>(x: scala.Int): scala.Long= _value >>> xprotecteddef>>>(x: scala.Long): scala.Long= _value >>> xprotecteddef>>(x: scala.Int): scala.Long= _value >> xprotecteddef>>(x: scala.Long): scala.Long= _value >> xprotecteddef<(x: scala.Byte): scala.Boolean= _value < xprotecteddef<(x: scala.Short): scala.Boolean= _value < xprotecteddef<(x: scala.Char): scala.Boolean= _value < xprotecteddef<(x: scala.Int): scala.Boolean= _value < xprotecteddef<(x: scala.Long): scala.Boolean= _value < xprotecteddef<(x: scala.Float): scala.Boolean= _value < xprotecteddef<(x: scala.Double): scala.Boolean= _value < xprotecteddef<=(x: scala.Byte): scala.Boolean= _value <= xprotecteddef<=(x: scala.Short): scala.Boolean= _value <= xprotecteddef<=(x: scala.Char): scala.Boolean= _value <= xprotecteddef<=(x: scala.Int): scala.Boolean= _value <= xprotecteddef<=(x: scala.Long): scala.Boolean= _value <= xprotecteddef<=(x: scala.Float): scala.Boolean= _value <= xprotecteddef<=(x: scala.Double): scala.Boolean= _value <= xprotecteddef>(x: scala.Byte): scala.Boolean= _value > xprotecteddef>(x: scala.Short): scala.Boolean= _value > xprotecteddef>(x: scala.Char): scala.Boolean= _value > xprotecteddef>(x: scala.Int): scala.Boolean= _value > xprotecteddef>(x: scala.Long): scala.Boolean= _value > xprotecteddef>(x: scala.Float): scala.Boolean= _value > xprotecteddef>(x: scala.Double): scala.Boolean= _value > xprotecteddef>=(x: scala.Byte): scala.Boolean= _value >= xprotecteddef>=(x: scala.Short): scala.Boolean= _value >= xprotecteddef>=(x: scala.Char): scala.Boolean= _value >= xprotecteddef>=(x: scala.Int): scala.Boolean= _value >= xprotecteddef>=(x: scala.Long): scala.Boolean= _value >= xprotecteddef>=(x: scala.Float): scala.Boolean= _value >= xprotecteddef>=(x: scala.Double): scala.Boolean= _value >= xprotecteddef|(x: scala.Byte): scala.Long= _value | xprotecteddef|(x: scala.Short): scala.Long= _value | xprotecteddef|(x: scala.Char): scala.Long= _value | xprotecteddef|(x: scala.Int): scala.Long= _value | xprotecteddef|(x: scala.Long): scala.Long= _value | xprotecteddef&(x: scala.Byte): scala.Long= _value & xprotecteddef&(x: scala.Short): scala.Long= _value & xprotecteddef&(x: scala.Char): scala.Long= _value & xprotecteddef&(x: scala.Int): scala.Long= _value & xprotecteddef&(x: scala.Long): scala.Long= _value & xprotecteddef^(x: scala.Byte): scala.Long= _value ^ xprotecteddef^(x: scala.Short): scala.Long= _value ^ xprotecteddef^(x: scala.Char): scala.Long= _value ^ xprotecteddef^(x: scala.Int): scala.Long= _value ^ xprotecteddef^(x: scala.Long): scala.Long= _value ^ xprotecteddef+(x: scala.Byte): scala.Long= _value + xprotecteddef+(x: scala.Short): scala.Long= _value + xprotecteddef+(x: scala.Char): scala.Long= _value + xprotecteddef+(x: scala.Int): scala.Long= _value + xprotecteddef+(x: scala.Long): scala.Long= _value + xprotecteddef+(x: scala.Float): scala.Float= _value + xprotecteddef+(x: scala.Double): scala.Double= _value + xprotecteddef-(x: scala.Byte): scala.Long= _value - xprotecteddef-(x: scala.Short): scala.Long= _value - xprotecteddef-(x: scala.Char): scala.Long= _value - xprotecteddef-(x: scala.Int): scala.Long= _value - xprotecteddef-(x: scala.Long): scala.Long= _value - xprotecteddef-(x: scala.Float): scala.Float= _value - xprotecteddef-(x: scala.Double): scala.Double= _value - xprotecteddef*(x: scala.Byte): scala.Long= _value - xprotecteddef*(x: scala.Short): scala.Long= _value - xprotecteddef*(x: scala.Char): scala.Long= _value - xprotecteddef*(x: scala.Int): scala.Long= _value - xprotecteddef*(x: scala.Long): scala.Long= _value - xprotecteddef*(x: scala.Float): scala.Float= _value - xprotecteddef*(x: scala.Double): scala.Double= _value - xprotecteddef/(x: scala.Byte): scala.Long= _value / xprotecteddef/(x: scala.Short): scala.Long= _value / xprotecteddef/(x: scala.Char): scala.Long= _value / xprotecteddef/(x: scala.Int): scala.Long= _value / xprotecteddef/(x: scala.Long): scala.Long= _value / xprotecteddef/(x: scala.Float): scala.Float= _value / xprotecteddef/(x: scala.Double): scala.Double= _value / xprotecteddef%(x: scala.Byte): scala.Long= _value % xprotecteddef%(x: scala.Short): scala.Long= _value % xprotecteddef%(x: scala.Char): scala.Long= _value % xprotecteddef%(x: scala.Int): scala.Long= _value % xprotecteddef%(x: scala.Long): scala.Long= _value % xprotecteddef%(x: scala.Float): scala.Float= _value % xprotecteddef%(x: scala.Double): scala.Double= _value % x}objectLong {finalvalTYPE= scala.Predef.classOf[scala.scalanative.runtime.PrimitiveLong]finalvalMIN_VALUE=LfinalvalMAX_VALUE=LfinalvalSIZE=64finalvalBYTES=8@inline defbitCount(l: scala.Long): scala.Int=LLVMIntrinsics.`llvm.ctpop.i64`(l).toInt@inline defcompare(x: scala.Long, y: scala.Long): scala.Int=if (x == y) 0elseif (x < y) -1else1@inline defcompareUnsigned(x: scala.Long, y: scala.Long): scala.Int= compare(x ^ scala.Long.MinValue, y ^ scala.Long.MinValue)privatedeffail(s: String):Nothing=thrownewNumberFormatException(s"""For input string: "$s"""")defdecode(nm: String):Long= {if (nm ==null)thrownewNumberFormatException("null")vallength= nm.length()if (length ==0) fail(nm)vari=0varfirstDigit= nm.charAt(i)valnegative= firstDigit =='-'valpositive= firstDigit =='+'if (negative || positive) {if (length ==1) fail(nm) i +=1 firstDigit = nm.charAt(i) }varbase=10if (firstDigit =='0') { i +=1if (i == length) {return valueOf(0L) } firstDigit = nm.charAt(i)if (firstDigit =='x'|| firstDigit =='X') { i +=1if (i == length) fail(nm) base =16 } else { base =8 } } elseif (firstDigit =='#') { i +=1if (i == length) fail(nm) base =16 } valueOf(parse(nm, i, base, negative)) }@inlinedefdivideUnsigned(dividend: scala.Long, divisor: scala.Long): scala.Long= divULong(dividend, divisor)@inline defgetLong(nm: String):Long= getLong(nm, null)@inline defgetLong(nm: String, v: scala.Long):Long= {valresult= getLong(nm, null)if (result ==null) newLong(v)else result }defgetLong(nm: String, v: Long):Long=if (nm ==null|| nm.length() ==0) { v } else {valprop=System.getProperty(nm)if (prop ==null) { v } else {try { decode(prop) } catch {casee: NumberFormatException=> v } } }@inline defhashCode(value: scala.Long):Int= value.toInt ^ (value >>>32).toInt@inline defhighestOneBit(i: scala.Long): scala.Long= ((1L<<63) >>> numberOfLeadingZeros(i)) & i@inline deflowestOneBit(i: scala.Long): scala.Long= i & (-i)@inline defmax(a: scala.Long, b: scala.Long): scala.Long=Math.max(a, b)@inline defmin(a: scala.Long, b: scala.Long): scala.Long=Math.min(a, b)@inline defnumberOfLeadingZeros(l: scala.Long):Int=LLVMIntrinsics.`llvm.ctlz.i64`(l, iszeroundef =false).toInt@inline defnumberOfTrailingZeros(l: scala.Long):Int=LLVMIntrinsics.`llvm.cttz.i64`(l, iszeroundef =false).toInt@inline defparseLong(s: String): scala.Long= parseLong(s, 10)@inline defparseLong(s: String, radix: Int): scala.Long= {if (s ==null)thrownewNumberFormatException("null")if (radix <Character.MIN_RADIX)thrownewNumberFormatException(s"radix $radix less than Character.MIN_RADIX" )if (radix >Character.MAX_RADIX)thrownewNumberFormatException(s"radix $radix greater than Character.MAX_RADIX" )vallength= s.length()if (length ==0) fail(s)valnegative= s.charAt(0) =='-'valhasPlusSign= s.charAt(0) =='+'if ((negative || hasPlusSign) && length ==1) fail(s)valoffset=if (negative || hasPlusSign) 1else0 parse(s, offset, radix, negative) }privatedefparse(s: String,_offset: Int,radix: Int,negative: scala.Boolean ): scala.Long= {valmax=MIN_VALUE/ radixvarresult=0Lvaroffset= _offsetvallength= s.length()while (offset < length) {valdigit=Character.digit(s.charAt(offset), radix) offset +=1if (digit ==-1) fail(s)if (max > result) fail(s)valnext= result * radix - digitif (next > result) fail(s) result = next }if (!negative) { result =-resultif (result <0) throw fail(s) } result }@inlinedefremainderUnsigned(dividend: scala.Long, divisor: scala.Long): scala.Long= remULong(dividend, divisor)@inline defreverse(l: scala.Long): scala.Long=LLVMIntrinsics.`llvm.bitreverse.i64`(l)@inline defreverseBytes(l: scala.Long): scala.Long=LLVMIntrinsics.`llvm.bswap.i64`(l)@inline defrotateLeft(i: scala.Long, distance: scala.Int): scala.Long= (i << distance) | (i >>>-distance)@inline defrotateRight(i: scala.Long, distance: scala.Int): scala.Long= (i >>> distance) | (i <<-distance)@inline defsignum(i: scala.Long): scala.Int=if (i ==0) 0elseif (i <0) -1else1@inline defsum(a: scala.Long, b: scala.Long): scala.Long= a + bdeftoBinaryString(l: scala.Long):String= {varcount=if (l ==0L) 1else numberOfLeadingZeros(l)valbuffer=newArray[Char](count)vark= ldo { count -=1 buffer(count) = ((k & 1) +'0').toChar k >>=1 } while (count >0)
Sours: https://github.com/scala-native/scala-native/blob/master/javalib/src/main/scala/java/lang/Long.scala

Scala - Data Types



Scala has all the same data types as Java, with the same memory footprint and precision. Following is the table giving details about all the data types available in Scala −

Sr.NoData Type & Description
1

Byte

8 bit signed value. Range from to

2

Short

16 bit signed value. Range to

3

Int

32 bit signed value. Range to

4

Long

64 bit signed value. to

5

Float

32 bit IEEE single-precision float

6

Double

64 bit IEEE double-precision float

7

Char

16 bit unsigned Unicode character. Range from U+ to U+FFFF

8

String

A sequence of Chars

9

Boolean

Either the literal true or the literal false

10

Unit

Corresponds to no value

11

Null

null or empty reference

12

Nothing

The subtype of every other type; includes no values

13

Any

The supertype of any type; any object is of type Any

14

AnyRef

The supertype of any reference type

All the data types listed above are objects. There are no primitive types like in Java. This means that you can call methods on an Int, Long, etc.

Scala Basic Literals

The rules Scala uses for literals are simple and intuitive. This section explains all basic Scala Literals.

Integral Literals

Integer literals are usually of type Int, or of type Long when followed by a L or l suffix. Here are some integer literals −

0 21 0xFFFFFFFF L

Floating Point Literal

Floating point literals are of type Float when followed by a floating point type suffix F or f, and are of type Double otherwise. Here are some floating point literals −

1e30f f e .1

Boolean Literals

The Boolean literals true and false are members of type Boolean.

Symbol Literals

A symbol literal 'x is a shorthand for the expression scala.Symbol("x"). Symbol is a case class, which is defined as follows.

package scala final case class Symbol private (name: String) { override def toString: String = "'" + name }

Character Literals

A character literal is a single character enclosed in quotes. The character is either a printable Unicode character or is described by an escape sequence. Here are some character literals −

'a' '\u' '\n' '\t'

String Literals

A string literal is a sequence of characters in double quotes. The characters are either printable Unicode character or are described by escape sequences. Here are some string literals −

"Hello,\nWorld!" "This string contains a \" character."

Multi-Line Strings

A multi-line string literal is a sequence of characters enclosed in triple quotes """ """. The sequence of characters is arbitrary, except that it may contain three or more consecutive quote characters only at the very end.

Characters must not necessarily be printable; newlines or other control characters are also permitted. Here is a multi-line string literal −

"""the present string spans three lines."""

Null Values

The null value is of type scala.Null and is thus compatible with every reference type. It denotes a reference value which refers to a special "null" object.

Escape Sequences

The following escape sequences are recognized in character and string literals.

Escape SequencesUnicodeDescription
\b\ubackspace BS
\t\uhorizontal tab HT
\n\ucformfeed FF
\f\ucformfeed FF
\r\udcarriage return CR
\"\udouble quote "
\'\usingle quote .
\\\ucbackslash \

A character with Unicode between 0 and may also be represented by an octal escape, i.e., a backslash '\' followed by a sequence of up to three octal characters. Following is the example to show few escape sequence characters −

Example

object Test { def main(args: Array[String]) { println("Hello\tWorld\n\n" ); } }

When the above code is compiled and executed, it produces the following result −

Output

Hello World
Sours: https://www.tutorialspoint.com/scala/scala_data_types.htm
  1. Hamer usa guitar for sale
  2. 2016 chrysler 300 srt8 horsepower
  3. Tamper resistant nuts and bolts
  4. Lil man pt 2

"Fossies" - the Fresh Open Source Software Archive

Member "scala/src/library/scala/Long.scala" (14 May , Bytes) of package /linux/misc/scalasrc.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Scala source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.


1 /* 2 * Scala (https://www.scala-lang.org) 3 * 4 * Copyright EPFL and Lightbend, Inc. 5 * 6 * Licensed under Apache License 7 * (http://www.apache.org/licenses/LICENSE). 8 * 9 * See the NOTICE file distributed with this work for 10 * additional information regarding copyright ownership. 11 */ 12 13 // DO NOT EDIT, CHANGES WILL BE LOST 14 // This auto-generated code can be modified in "project/GenerateAnyVals.scala". 15 // Afterwards, running "sbt generateSources" regenerates this source file. 16 17 package scala 18 19 /** `Long`, a bit signed integer (equivalent to Java's `long` primitive type) is a 20 * subtype of [[scala.AnyVal]]. Instances of `Long` are not 21 * represented by an object in the underlying runtime system. 22 * 23 * There is an implicit conversion from [[scala.Long]] => [[scala.runtime.RichLong]] 24 * which provides useful non-primitive operations. 25 */ 26 final abstract class Long private extends AnyVal { 27 def toByte: Byte 28 def toShort: Short 29 def toChar: Char 30 def toInt: Int 31 def toLong: Long 32 def toFloat: Float 33 def toDouble: Double 34 35 /** 36 * Returns the bitwise negation of this value. 37 * @example {{{ 38 * ~5 == -6 39 * // in binary: ~ == 40 * // 41 * }}} 42 */ 43 def unary_~ : Long 44 /** Returns this value, unmodified. */ 45 def unary_+ : Long 46 /** Returns the negation of this value. */ 47 def unary_- : Long 48 49 @deprecated("Adding a number and a String is deprecated. Use the string interpolation `s\"$num$str\"`","") 50 def+(x: String): String 51 52 /** 53 * Returns this value bit-shifted left by the specified number of bits, 54 * filling in the new right bits with zeroes. 55 * @example {{{ 6 << 3 == 48 // in binary: << 3 == }}} 56 */ 57 def<<(x: Int): Long 58 /** 59 * Returns this value bit-shifted left by the specified number of bits, 60 * filling in the new right bits with zeroes. 61 * @example {{{ 6 << 3 == 48 // in binary: << 3 == }}} 62 */ 63 def<<(x: Long): Long 64 /** 65 * Returns this value bit-shifted right by the specified number of bits, 66 * filling the new left bits with zeroes. 67 * @example {{{ 21 >>> 3 == 2 // in binary: >>> 3 == }}} 68 * @example {{{ 69 * >>> 3 == 70 * // in binary: >>> 3 == 71 * // 72 * }}} 73 */ 74 def>>>(x: Int): Long 75 /** 76 * Returns this value bit-shifted right by the specified number of bits, 77 * filling the new left bits with zeroes. 78 * @example {{{ 21 >>> 3 == 2 // in binary: >>> 3 == }}} 79 * @example {{{ 80 * >>> 3 == 81 * // in binary: >>> 3 == 82 * // 83 * }}} 84 */ 85 def>>>(x: Long): Long 86 /** 87 * Returns this value bit-shifted right by the specified number of bits, 88 * filling in the left bits with the same value as the left-most bit of this. 89 * The effect of this is to retain the sign of the value. 90 * @example {{{ 91 * >> 3 == -3 92 * // in binary: >> 3 == 93 * // 94 * }}} 95 */ 96 def>>(x: Int): Long 97 /** 98 * Returns this value bit-shifted right by the specified number of bits, 99 * filling in the left bits with the same value as the left-most bit of this. * The effect of this is to retain the sign of the value. * @example {{{ * >> 3 == -3 * // in binary: >> 3 == * // * }}} */ def>>(x: Long): Long /** Returns `true` if this value is equal to x, `false` otherwise. */ def==(x: Byte): Boolean /** Returns `true` if this value is equal to x, `false` otherwise. */ def==(x: Short): Boolean /** Returns `true` if this value is equal to x, `false` otherwise. */ def==(x: Char): Boolean /** Returns `true` if this value is equal to x, `false` otherwise. */ def==(x: Int): Boolean /** Returns `true` if this value is equal to x, `false` otherwise. */ def==(x: Long): Boolean /** Returns `true` if this value is equal to x, `false` otherwise. */ def==(x: Float): Boolean /** Returns `true` if this value is equal to x, `false` otherwise. */ def==(x: Double): Boolean /** Returns `true` if this value is not equal to x, `false` otherwise. */ def!=(x: Byte): Boolean /** Returns `true` if this value is not equal to x, `false` otherwise. */ def!=(x: Short): Boolean /** Returns `true` if this value is not equal to x, `false` otherwise. */ def!=(x: Char): Boolean /** Returns `true` if this value is not equal to x, `false` otherwise. */ def!=(x: Int): Boolean /** Returns `true` if this value is not equal to x, `false` otherwise. */ def!=(x: Long): Boolean /** Returns `true` if this value is not equal to x, `false` otherwise. */ def!=(x: Float): Boolean /** Returns `true` if this value is not equal to x, `false` otherwise. */ def!=(x: Double): Boolean /** Returns `true` if this value is less than x, `false` otherwise. */ def<(x: Byte): Boolean /** Returns `true` if this value is less than x, `false` otherwise. */ def<(x: Short): Boolean /** Returns `true` if this value is less than x, `false` otherwise. */ def<(x: Char): Boolean /** Returns `true` if this value is less than x, `false` otherwise. */ def<(x: Int): Boolean /** Returns `true` if this value is less than x, `false` otherwise. */ def<(x: Long): Boolean /** Returns `true` if this value is less than x, `false` otherwise. */ def<(x: Float): Boolean /** Returns `true` if this value is less than x, `false` otherwise. */ def<(x: Double): Boolean /** Returns `true` if this value is less than or equal to x, `false` otherwise. */ def<=(x: Byte): Boolean /** Returns `true` if this value is less than or equal to x, `false` otherwise. */ def<=(x: Short): Boolean /** Returns `true` if this value is less than or equal to x, `false` otherwise. */ def<=(x: Char): Boolean /** Returns `true` if this value is less than or equal to x, `false` otherwise. */ def<=(x: Int): Boolean /** Returns `true` if this value is less than or equal to x, `false` otherwise. */ def<=(x: Long): Boolean /** Returns `true` if this value is less than or equal to x, `false` otherwise. */ def<=(x: Float): Boolean /** Returns `true` if this value is less than or equal to x, `false` otherwise. */ def<=(x: Double): Boolean /** Returns `true` if this value is greater than x, `false` otherwise. */ def>(x: Byte): Boolean /** Returns `true` if this value is greater than x, `false` otherwise. */ def>(x: Short): Boolean /** Returns `true` if this value is greater than x, `false` otherwise. */ def>(x: Char): Boolean /** Returns `true` if this value is greater than x, `false` otherwise. */ def>(x: Int): Boolean /** Returns `true` if this value is greater than x, `false` otherwise. */ def>(x: Long): Boolean /** Returns `true` if this value is greater than x, `false` otherwise. */ def>(x: Float): Boolean /** Returns `true` if this value is greater than x, `false` otherwise. */ def>(x: Double): Boolean /** Returns `true` if this value is greater than or equal to x, `false` otherwise. */ def>=(x: Byte): Boolean /** Returns `true` if this value is greater than or equal to x, `false` otherwise. */ def>=(x: Short): Boolean /** Returns `true` if this value is greater than or equal to x, `false` otherwise. */ def>=(x: Char): Boolean /** Returns `true` if this value is greater than or equal to x, `false` otherwise. */ def>=(x: Int): Boolean /** Returns `true` if this value is greater than or equal to x, `false` otherwise. */ def>=(x: Long): Boolean /** Returns `true` if this value is greater than or equal to x, `false` otherwise. */ def>=(x: Float): Boolean /** Returns `true` if this value is greater than or equal to x, `false` otherwise. */ def>=(x: Double): Boolean /** * Returns the bitwise OR of this value and `x`. * @example {{{ * (0xf0 | 0xaa) == 0xfa * // in binary: * // | * // * // * }}} */ def|(x: Byte): Long /** * Returns the bitwise OR of this value and `x`. * @example {{{ * (0xf0 | 0xaa) == 0xfa * // in binary: * // | * // * // * }}} */ def|(x: Short): Long /** * Returns the bitwise OR of this value and `x`. * @example {{{ * (0xf0 | 0xaa) == 0xfa * // in binary: * // | * // * // * }}} */ def|(x: Char): Long /** * Returns the bitwise OR of this value and `x`. * @example {{{ * (0xf0 | 0xaa) == 0xfa * // in binary: * // | * // * // * }}} */ def|(x: Int): Long /** * Returns the bitwise OR of this value and `x`. * @example {{{ * (0xf0 | 0xaa) == 0xfa * // in binary: * // | * // * // * }}} */ def|(x: Long): Long /** * Returns the bitwise AND of this value and `x`. * @example {{{ * (0xf0 & 0xaa) == 0xa0 * // in binary: * // & * // * // * }}} */ def&(x: Byte): Long /** * Returns the bitwise AND of this value and `x`. * @example {{{ * (0xf0 & 0xaa) == 0xa0 * // in binary: * // & * // * // * }}} */ def&(x: Short): Long /** * Returns the bitwise AND of this value and `x`. * @example {{{ * (0xf0 & 0xaa) == 0xa0 * // in binary: * // & * // * // * }}} */ def&(x: Char): Long /** * Returns the bitwise AND of this value and `x`. * @example {{{ * (0xf0 & 0xaa) == 0xa0 * // in binary: * // & * // * // * }}} */ def&(x: Int): Long /** * Returns the bitwise AND of this value and `x`. * @example {{{ * (0xf0 & 0xaa) == 0xa0 * // in binary: * // & * // * // * }}} */ def&(x: Long): Long /** * Returns the bitwise XOR of this value and `x`. * @example {{{ * (0xf0 ^ 0xaa) == 0x5a * // in binary: * // ^ * // * // * }}} */ def ^(x: Byte): Long /** * Returns the bitwise XOR of this value and `x`. * @example {{{ * (0xf0 ^ 0xaa) == 0x5a * // in binary: * // ^ * // * // * }}} */ def ^(x: Short): Long /** * Returns the bitwise XOR of this value and `x`. * @example {{{ * (0xf0 ^ 0xaa) == 0x5a * // in binary: * // ^ * // * // * }}} */ def ^(x: Char): Long /** * Returns the bitwise XOR of this value and `x`. * @example {{{ * (0xf0 ^ 0xaa) == 0x5a * // in binary: * // ^ * // * // * }}} */ def ^(x: Int): Long /** * Returns the bitwise XOR of this value and `x`. * @example {{{ * (0xf0 ^ 0xaa) == 0x5a * // in binary: * // ^ * // * // * }}} */ def ^(x: Long): Long /** Returns the sum of this value and `x`. */ def+(x: Byte): Long /** Returns the sum of this value and `x`. */ def+(x: Short): Long /** Returns the sum of this value and `x`. */ def+(x: Char): Long /** Returns the sum of this value and `x`. */ def+(x: Int): Long /** Returns the sum of this value and `x`. */ def+(x: Long): Long /** Returns the sum of this value and `x`. */ def+(x: Float): Float /** Returns the sum of this value and `x`. */ def+(x: Double): Double /** Returns the difference of this value and `x`. */ def-(x: Byte): Long /** Returns the difference of this value and `x`. */ def-(x: Short): Long /** Returns the difference of this value and `x`. */ def-(x: Char): Long /** Returns the difference of this value and `x`. */ def-(x: Int): Long /** Returns the difference of this value and `x`. */ def-(x: Long): Long /** Returns the difference of this value and `x`. */ def-(x: Float): Float /** Returns the difference of this value and `x`. */ def-(x: Double): Double /** Returns the product of this value and `x`. */ def*(x: Byte): Long /** Returns the product of this value and `x`. */ def*(x: Short): Long /** Returns the product of this value and `x`. */ def*(x: Char): Long /** Returns the product of this value and `x`. */ def*(x: Int): Long /** Returns the product of this value and `x`. */ def*(x: Long): Long /** Returns the product of this value and `x`. */ def*(x: Float): Float /** Returns the product of this value and `x`. */ def*(x: Double): Double /** Returns the quotient of this value and `x`. */ def/(x: Byte): Long /** Returns the quotient of this value and `x`. */ def/(x: Short): Long /** Returns the quotient of this value and `x`. */ def/(x: Char): Long /** Returns the quotient of this value and `x`. */ def/(x: Int): Long /** Returns the quotient of this value and `x`. */ def/(x: Long): Long /** Returns the quotient of this value and `x`. */ def/(x: Float): Float /** Returns the quotient of this value and `x`. */ def/(x: Double): Double /** Returns the remainder of the division of this value by `x`. */ def%(x: Byte): Long /** Returns the remainder of the division of this value by `x`. */ def%(x: Short): Long /** Returns the remainder of the division of this value by `x`. */ def%(x: Char): Long /** Returns the remainder of the division of this value by `x`. */ def%(x: Int): Long /** Returns the remainder of the division of this value by `x`. */ def%(x: Long): Long /** Returns the remainder of the division of this value by `x`. */ def%(x: Float): Float /** Returns the remainder of the division of this value by `x`. */ def%(x: Double): Double // Provide a more specific return type for Scaladoc override defgetClass(): Class[Long] = ??? } object Long extends AnyValCompanion { /** The smallest value representable as a Long. */ final val MinValue = java.lang.Long.MIN_VALUE /** The largest value representable as a Long. */ final val MaxValue = java.lang.Long.MAX_VALUE /** Transform a value type into a boxed reference type. * * Runtime implementation determined by `scala.runtime.BoxesRunTime.boxToLong`. See [[https://github.com/scala/scala src/library/scala/runtime/BoxesRunTime.java]]. * * @param x the Long to be boxed * @return a java.lang.Long offering `x` as its underlying value. */ defbox(x: Long): java.lang.Long = ??? /** Transform a boxed type into a value type. Note that this * method is not typesafe: it accepts any Object, but will throw * an exception if the argument is not a java.lang.Long. * * Runtime implementation determined by `scala.runtime.BoxesRunTime.unboxToLong`. See [[https://github.com/scala/scala src/library/scala/runtime/BoxesRunTime.java]]. * * @param x the java.lang.Long to be unboxed. * @throws ClassCastException if the argument is not a java.lang.Long * @return the Long resulting from calling longValue() on `x` */ defunbox(x: java.lang.Object): Long = ??? /** The String representation of the scala.Long companion object. */ override def toString ="object scala.Long" /** Language mandated coercions from Long to "wider" types. */ import scala.language.implicitConversions @deprecated("Implicit conversion from Long to Float is dangerous because it loses precision. Write `.toFloat` instead.","") implicit deflong2float(x: Long): Float = x.toFloat @deprecated("Implicit conversion from Long to Double is dangerous because it loses precision. Write `.toDouble` instead.","") implicit deflong2double(x: Long): Double = x.toDouble }
Sours: https://fossies.org/linux/scala/src/library/scala/Long.scala
18 - More Integer Data Types (Int, Byte, Short, Long) in Java
Modifier and TypeMethod and Description

Returns the number of one-bits in the two's complement binary representation of the specified value.

Returns the value of this as a after a narrowing primitive conversion.

Compares two values numerically.

Compares two objects numerically.

Compares two values numerically treating the values as unsigned.

Decodes a into a .

Returns the unsigned quotient of dividing the first argument by the second where each argument and the result is interpreted as an unsigned value.

Returns the value of this as a after a widening primitive conversion.

Compares this object to the specified object.

Returns the value of this as a after a widening primitive conversion.

Determines the value of the system property with the specified name.

Determines the value of the system property with the specified name.

Returns the value of the system property with the specified name.

Returns a hash code for this .

Returns a hash code for a value; compatible with .

Returns a value with at most a single one-bit, in the position of the highest-order ("leftmost") one-bit in the specified value.

Returns the value of this as an after a narrowing primitive conversion.

Returns the value of this as a value.

Returns a value with at most a single one-bit, in the position of the lowest-order ("rightmost") one-bit in the specified value.

Returns the greater of two values as if by calling .

Returns the smaller of two values as if by calling .

Returns the number of zero bits preceding the highest-order ("leftmost") one-bit in the two's complement binary representation of the specified value.

Returns the number of zero bits following the lowest-order ("rightmost") one-bit in the two's complement binary representation of the specified value.

Parses the string argument as a signed decimal .

Parses the string argument as a signed in the radix specified by the second argument.

Parses the string argument as an unsigned decimal .

Parses the string argument as an unsigned in the radix specified by the second argument.

Returns the unsigned remainder from dividing the first argument by the second where each argument and the result is interpreted as an unsigned value.

Returns the value obtained by reversing the order of the bits in the two's complement binary representation of the specified value.

Returns the value obtained by reversing the order of the bytes in the two's complement representation of the specified value.

Returns the value obtained by rotating the two's complement binary representation of the specified value left by the specified number of bits.

Returns the value obtained by rotating the two's complement binary representation of the specified value right by the specified number of bits.

Returns the value of this as a after a narrowing primitive conversion.

Returns the signum function of the specified value.

Adds two values together as per the + operator.

Returns a string representation of the argument as an unsigned integer in base 2.

Returns a string representation of the argument as an unsigned integer in base 

Returns a string representation of the argument as an unsigned integer in base 8.

Returns a object representing this 's value.

Returns a object representing the specified .

Returns a string representation of the first argument in the radix specified by the second argument.

Returns a string representation of the argument as an unsigned decimal value.

Returns a string representation of the first argument as an unsigned integer value in the radix specified by the second argument.

Returns a instance representing the specified value.

Returns a object holding the value of the specified .

Returns a object holding the value extracted from the specified when parsed with the radix given by the second argument.

Sours: https://docs.oracle.com/javase/8/docs/api/java/lang/Long.html

Java long scala long to

Why in Scala Long cannot in initialized to null whear as Integer can

Scala is literal data type like in Java. Same is true for . But is a Wrapper class i.e

If you want nullable Long value, you can use


and are Scala types and are derived from , which is not a reference type (i.e. not ) and hence can't be . on the other hand is an alias for , which is a reference type.

No, it's not an oversight, and are consistent, using in Scala is considered a bad thing and, as I understand it, exists merely for Java compatibility (even for ) as well as .


In Scala, type is a subtype of all reference types (all types which inherit from - which is an alias of ). That's why you can use the value (of type ) anywhere a reference type is expected.

It is not, however, a subtype of any value type (types which inherit from ). Because types such as , , (corresponding to Java's primitive types) are value types, they cannot be null.

As for the type you mention: I guess this is , which is a subtype of (a.k.a. ): it's a reference type, so you can use .

It's probably easier to understand with this diagram of the Scala type hierarchy (lifted from the official documentation): Scala types hierarchy

Sours: https://newbedev.com/why-in-scala-long-cannot-in-initialized-to-null-whear-as-integer-can
Compile Scala Run using scala and java
/* __ *\ ** ________ ___ / / ___ Scala API ** ** / __/ __// _ | / / / _ | (c) , LAMP/EPFL ** ** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** ** /____/\___/_/ |_/____/_/ | | ** ** |/ ** \* */ // $Id: Math.scala Z dubochet $ package scala /** The object <code>Math</code> contains methods for performing basic numeric * operations such as the elementary exponential, logarithm, square root, and * trigonometric functions. */ objectMath{ /** The smallest possible value for <a href="Byte.html" target="_self">scala.Byte</a>. */ valMIN_BYTE = java.lang.Byte.MIN_VALUE /** The greatest possible value for <a href="Byte.html" target="_self">scala.Byte</a>. */ valMAX_BYTE = java.lang.Byte.MAX_VALUE /** The smallest possible value for <a href="Short.html" target="_self">scala.Short</a>. */ valMIN_SHORT = java.lang.Short.MIN_VALUE /** The greatest possible value for <a href="Short.html" target="_self">scala.Short</a>. */ valMAX_SHORT = java.lang.Short.MAX_VALUE /** The smallest possible value for <a href="Char.html" target="_self">scala.Char</a>. */ valMIN_CHAR = java.lang.Character.MIN_VALUE /** The greatest possible value for <a href="Char.html" target="_self">scala.Char</a>. */ valMAX_CHAR = java.lang.Character.MAX_VALUE /** The smallest possible value for <a href="Int.html" target="_self">scala.Int</a>. */ valMIN_INT = java.lang.Integer.MIN_VALUE /** The greatest possible value for <a href="Int.html" target="_self">scala.Int</a>. */ valMAX_INT = java.lang.Integer.MAX_VALUE /** The smallest possible value for <a href="Long.html" target="_self">scala.Long</a>. */ valMIN_LONG = java.lang.Long.MIN_VALUE /** The greatest possible value for <a href="Long.html" target="_self">scala.Long</a>. */ valMAX_LONG = java.lang.Long.MAX_VALUE /** The smallest possible value for <a href="Float.html" target="_self">scala.Float</a>. */ valMIN_FLOAT = -java.lang.Float.MAX_VALUE /** The smallest difference between two values of <a href="Float.html" target="_self">scala.Float</a>. */ valEPS_FLOAT = java.lang.Float.MIN_VALUE /** The greatest possible value for <a href="Float.html" target="_self">scala.Float</a>. */ valMAX_FLOAT = java.lang.Float.MAX_VALUE /** A value of type <a href="Float.html" target="_self">scala.Float</a> that represents no number. */ valNaN_FLOAT = java.lang.Float.NaN /** Negative infinity of type <a href="Float.html" target="_self">scala.Float</a>. */ valNEG_INF_FLOAT = java.lang.Float.NEGATIVE_INFINITY /** Positive infinity of type <a href="Float.html" target="_self">scala.Float</a>. */ valPOS_INF_FLOAT = java.lang.Float.POSITIVE_INFINITY /** The smallest possible value for <a href="Double.html" target="_self">scala.Double</a>. */ valMIN_DOUBLE = -java.lang.Double.MAX_VALUE /** The smallest difference between two values of <a href="Double.html" target="_self">scala.Double</a>. */ valEPS_DOUBLE = java.lang.Double.MIN_VALUE /** The greatest possible value for <a href="Double.html" target="_self">scala.Double</a>. */ valMAX_DOUBLE = java.lang.Double.MAX_VALUE /** A value of type <a href="Double.html" target="_self">scala.Double</a> that represents no number. */ valNaN_DOUBLE = java.lang.Double.NaN /** Negative infinity of type <a href="Double.html" target="_self">scala.Double</a>. */ valNEG_INF_DOUBLE = java.lang.Double.NEGATIVE_INFINITY /** Positive infinity of type <a href="Double.html" target="_self">scala.Double</a>. */ valPOS_INF_DOUBLE = java.lang.Double.POSITIVE_INFINITY /** The <code>double</code> value that is closer than any other to * <code>e</code>, the base of the natural logarithms. */ valE = java.lang.Math.E /** The <code>double</code> value that is closer than any other to * <code>pi</code>, the ratio of the circumference of a circle to its * diameter. */ valPi = java.lang.Math.PI /** Returns a <code>double</code> value with a positive sign, greater than * or equal to <code></code> and less than <code></code>. */ defrandom: Double = java.lang.Math.random() defsin(x: Double): Double = java.lang.Math.sin(x) defcos(x: Double): Double = java.lang.Math.cos(x) deftan(x: Double): Double = java.lang.Math.tan(x) defasin(x: Double): Double = java.lang.Math.asin(x) defacos(x: Double): Double = java.lang.Math.acos(x) defatan(x: Double): Double = java.lang.Math.atan(x) /** Converts an angle measured in degrees to an approximately equivalent * angle measured in radians. * * @param x an angle, in degrees * @return the measurement of the angle <code>x</code> in radians. */ deftoRadians(x: Double): Double = java.lang.Math.toRadians(x) /** Converts an angle measured in radians to an approximately equivalent * angle measured in degrees. * * @param x angle, in radians * @return the measurement of the angle <code>x</code> in degrees. */ deftoDegrees(x: Double): Double = java.lang.Math.toDegrees(x) /** Returns Euler's number <code>e</code> raised to the power of a * <code>double</code> value. * * @param x the exponent to raise <code>e</code> to. * @return the value <code>e<sup>a</sup></code>, where <code>e</code> * is the base of the natural logarithms. */ defexp(x: Double): Double = java.lang.Math.exp(x) deflog(x: Double): Double = java.lang.Math.log(x) defsqrt(x: Double): Double = java.lang.Math.sqrt(x) defIEEEremainder(x: Double, y: Double): Double = java.lang.Math.IEEEremainder(x, y) defceil(x: Double): Double = java.lang.Math.ceil(x) deffloor(x: Double): Double = java.lang.Math.floor(x) /** Returns the <code>double</code> value that is closest in value to the * argument and is equal to a mathematical integer. * * @param x a <code>double</code> value * @return the closest floating-point value to a that is equal to a * mathematical integer. */ defrint(x: Double): Double = java.lang.Math.rint(x) /** Converts rectangular coordinates <code>(x, y)</code> to polar * <code>(r, theta)</code>. * * @param x the ordinate coordinate * @param y the abscissa coordinate * @return the <em>theta</em> component of the point <code>(r, theta)</code> * in polar coordinates that corresponds to the point * <code>(x, y)</code> in Cartesian coordinates. */ defatan2(y: Double, x: Double): Double = java.lang.Math.atan2(y, x) /** Returns the value of the first argument raised to the power of the * second argument. * * @param x the base. * @param y the exponent. * @return the value <code>x<sup>y</sup></code>. */ defpow(x: Double, y: Double): Double = java.lang.Math.pow(x, y) /** Returns the closest <code>long</code> to the argument. * * @param x a floating-point value to be rounded to a <code>long</code>. * @return the value of the argument rounded to the nearest * <code>long</code> value. */ defround(x: Float): Int = java.lang.Math.round(x) defround(x: Double): Long = java.lang.Math.round(x) defabs(x: Int): Int = java.lang.Math.abs(x) defabs(x: Long): Long = java.lang.Math.abs(x) defabs(x: Float): Float = java.lang.Math.abs(x) defabs(x: Double): Double = java.lang.Math.abs(x) defmax(x: Int, y: Int): Int = java.lang.Math.max(x, y) defmax(x: Long, y: Long): Long = java.lang.Math.max(x, y) defmax(x: Float, y: Float): Float = java.lang.Math.max(x, y) defmax(x: Double, y: Double): Double = java.lang.Math.max(x, y) defmin(x: Int, y: Int): Int = java.lang.Math.min(x, y) defmin(x: Long, y: Long): Long = java.lang.Math.min(x, y) defmin(x: Float, y: Float): Float = java.lang.Math.min(x, y) defmin(x: Double, y: Double): Double = java.lang.Math.min(x, y) defsignum(x: Double): Double = xmatch { case0 => 0caseyify < 0 => caseyify > 0 => } defsignum(x: Float): Float = xmatch { case0f => 0fcaseyify < 0f => fcaseyify > 0f => f } defsignum(x: Long): Long = xmatch { case0l => 0lcaseyify < 0l => -1lcaseyify > 0l => 1l } defsignum(x: Int): Int = xmatch { case0 => 0caseyify < 0 => -1caseyify > 0 => 1} // from Java // def log10(x: Double): Double = java.lang.Math.log10(x) // def cbrt(x: Double): Double = java.lang.Math.cbrt(x) // // def ulp(x: Double): Double = java.lang.Math.ulp(x) // def ulp(x: Float): Float = java.lang.Math.ulp(x) // def sinh(x: Double): Double = java.lang.Math.sinh(x) // def cosh(x: Double): Double = java.lang.Math.cosh(x) // def tanh(x: Double):Double = java.lang.Math.tanh(x) // def hypot(x: Double, y: Double): Double = java.lang.Math.hypot(x, y) // def expm1(x: Double): Double = java.lang.Math.expm1(x) // def log1p(x: Double): Double = java.lang.Math.log1p(x) }
Sours: https://www.scala-sbt.org/sxr/samples/library/scala/Math.scala.html

Now discussing:

Databaseline

There are a few subtle changes between Scala and / when it comes to conversions between Java and Scala types that you may not be aware of: nullable boxed primitives, such as numbers.

Comparison

When dealing with Avro records in data pipelines in Scala (e.g. with Spotify’s open-source API for Apache Beam: Scio), you often need to convert back and forth between Java and Scala types, most commonly when reading from or writing to Avro. The interoperability between Java and Scala is fairly seamless thanks to the JVM. There are, however, differences from Scala to that may be tricky to spot if you’re not careful because it affects boxed primitive types, such as nullable boolean and numeric types.

If you want to run the following code yourself, you can either re-use the minimal sbt-based Scala REPL, or you can use Scastie in the convenience of your web browser.

Let’s now run some simple operations with these values and case classes in different Scala versions:

Snippet()(.8)(M5)
NPENPENPE
NPENPENPE
NPENPENPE
NPENPENPE
NPE
NPE
NPE
NPENPENPE
NPE
NPE
NPE
NPE
n/an/an/a

The wildcard ‘’ is used to indicate the same expression is used for all five values , , , , and . NPE stands for . If it says ‘n/a’ it means it is not applicable because the code fails to compile due to type mismatches.

As you can see, the implicit conversions from Java types to Scala’s cause problems. Whereas in the behaviour was to throw NPEs when converting boxed values from Java to Scala, in and onwards some of these are converted to a default value (false for booleans and zero for numbers). You can easily check that the same table holds for other number types: , , , and so on.

Please note that a ‘instance’ of when passed to actually becomes even though gives an NPE.

Safe Conversions

In Scala , the following function would have allowed you to capture issues with nullable Java types and wrap these in an :

Because the argument is called by name rather than value (indicated by in the parameter list), it’s not evaluated when it’s handed to the function for further processing, but rather when it’s needed within the function itself. This means always ends up inside the monad, where it’s safe, even in the event of exceptions.

With it, you could have executed and it would have given you . In Scala and that does not work because of the implicit conversion needed to go from to Scala’s . To ensure type correctness, in is (as evidenced from the type annotation on the ), which means the argument to the function is automatically converted from to . With the table above we can see that the argument passed to the function is essentially , which is . The lack of an NPE thrown means it ends up in the first case and thus becomes .

Instead, we need a different way to handle this in Scala and I shall present three equivalent functions:

The second argument list, which reads , states that there has to be an implicit conversion in scope from to the return type . We could write this with a view bound, in which case the signature is as follows: . View bounds have been deprecated though.

A battery of ScalaTest unit tests is easily implemented:

Note that I have assumed a single method named rather than the three alternatives. So, which alternative should you pick?

Benchmarks

The third option has consistently proven to be faster with micro-benchmarks and actual production code. It also has a smaller memory footprint. The reason is obvious: has no unnecessary boxing and unboxing with the monad. That’s why I prefer that alternative, especially when running this at scale. Of course, you can rely on explicit checks and explicit type conversions, which would be even faster. However, you often want a generic method you can rely on in different situations.

If you want to do a poor person’s benchmark on your machine, here’s some code to get you started (without the need to play with JMH):

Sours: https://databaseline.tech/differences-in-conversions-of-java-numbers-in-scala/


1319 1320 1321 1322 1323