An input string to convert to a Float16?
instance.
init(_:)
Availability
- iOS 14.0+
- iPadOS 14.0+
- macOS 11.0+
- Mac Catalyst 14.5+
- tvOS 14.0+
- watchOS 7.0+
- Xcode 12.0+
Technology
- Swift Standard Library Swift標準ライブラリ
Declaration 宣言
init?<S>(_ text: S) where S : StringProtocol
Parameters パラメータ
text
Discussion 解説
The string passed as text
can represent a real number in decimal or hexadecimal format or can be in a special format representing infinity or NaN (“not a number”). If text
is not in a recognized format, the optional initializer will fail and return nil
.
The text
string consists of an optional plus or minus sign character (+
or -
) followed by one of the following:
-
A decimal string contains a significand consisting of one or more decimal digits that may include a decimal point:
A decimal string may also include an exponent following the significand, indicating the power of 10 by which the significand should be multiplied. If included, the exponent is separated by a single character,
e
orE
, and consists of an optional plus or minus sign character and a sequence of decimal digits. もし含むならば、指数は1つの文字e
もしくはE
によって区切られます、そして随意のプラスまたはマイナス符号文字と一連の10進の桁から成り立ちます。 -
A hexadecimal string contains a significand consisting of
0X
or0x
followed by one or more hexadecimal digits that may include a decimal point.A hexadecimal string may also include an exponent indicating the power of 2 by which the significand should be multiplied. If included, the exponent is separated by a single character,
p
orP
, and consists of an optional plus or minus sign character and a sequence of decimal digits. もし含むならば、指数は1つの文字p
もしくはP
によって区切られます、そして随意のプラスまたはマイナス符号文字と一連の10進の桁から成り立ちます。 -
The input strings
"inf"
or"infinity"
(case insensitive) are converted to an infinite result: -
An input string of
"nan"
(case insensitive) is converted into a NaN value:A NaN string may also include a payload in parentheses following the
"nan"
keyword. The payload consists of a sequence of decimal digits, or the characters0X
or0x
followed by a sequence of hexadecimal digits. If the payload contains any other characters, it is ignored. If the value of the payload is larger than can be stored as the payload of aFloat16
, the least significant bits are used. ペイロードは、一連の10進の桁、または文字.nan 0X
か0x
に続く一連の16進の桁から成ります。ペイロードが何か他の文字を含むならば、それは無視されます。ペイロードの値がFloat16
のペイロードとして格納可能であるより大きいならば、最下位ビットが使われます。.nan
A string in any other format than those described above or containing additional characters results in a nil
value. For example, the following conversions result in nil
:
A decimal or hexadecimal string is converted to a Float16
instance using the IEEE 754 roundTiesToEven (default) rounding attribute. Values with absolute value smaller than Float16
are rounded to plus or minus zero. Values with absolute value larger than Float16
are rounded to plus or minus infinity.
Note 注意
Prior to Swift 5.4, a decimal or hexadecimal input string whose value was too large to represent as a finite Float16
instance returned nil
instead of Float16
.