What are modifiers like Java primitive data?

Well, I have been programming in Java for most of the three years, and I consider myself very experienced. However, while looking at the Java SE source code, I came across something that I did not expect:

in class Double :

 public static final double MIN_NORMAL = 0x1.0p-1022; // 2.2250738585072014E-308 public static final double MIN_VALUE = 0x0.0000000000001P-1022; // 4.9e-324 

I did not expect this and cannot understand what this means. If you do not know, I mean p and p , which are after these numbers, before the subtraction operator. I know that you can use suffixes to make the number be Double , long , float , etc., but I never met p or p . I checked the Java API , but it does not mention it. Is there a complete list of Java literal modifiers somewhere? Does anyone know them all?

For reference, the following are the ones I used or met, with those whose goals elude me in bold with question marks ( # represents any arbitrary number within the appropriate range):

suffixes:

  • # = 32-bit int
  • #L = 64-bit integer long
  • #L = another 64-bit integer l ?
  • #f = 32-bit float
  • #f = another 32-bit float ?
  • #d = 64-bit Double Float
  • #d = another 64-bit floating point Double ?
  • #e# = scientific notation
  • #e# = other scientific notation
  • #p =?
  • #p =?
  • More?

Prefixes:

  • 0b# = binary (base 2) literal
  • 0b# = another binary (base 2) literal?
  • 0# = octal (base 8) literal
  • # = decimal (base 10) literal
  • 0x# = hexadecimal (base 16) literal
  • 0x# = another hexadecimal (base 16) literal?
  • More?

Other ( do suffixes or prefixes exist for them? ):

  • (byte)# = 8-bit byte integer
  • (short)# = 16-bit integer short
  • (char)# - 32-bit char character
+6
source share
3 answers

P is an exponent. It does not matter if it is capital or not.

According to the Javadoc for toHextString (which, as we know, is used since it starts with 0x :

public static String toHexString(double d) Returns the hexadecimal string representation of the double argument. All characters mentioned below are ASCII characters. If the argument is NaN, the result is the string "NaN". Otherwise, the result is a string that represents the sign and value of the argument. If the sign is negative, the first character of the result is '-' ('\ u002D'); if the sign is positive, the sign does not appear as a result. As for the value of m:

  • If m is infinity, it is represented by the line "Infinity"; thus, positive infinity gives the result "Infinity" and negative infinity gives the result "-Infinity".

  • If m is zero, it is represented by the string "0x0.0p0"; thus, a negative zero gives the result "-0x0.0p0", and a positive zero gives the result "0x0.0p0".

  • If m is a double value with a normalized representation, substrings are used to represent strong and exponential fields. Significance is represented by the characters "0x1". followed by a lowercase hexadecimal representation of the rest of the value as a fractional part. Trailing zeros in the hexadecimal representation are deleted if all digits are not equal to zero, in which case one zero is used. Next, the exponent is represented by "p", followed by the decimal string of the unbiased exponent , as if it were called by calling Integer.toString by exponent.

  • If m is a double value with a subnormal representation, the value and is denoted by the characters "0x0". followed by a hexadecimal representation of the rest of the value as a fraction. Fixed zero zeros in hexadecimal representation. Further, the indicator is represented by "p-1022". Please note that in the subnormal value there must be at least one nonzero digit.

According to JLS , the following grammar fragments are accepted:

3.10.1. Integer Literals

IntegerTypeSuffix :

  • l
  • L

OctalNumeral:

  • 0 OctalDigits
  • 0 Emphasizes OctalDigits

HexNumeral:

  • 0 x HexDigits
  • 0 X HexDigits

BinaryNumeral:

  • 0 b BinaryDigits
  • 0 B BinaryDigits

3.10.2. Floating-Point Literals

ExponentIndicator: one of

  • e
  • E

FloatTypeSuffix: one of

  • F
  • F
  • d
  • D

HexSignificand:

  • Hexnumeral
  • HexNumeral.
  • 0 x HexDigitsopt. Hex_number
  • 0 X HexDigitsopt. Hex_number

BinaryExponentIndicator: one of

  • p
  • P

No other literals of the same character are specified for this purpose.

+7
source

All legal ways to declare a literal are defined in JLS .

  • p or p is the binary exponent of a number.
  • l or l defines a long .
  • f or f defines a float .
  • d or d defines a double .
  • 0B or 0B defines a binary literal.
  • 0x or 0x defines a hexadecimal literal.
  • e or e also a measure, but since e is a valid hexadecimal character, p is also used.
+3
source

P or P is a BinaryExponentIndicator . See Java Language Specification.

See http://docs.oracle.com/javase/specs/jls/se5.0/html/lexical.html#3.10.2

0
source

Source: https://habr.com/ru/post/924221/


All Articles