Re: D: Convert/parse uint integer to string. (@nogc)

2023-11-30 Thread Siarhei Siamashka via Digitalmars-d-learn
On Friday, 24 November 2023 at 09:35:00 UTC, BoQsc wrote: I tried to look into https://dlang.org/phobos/std_conv.html Most of the functions inside `std.conv` seem to be dependant on [Garbage Collection](https://dlang.org/spec/garbage.html). And I couldn't find a straightforward way to

Re: D: Convert/parse uint integer to string. (@nogc)

2023-11-30 Thread kdevel via Digitalmars-d-learn
On Tuesday, 28 November 2023 at 09:43:47 UTC, Dom DiSc wrote: On Tuesday, 28 November 2023 at 08:51:21 UTC, Mark Davies wrote: On Friday, 24 November 2023 at 09:35:00 UTC, BoQsc wrote: ``` import std.stdio; char[10] longToString(long n) @nogc ``` For a 'long' 10 characters is likely to be

Re: D: Convert/parse uint integer to string. (@nogc)

2023-11-30 Thread kdevel via Digitalmars-d-learn
On Friday, 24 November 2023 at 13:05:30 UTC, Ferhat Kurtulmuş wrote: [...] ``` import core.stdc.stdio : sprintf; import core.stdc.math : log10; import std.exception : assumeUnique; import std.stdio : writeln; size_t nod(int num){ return cast(size_t)((num==0)?1:log10(num)+1); }

Re: D: Convert/parse uint integer to string. (@nogc)

2023-11-28 Thread Julian Fondren via Digitalmars-d-learn
On Tuesday, 28 November 2023 at 08:51:21 UTC, Mark Davies wrote: I did it this way ... You always print the full array of bytes this way. Output piped to `od -c` is ``` 000 1 2 3 4 5 377 377 377 377 377 \n - 1 2 3 4 020 5 377 377 377 377 \n ``` Those 377s

Re: D: Convert/parse uint integer to string. (@nogc)

2023-11-28 Thread Dom DiSc via Digitalmars-d-learn
On Tuesday, 28 November 2023 at 08:51:21 UTC, Mark Davies wrote: On Friday, 24 November 2023 at 09:35:00 UTC, BoQsc wrote: ``` import std.stdio; char[10] longToString(long n) @nogc ``` For a 'long' 10 characters is likely to be not enough (long max is 9223372036854775808 which has 19 chars,

Re: D: Convert/parse uint integer to string. (@nogc)

2023-11-28 Thread Mark Davies via Digitalmars-d-learn
On Friday, 24 November 2023 at 09:35:00 UTC, BoQsc wrote: I tried to look into https://dlang.org/phobos/std_conv.html Most of the functions inside `std.conv` seem to be dependant on [Garbage Collection](https://dlang.org/spec/garbage.html). And I couldn't find a straightforward way to

Re: D: Convert/parse uint integer to string. (@nogc)

2023-11-27 Thread Nick Treleaven via Digitalmars-d-learn
On Monday, 27 November 2023 at 12:34:30 UTC, Nick Treleaven wrote: On Friday, 24 November 2023 at 09:35:00 UTC, BoQsc wrote: You can use std.conv.toChars: ```d void main() @nogc { int n = 515; import std.conv; char[10] s = 0; auto r = n.toChars(); assert(r.length <

Re: D: Convert/parse uint integer to string. (@nogc)

2023-11-27 Thread Nick Treleaven via Digitalmars-d-learn
On Friday, 24 November 2023 at 09:35:00 UTC, BoQsc wrote: I tried to look into https://dlang.org/phobos/std_conv.html Most of the functions inside `std.conv` seem to be dependant on [Garbage Collection](https://dlang.org/spec/garbage.html). And I couldn't find a straightforward way to

Re: D: Convert/parse uint integer to string. (@nogc)

2023-11-24 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Friday, 24 November 2023 at 09:35:00 UTC, BoQsc wrote: I tried to look into https://dlang.org/phobos/std_conv.html Most of the functions inside `std.conv` seem to be dependant on [Garbage Collection](https://dlang.org/spec/garbage.html). And I couldn't find a straightforward way to

D: Convert/parse uint integer to string. (@nogc)

2023-11-24 Thread BoQsc via Digitalmars-d-learn
I tried to look into https://dlang.org/phobos/std_conv.html Most of the functions inside `std.conv` seem to be dependant on [Garbage Collection](https://dlang.org/spec/garbage.html). And I couldn't find a straightforward way to produce a `string` value out of `uint` value. How to convert