www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Cent/ucent why should we implement?

reply Richard (Rikki) Andrew Cattermole <richard cattermole.co.nz> writes:
Another monthly meeting has occurred, this time one of the things 
I presented was for my PR to implement cent/ucent.

The reception was not the warmest, with questioning on why to do 
it.

Does anyone have reasons for they may want it in language?

Mine:

- Some basic arithmetic can only be described using double the 
word-size type, like with overflow, without using intrinsics.
- Atomics use it for cas
- SIMD types go above word-size.

Has anyone got any other reasons?

https://github.com/dlang/dmd/pull/23575
Aug 14
next sibling parent kinke <noone nowhere.com> writes:
On Friday, 14 August 2026 at 16:27:50 UTC, Richard (Rikki) Andrew 
Cattermole wrote:
 Does anyone have reasons for they may want it in language?
Emphasis on 'in the language', as opposed to a library type like (existing) `std.int128.Int128`, or its `core.int128.Cent` low-level foundation.
Aug 14
prev sibling next sibling parent Mindy Batek (0xEAB) <desisma heidel.beer> writes:
On Friday, 14 August 2026 at 16:27:50 UTC, Richard (Rikki) Andrew 
Cattermole wrote:
 Has anyone got any other reasons?
Straightforward C bindings and importC.
Aug 14
prev sibling next sibling parent monkyyy <crazymonkyyy gmail.com> writes:
On Friday, 14 August 2026 at 16:27:50 UTC, Richard (Rikki) Andrew 
Cattermole wrote:
 my PR to implement cent
Lincoln was a very important president and it will help D become the future of banking along with all the barrow checking work
Aug 14
prev sibling next sibling parent Johan <j j.nl> writes:
On Friday, 14 August 2026 at 16:27:50 UTC, Richard (Rikki) Andrew 
Cattermole wrote:
 Another monthly meeting has occurred, this time one of the 
 things I presented was for my PR to implement cent/ucent.

 The reception was not the warmest, with questioning on why to 
 do it.

 Does anyone have reasons for they may want it in language?
Perhaps Amaury can chime in. I remember he improved a few LLVM 128bit codegen things, clearly because he needed it. (cryptography/hashing, I suppose) cheers, Johan
Aug 14
prev sibling next sibling parent Doigt <labog outlook.com> writes:
On Friday, 14 August 2026 at 16:27:50 UTC, Richard (Rikki) Andrew 
Cattermole wrote:
 Another monthly meeting has occurred, this time one of the 
 things I presented was for my PR to implement cent/ucent.

 The reception was not the warmest, with questioning on why to 
 do it.

 Does anyone have reasons for they may want it in language?

 Mine:

 - Some basic arithmetic can only be described using double the 
 word-size type, like with overflow, without using intrinsics.
 - Atomics use it for cas
 - SIMD types go above word-size.

 Has anyone got any other reasons?

 https://github.com/dlang/dmd/pull/23575
While it is a superficial reason, I believe it must be stated anyway: because it's cool and D is a cool language that always has the coolest features. It may sound silly, but being cool is part of D's core appeal as a language. With that said, I hope you had a good laugh.
Aug 30
prev sibling next sibling parent Dukc <ajieskola gmail.com> writes:
On Friday, 14 August 2026 at 16:27:50 UTC, Richard (Rikki) Andrew 
Cattermole wrote:
 Another monthly meeting has occurred, this time one of the 
 things I presented was for my PR to implement cent/ucent.

 The reception was not the warmest, with questioning on why to 
 do it.

 Does anyone have reasons for they may want it in language?
It isn't really any added language complexity from design or user perspective, because all it's rules are reused from `byte`/`short`/`int`/`long`. We need all the language rules for built-in integers, `cent` or no `cent`, so we might as well have it. It probably does make sense to _internally_ implement it in DRuntime so that the user can swap or leave out its implementation without using a custom compiler, but having a language keyword to actually use that implementation is only consistent with how other integer types are used, especially as we already have a keyword pair reserved for that.
Aug 31
prev sibling parent reply Luna <luna foxgirls.gay> writes:
On Friday, 14 August 2026 at 16:27:50 UTC, Richard (Rikki) Andrew 
Cattermole wrote:
 Another monthly meeting has occurred, this time one of the 
 things I presented was for my PR to implement cent/ucent.

 The reception was not the warmest, with questioning on why to 
 do it.

 Does anyone have reasons for they may want it in language?

 Mine:

 - Some basic arithmetic can only be described using double the 
 word-size type, like with overflow, without using intrinsics.
 - Atomics use it for cas
 - SIMD types go above word-size.

 Has anyone got any other reasons?

 https://github.com/dlang/dmd/pull/23575
Makes writing float/double parsers far easier given then you can assume that the compiler implements 128 bit values correctly
Sep 05
parent reply Guillaume Piolat <first.name gmail.com> writes:
On Sunday, 6 September 2026 at 02:03:09 UTC, Luna wrote:
 Makes writing float/double parsers far easier given then you 
 can assume that the compiler implements 128 bit values correctly
Clock conversion in video needs 64-bit * 64-bit => 128-bit result
Sep 06
parent reply Dom Disc <dominikus scherkl.de> writes:
On Sunday, 6 September 2026 at 10:33:15 UTC, Guillaume Piolat 
wrote:
 On Sunday, 6 September 2026 at 02:03:09 UTC, Luna wrote:
 Makes writing float/double parsers far easier given then you 
 can assume that the compiler implements 128 bit values 
 correctly
Clock conversion in video needs 64-bit * 64-bit => 128-bit result
This is already available in the registers. You just need to copy it out: ```d ulong[2] mul128(const ulong u, const ulong v) safe pure nogc nothrow { ulong[2] r; if(!u || !v) return r; version(D_InlineAsm_X86) { asm trusted pure nogc nothrow { mov R8, r.ptr; mov R9, v; mov RAX, u; mul R9; mov [R8], RAX; add R8, 8; mov [R8], RDX; } } else // without asm we have no access to the high bits of the result { // this is awfully slow (4 multiplications, 6 additions and 8 shifts) // but during CTFE this will only increase the compilation time // so maybe acceptable enum m = uint.max; ulong t; t = (u & m)*(v & m); r[0] = t & m; t = (u>>32)*(v & m) + (t>>32); r[1] = t>>32; t = (u & m)*(v>>32) + (t & m); r[0] += (t<<32); r[1] += (u>>32)*(v>>32) + (t>>32); } return r; // r[1] contains the high bits of the product, r[0] the low bits (big endian) } ``` But at least, this function should be in Phobos.
Sep 07
parent kinke <noone nowhere.com> writes:
On Monday, 7 September 2026 at 10:38:42 UTC, Dom Disc wrote:
 But at least, this function should be in Phobos.
In druntime since v2.112: https://dlang.org/changelog/2.112.0.html#druntime.int128, https://dlang.org/phobos/core_int128.html#.mul.2
Sep 07