diff options
author | Iain Buclaw <ibuclaw@gdcproject.org> | 2023-10-15 12:05:10 +0200 |
---|---|---|
committer | Iain Buclaw <ibuclaw@gdcproject.org> | 2023-10-15 12:12:49 +0200 |
commit | ac908237bd551fb55f2f82736cb37038e9b91459 (patch) | |
tree | 1d9efb93ef9af63ec88bf85130e16116249bb192 /libphobos/src/std | |
parent | 648d30716d0cdb5dec96b2da9ed23328bad7cb9f (diff) | |
download | gcc-ac908237bd551fb55f2f82736cb37038e9b91459.zip gcc-ac908237bd551fb55f2f82736cb37038e9b91459.tar.gz gcc-ac908237bd551fb55f2f82736cb37038e9b91459.tar.bz2 |
d: Merge upstream dmd, druntime f9efc98fd7, phobos a3f22129d.
D front-end changes:
- Import dmd v2.105.2.
- A function with enum storage class is now deprecated.
- Global variables can now be initialized with Associative
Arrays.
- Improvements for the C++ header generation of static variables
used in a default argument context.
D runtime changes:
- Import druntime v2.105.2.
- The `core.memory.GC' functions `GC.enable', `GC.disable',
`GC.collect', and `GC.minimize' `have been marked `@safe'.
Phobos changes:
- Import phobos v2.105.2.
gcc/d/ChangeLog:
* dmd/MERGE: Merge upstream dmd f9efc98fd7.
* dmd/VERSION: Bump version to v2.105.2.
* d-builtins.cc (build_frontend_type): Update for new front-end
interface.
* d-diagnostic.cc (verrorReport): Don't emit tips when error gagging
is turned on.
* d-lang.cc (d_handle_option): Remove obsolete parameter.
(d_post_options): Likewise.
(d_read_ddoc_files): New function.
(d_generate_ddoc_file): New function.
(d_parse_file): Update for new front-end interface.
* expr.cc (ExprVisitor::visit (AssocArrayLiteralExp *)): Check for new
front-end lowering of static associative arrays.
libphobos/ChangeLog:
* libdruntime/MERGE: Merge upstream druntime f9efc98fd7.
* libdruntime/Makefile.am (DRUNTIME_DSOURCES): Add
core/internal/newaa.d.
* libdruntime/Makefile.in: Regenerate.
* src/MERGE: Merge upstream phobos a3f22129d.
* testsuite/libphobos.hash/test_hash.d: Update test.
* testsuite/libphobos.phobos/phobos.exp: Add compiler flags
-Wno-deprecated.
* testsuite/libphobos.phobos_shared/phobos_shared.exp: Likewise.
gcc/testsuite/ChangeLog:
* lib/gdc-utils.exp (gdc-convert-args): Handle new compiler options.
Diffstat (limited to 'libphobos/src/std')
-rw-r--r-- | libphobos/src/std/int128.d | 46 | ||||
-rw-r--r-- | libphobos/src/std/string.d | 1 |
2 files changed, 46 insertions, 1 deletions
diff --git a/libphobos/src/std/int128.d b/libphobos/src/std/int128.d index b20fa1f..9289544 100644 --- a/libphobos/src/std/int128.d +++ b/libphobos/src/std/int128.d @@ -147,7 +147,7 @@ public struct Int128 /** Support casting to a bool * Params: T = bool - * Returns: boolean result + * Returns: true if value is not zero */ bool opCast(T : bool)() const { @@ -155,6 +155,50 @@ public struct Int128 } } // @safe pure nothrow @nogc + /** Support casting to an integral type + * Params: T = integral type + * Returns: low bits of value reinterpreted as T + */ + T opCast(T : long)() const + if (is(byte : T)) + { + return cast(T) this.data.lo; + } + + /// + @safe unittest + { + const Int128 a = Int128(0xffff_ffff_ffff_ffffL, 0x0123_4567_89ab_cdefL); + assert(cast(long) a == 0x0123_4567_89ab_cdefL); + assert(cast(int) a == 0x89ab_cdef); + assert(cast(byte) a == cast(byte) 0xef); + } + + /** Support casting to floating point type + * Params: T = floating point type + * Returns: value cast to floating point with environment-dependent + * rounding if the value is not exactly representable + */ + T opCast(T : real)() const + { + import core.math : ldexp; + if (cast(long) this.data.hi >= 0) + return ldexp(cast(T) this.data.hi, 64) + this.data.lo; + else + { + const absData = neg(this.data); + return -ldexp(cast(T) absData.hi, 64) - absData.lo; + } + } + + /// + @safe unittest + { + const Int128 a = Int128(-1L << 60); + assert(cast(double) a == -(2.0 ^^ 60)); + assert(cast(double) (a * a) == 2.0 ^^ 120); + } + /** Support binary arithmetic operators + - * / % & | ^ << >> >>> * Params: * op = one of the arithmetic binary operators diff --git a/libphobos/src/std/string.d b/libphobos/src/std/string.d index b1063ee..ca14c23 100644 --- a/libphobos/src/std/string.d +++ b/libphobos/src/std/string.d @@ -3815,6 +3815,7 @@ unittest assert(chomp(" hello world \n\n" ~ [lineSep]) == " hello world \n\n"); assert(chomp(" hello world \n\n" ~ [paraSep]) == " hello world \n\n"); assert(chomp(" hello world \n\n" ~ [ nelSep]) == " hello world \n\n"); + assert(chomp(" hello world ") == " hello world "); assert(chomp(" hello world") == " hello world"); assert(chomp("") == ""); |