Re: bigint and pow

2022-10-02 Thread rassoc via Digitalmars-d-learn
On 10/2/22 09:24, Fausto via Digitalmars-d-learn wrote: Thanks a lot. I am to used to C and, more important, I didn't think to look for also another operator for the power function :) Oh, and I forgot to mention that this is doing what you probably asked for originally: ```d import std;

Re: bigint and pow

2022-10-02 Thread rassoc via Digitalmars-d-learn
On 10/2/22 09:24, Fausto via Digitalmars-d-learn wrote: Thanks a lot. I am to used to C and, more important, I didn't think to look for also another operator for the power function :) D does have pow and many other useful math functions [1], it's just not defined for BitInts. Oh, and

Re: bigint and pow

2022-10-02 Thread Fausto via Digitalmars-d-learn
On Sunday, 2 October 2022 at 02:02:37 UTC, rassoc wrote: On 10/2/22 00:04, Fausto via Digitalmars-d-learn wrote: Hello, I am trying to use pow with an integer argument, but I cannot have a bigint result, for example, ```pow(10,72)```. Do I have to write my pow function or is there a native

Re: bigint and pow

2022-10-01 Thread rassoc via Digitalmars-d-learn
On 10/2/22 00:04, Fausto via Digitalmars-d-learn wrote: Hello, I am trying to use pow with an integer argument, but I cannot have a bigint result, for example, ```pow(10,72)```. Do I have to write my pow function or is there a native solution? thanks, Fausto In contrast to certain

bigint and pow

2022-10-01 Thread Fausto via Digitalmars-d-learn
Hello, I am trying to use pow with an integer argument, but I cannot have a bigint result, for example, ```pow(10,72)```. Do I have to write my pow function or is there a native solution? thanks, Fausto

Re: sha256 to bigint

2022-06-11 Thread Paul Backus via Digitalmars-d-learn
On Saturday, 11 June 2022 at 13:09:44 UTC, vc wrote: Hello, is there any way to represnts a sha256 hash like 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824 in BigInt ? I've try so far auto t = BigInt("2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938

Re: sha256 to bigint

2022-06-11 Thread vc via Digitalmars-d-learn
On Saturday, 11 June 2022 at 13:09:44 UTC, vc wrote: Hello, is there any way to represnts a sha256 hash like 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824 in BigInt ? I've try so far auto t = BigInt("2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938

sha256 to bigint

2022-06-11 Thread vc via Digitalmars-d-learn
Hello, is there any way to represnts a sha256 hash like 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824 in BigInt ? I've try so far auto t = BigInt("2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824") and it gives me invalid digit

Re: Optimizing a bigint fibonacci

2017-12-06 Thread Biotronic via Digitalmars-d-learn
On Wednesday, 6 December 2017 at 10:16:16 UTC, helxi wrote: On Wednesday, 6 December 2017 at 10:00:48 UTC, Biotronic wrote: AliasSeq!(a, b) = tuple( a * (2*b - a), a*a + b*b); [...] Nice. But why the AliasSeq? Just playing around a bit. The alternative is to

Re: Optimizing a bigint fibonacci

2017-12-06 Thread codephantom via Digitalmars-d-learn
On Wednesday, 6 December 2017 at 09:59:12 UTC, codephantom wrote: On Wednesday, 6 December 2017 at 09:12:08 UTC, helxi wrote: This is question not directly related to language concepts, it's got more to do with the application. I would appreciate if anyone would point to me how I could

Re: Optimizing a bigint fibonacci

2017-12-06 Thread helxi via Digitalmars-d-learn
On Wednesday, 6 December 2017 at 10:00:48 UTC, Biotronic wrote: On Wednesday, 6 December 2017 at 09:12:08 UTC, helxi wrote: [...] Here's my version:, based on fast squaring: auto fib(ulong n) { import std.bigint : BigInt; import std.meta : AliasSeq; import std.typecons : tuple

Re: Optimizing a bigint fibonacci

2017-12-06 Thread Biotronic via Digitalmars-d-learn
: auto fib(ulong n) { import std.bigint : BigInt; import std.meta : AliasSeq; import std.typecons : tuple; BigInt a = 0; BigInt b = 1; auto bit = 63; while (bit > 0) { AliasSeq!(a, b) = tuple( a * (2*b - a), a*a + b*b); if

Re: Optimizing a bigint fibonacci

2017-12-06 Thread codephantom via Digitalmars-d-learn
On Wednesday, 6 December 2017 at 09:12:08 UTC, helxi wrote: This is question not directly related to language concepts, it's got more to do with the application. I would appreciate if anyone would point to me how I could optimize this bit of code Compile it with ldc ;-)

Re: Optimizing a bigint fibonacci

2017-12-06 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, December 06, 2017 09:12:08 helxi via Digitalmars-d-learn wrote: > void main() > { > import std.stdio, std.datetime; > > auto t0 = Clock.currTime; > writeln(fib(100_000)); > writeln(Clock.currTime - t0); > } On a complete sidenote, if you want to correctly time stuff, you

Optimizing a bigint fibonacci

2017-12-06 Thread helxi via Digitalmars-d-learn
This is question not directly related to language concepts, it's got more to do with the application. I would appreciate if anyone would point to me how I could optimize this bit of code auto fib(const int n) { import std.bigint; if (n == 0) return BigInt(0

Re: BigInt foreach loop

2017-08-09 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/9/17 9:08 PM, Steven Schveighoffer wrote: Right, but this is not a limitation of the API, just the implementation. It could be improved. https://issues.dlang.org/show_bug.cgi?id=17736 Based on H.S. Teoh's comment in the bug report, this actually is invalid. That's a tough requirement.

Re: BigInt foreach loop

2017-08-09 Thread Steven Schveighoffer via Digitalmars-d-learn
;key < limit;++key) { // use x } That's enough to know that the foreach loop does not reuse the space for the iteration variable. That was what I cared about. Note that using BigInt as iteration variable will probably cause a BigInt allocation per iteration, because operations on Big

Re: BigInt foreach loop

2017-08-09 Thread H. S. Teoh via Digitalmars-d-learn
x = key;key < limit;++key) > > { > > // use x > > } > > That's enough to know that the foreach loop does not reuse the space > for the iteration variable. That was what I cared about. Note that using BigInt as iteration variable will probably cause a BigInt allo

Re: BigInt foreach loop

2017-08-09 Thread Q. Schroll via Digitalmars-d-learn
On Friday, 4 August 2017 at 16:40:08 UTC, Stefan Koch wrote: [..] foreach(x;A .. B) it's lowerd to auto limit = B; auto key = A; for(auto x = key;key < limit;++key) { // use x } That's enough to know that the foreach loop does not reuse the space for the iteration variable. That was what I

Re: BigInt foreach loop

2017-08-04 Thread Stefan Koch via Digitalmars-d-learn
ult is the same. > as incrementing is a costly operation? Here is increment in bigint: https://github.com/dlang/phobos/blob/master/std/bigint.d#L563 And addOrSubInt: https://github.com/dlang/phobos/blob/master/std/internal/math/biguintcore.d#L508 I think there is room for impro

Re: BigInt foreach loop

2017-08-04 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/4/17 8:49 AM, Q. Schroll wrote: One can do BigInt n = returnsBigInt(); foreach (i; BigInt(0) .. n) { .. } How is this implemented? The code for BigInt is very large and I didn't find it. And is it more efficient than for (BigInt i = 0; i < n; ++i) { .. } Any foreach ra

Re: BigInt foreach loop

2017-08-04 Thread Stefan Koch via Digitalmars-d-learn
On Friday, 4 August 2017 at 12:49:30 UTC, Q. Schroll wrote: One can do BigInt n = returnsBigInt(); foreach (i; BigInt(0) .. n) { .. } How is this implemented? The code for BigInt is very large and I didn't find it. And is it more efficient than for (BigInt i = 0; i < n;

BigInt foreach loop

2017-08-04 Thread Q. Schroll via Digitalmars-d-learn
One can do BigInt n = returnsBigInt(); foreach (i; BigInt(0) .. n) { .. } How is this implemented? The code for BigInt is very large and I didn't find it. And is it more efficient than for (BigInt i = 0; i < n; ++i) { .. } as incrementing is a costly operation?

Re: Is DMD breaking BigInt?

2017-04-08 Thread Meta via Digitalmars-d-learn
On Saturday, 8 April 2017 at 12:14:31 UTC, Russel Winder wrote: On Fri, 2017-04-07 at 22:47 +, Meta via Digitalmars-d-learn wrote: […] Do you have the -dip1000 switch enabled? Not as far as I know. Why would I want to do that? You wouldn't as the std lib doesn't work with it yet.

Re: Is DMD breaking BigInt?

2017-04-08 Thread ag0aep6g via Digitalmars-d-learn
/Factorial/tree/master/D So, factorial.d:71 is this: tuple(30, immutable BigInt("26525285981219105863630848000")), And the BigInt constructor you're trying to use there is this one [1]: this(Range)(Range s) if ( isBidirectionalRange!Range &&

Re: Is DMD breaking BigInt?

2017-04-08 Thread Johan Engelen via Digitalmars-d-learn
On Saturday, 8 April 2017 at 12:16:10 UTC, Russel Winder wrote: Fedora Rawhide is now on LLVM 4.0 is that going to be a problem building LDC? Of course not! ;-) -Johan

Re: Is DMD breaking BigInt?

2017-04-08 Thread Russel Winder via Digitalmars-d-learn
On Fri, 2017-04-07 at 20:29 +, Jack Stouffer via Digitalmars-d- learn wrote: > On Friday, 7 April 2017 at 17:06:31 UTC, Russel Winder wrote: > > Simple Dub build of a Factorial example using Unit-Threaded for  > > testing. Works fine with ldc2 breaks with dmd. > > Can you post the code your

Re: Is DMD breaking BigInt?

2017-04-08 Thread Russel Winder via Digitalmars-d-learn
On Fri, 2017-04-07 at 20:38 +, David Nadlinger via Digitalmars-d- learn wrote: > […] > > You might want to check with LDC from Git master first to see  > whether it is in fact a 2.073-related problem. — David Rats, I thought I'd got away from manually building LDC. Fedora Rawhide is now on

Re: Is DMD breaking BigInt?

2017-04-08 Thread Russel Winder via Digitalmars-d-learn
On Fri, 2017-04-07 at 22:47 +, Meta via Digitalmars-d-learn wrote: > […] > > Do you have the -dip1000 switch enabled? Not as far as I know. Why would I want to do that? -- Russel. = Dr Russel Winder t: +44 20

Re: Is DMD breaking BigInt?

2017-04-07 Thread Meta via Digitalmars-d-learn
are: /usr/include/dmd/phobos/std/bigint.d(64,5): std.bigint.BigInt.__ctor(Range)(Range s) if (isBidirectionalRange!Range && isSomeChar!(ElementType!Range) && !isInfinite!Range) /usr/include/dmd/phobos/std/bigint.d(146,5): std.bigint.BigInt.__ctor(T)(T x) if (isInte

Re: Is DMD breaking BigInt?

2017-04-07 Thread David Nadlinger via Digitalmars-d-learn
On Friday, 7 April 2017 at 17:06:31 UTC, Russel Winder wrote: If anyone has any useful intelligence as to what happening and how I can workaround it, I'd be a grateful bunny. You might want to check with LDC from Git master first to see whether it is in fact a 2.073-related problem. — David

Re: Is DMD breaking BigInt?

2017-04-07 Thread Jack Stouffer via Digitalmars-d-learn
On Friday, 7 April 2017 at 17:06:31 UTC, Russel Winder wrote: Simple Dub build of a Factorial example using Unit-Threaded for testing. Works fine with ldc2 breaks with dmd. Can you post the code your using?

Is DMD breaking BigInt?

2017-04-07 Thread Russel Winder via Digitalmars-d-learn
t.BigInt.__ctor(Range)(Range s) if (isBidirectionalRange!Range && isSomeChar!(ElementType!Range) && !isInfinite!Range) /usr/include/dmd/phobos/std/bigint.d(146,5): std.bigint.BigInt.__ctor(T)(T x) if (isIntegral!T) /usr/include/dmd/phobos/std/bigint.d(162,5): std.b

Re: Best way to get ceil(log2(x)) of a BigInt?

2016-11-02 Thread Andrea Fontana via Digitalmars-d-learn
On Wednesday, 2 November 2016 at 15:15:18 UTC, Andrea Fontana wrote: Why don't you perform a binary search over 200 power of 2? Something like: http://paste.ofcode.org/scMD5JbmLMZkrv3bWRmPPT I wonder if a simple binary search on whole array is faster than search for limits as in this example

Re: Best way to get ceil(log2(x)) of a BigInt?

2016-11-02 Thread Andrea Fontana via Digitalmars-d-learn
the ceil of log2 of a bigint. Help? How big are your bigints? I think they'll generally stay between 0 and 2^200 I came up with this, I guess it'll work? auto clog2(BigInt number) in{ assert(number > 0); }body{ uint log; auto n = number - 1; while(n

Re: Best way to get ceil(log2(x)) of a BigInt?

2016-11-02 Thread pineapple via Digitalmars-d-learn
On Wednesday, 2 November 2016 at 14:24:42 UTC, Andrea Fontana wrote: On Wednesday, 2 November 2016 at 14:05:50 UTC, pineapple wrote: I'm trying to do some math stuff with std.bigint and realized there's no obvious way to calculate the ceil of log2 of a bigint. Help? How big are your bigints

Re: Best way to get ceil(log2(x)) of a BigInt?

2016-11-02 Thread Andrea Fontana via Digitalmars-d-learn
On Wednesday, 2 November 2016 at 14:05:50 UTC, pineapple wrote: I'm trying to do some math stuff with std.bigint and realized there's no obvious way to calculate the ceil of log2 of a bigint. Help? How big are your bigints?

Best way to get ceil(log2(x)) of a BigInt?

2016-11-02 Thread pineapple via Digitalmars-d-learn
I'm trying to do some math stuff with std.bigint and realized there's no obvious way to calculate the ceil of log2 of a bigint. Help?

Re: conver BigInt to string

2015-11-06 Thread Namal via Digitalmars-d-learn
On Thursday, 5 November 2015 at 17:40:12 UTC, bearophile wrote: Namal: Hello I am trying to convert BigInt to string like that while trying to sort it: void main() { import std.stdio, std.algorithm, std.conv, std.bigint, std.string; auto n = 17.BigInt ^^ 179

Re: conver BigInt to string

2015-11-06 Thread cym13 via Digitalmars-d-learn
On Friday, 6 November 2015 at 10:00:23 UTC, Namal wrote: On Thursday, 5 November 2015 at 17:40:12 UTC, bearophile wrote: Namal: Hello I am trying to convert BigInt to string like that while trying to sort it: void main() { import std.stdio, std.algorithm, std.conv, std.bigint

Re: conver BigInt to string

2015-11-05 Thread Meta via Digitalmars-d-learn
On Thursday, 5 November 2015 at 16:29:30 UTC, Namal wrote: Hello I am trying to convert BigInt to string like that while trying to sort it: string s1 = to!string(a).dup.sort; and get an error cannot implicitly convert expression (_adSortChar(dup(to(a of type char[] to string what do I

Re: conver BigInt to string

2015-11-05 Thread Namal via Digitalmars-d-learn
On Thursday, 5 November 2015 at 16:35:01 UTC, BBasile wrote: On Thursday, 5 November 2015 at 16:29:30 UTC, Namal wrote: Hello I am trying to convert BigInt to string like that while trying to sort it: string s1 = to!string(a).dup.sort; and get an error cannot implicitly convert expression

Re: conver BigInt to string

2015-11-05 Thread Namal via Digitalmars-d-learn
On Thursday, 5 November 2015 at 17:13:07 UTC, Ilya Yaroshenko wrote: string s1 = to!string(a).dup.sort.idup; well, but I was just told not to use sort ??

Re: conver BigInt to string

2015-11-05 Thread Namal via Digitalmars-d-learn
On Thursday, 5 November 2015 at 16:45:10 UTC, Meta wrote: On Thursday, 5 November 2015 at 16:29:30 UTC, Namal wrote: Hello I am trying to convert BigInt to string like that while trying to sort it: string s1 = to!string(a).dup.sort; and get an error cannot implicitly convert expression

conver BigInt to string

2015-11-05 Thread Namal via Digitalmars-d-learn
Hello I am trying to convert BigInt to string like that while trying to sort it: string s1 = to!string(a).dup.sort; and get an error cannot implicitly convert expression (_adSortChar(dup(to(a of type char[] to string what do I do wrong?

Re: conver BigInt to string

2015-11-05 Thread BBasile via Digitalmars-d-learn
On Thursday, 5 November 2015 at 16:39:03 UTC, Namal wrote: On Thursday, 5 November 2015 at 16:35:01 UTC, BBasile wrote: On Thursday, 5 November 2015 at 16:29:30 UTC, Namal wrote: Hello I am trying to convert BigInt to string like that while trying to sort it: string s1 = to!string

Re: conver BigInt to string

2015-11-05 Thread Ilya Yaroshenko via Digitalmars-d-learn
On Thursday, 5 November 2015 at 16:53:50 UTC, Namal wrote: On Thursday, 5 November 2015 at 16:45:10 UTC, Meta wrote: On Thursday, 5 November 2015 at 16:29:30 UTC, Namal wrote: Hello I am trying to convert BigInt to string like that while trying to sort it: string s1 = to!string(a).dup.sort

Re: conver BigInt to string

2015-11-05 Thread BBasile via Digitalmars-d-learn
On Thursday, 5 November 2015 at 16:29:30 UTC, Namal wrote: Hello I am trying to convert BigInt to string like that while trying to sort it: string s1 = to!string(a).dup.sort; and get an error cannot implicitly convert expression (_adSortChar(dup(to(a of type char[] to string what do I

Re: conver BigInt to string

2015-11-05 Thread bearophile via Digitalmars-d-learn
Namal: Hello I am trying to convert BigInt to string like that while trying to sort it: void main() { import std.stdio, std.algorithm, std.conv, std.bigint, std.string; auto n = 17.BigInt ^^ 179; n.text.dup.representation.sort().release.assumeUTF.writeln; } Bye, bearophile

Re: conver BigInt to string

2015-11-05 Thread bearophile via Digitalmars-d-learn
void main() { import std.stdio, std.algorithm, std.conv, std.bigint, std.string; auto n = 17.BigInt ^^ 179; n.text.dup.representation.sort().release.assumeUTF.writeln; } Better: n.to!(char[]).representation.sort().release.assumeUTF.writeln; Bye, bearophile

Re: bearophile is back! :) was: Re: conver BigInt to string

2015-11-05 Thread Chris via Digitalmars-d-learn
On Thursday, 5 November 2015 at 19:38:23 UTC, Ali Çehreli wrote: Good one! ;) I'm really happy that he is still around. Ali So am I! The more, the merrier!

bearophile is back! :) was: Re: conver BigInt to string

2015-11-05 Thread Ali Çehreli via Digitalmars-d-learn
On 11/05/2015 09:40 AM, bearophile wrote: Bye, bearophile Were you immersed in another language? Rust? Ali

Re: bearophile is back! :) was: Re: conver BigInt to string

2015-11-05 Thread Ali Çehreli via Digitalmars-d-learn
On 11/05/2015 11:35 AM, Chris wrote: On Thursday, 5 November 2015 at 19:30:02 UTC, Ali Çehreli wrote: On 11/05/2015 09:40 AM, bearophile wrote: Bye, bearophile Were you immersed in another language? Rust? Ali His D doesn't seem to be Rusty though! Good one! ;) I'm really happy that he

Re: bearophile is back! :) was: Re: conver BigInt to string

2015-11-05 Thread Chris via Digitalmars-d-learn
On Thursday, 5 November 2015 at 19:30:02 UTC, Ali Çehreli wrote: On 11/05/2015 09:40 AM, bearophile wrote: Bye, bearophile Were you immersed in another language? Rust? Ali His D doesn't seem to be Rusty though!

Re: conver BigInt to string

2015-11-05 Thread TheGag96 via Digitalmars-d-learn
On Thursday, 5 November 2015 at 16:45:10 UTC, Meta wrote: The second issue is that using .sort instead of .sort() (note the parentheses) calls the built-in sort instead of std.algorithm.sort, which is strongly discouraged. You should always use std.algorithm.sort over the built-in sort, which

Re: conver BigInt to string

2015-11-05 Thread Meta via Digitalmars-d-learn
On Thursday, 5 November 2015 at 20:45:45 UTC, TheGag96 wrote: Whoa whoa whoa... This is the first time I've heard about this difference, and I've used .sort plenty of times... That seems like really, REALLY bad design, especially considering the language allows functions to be called without

Re: bigint compile time errors

2015-07-10 Thread Kai Nacke via Digitalmars-d-learn
wrote: [...] Should be plusTwo(in BigInt n) instead. Yes, I had aliased BigInt to bigint. And I checked and it compiles for me too with Windows m64. That makes it seem more like a bug than a feature. I'll open a bug report. Paul The point here is that x86 uses an assembler-optimized

Re: bigint compile time errors

2015-07-07 Thread Paul D Anderson via Digitalmars-d-learn
On Sunday, 5 July 2015 at 20:35:03 UTC, Kai Nacke wrote: On Friday, 3 July 2015 at 04:08:32 UTC, Paul D Anderson wrote: On Friday, 3 July 2015 at 03:57:57 UTC, Anon wrote: On Friday, 3 July 2015 at 02:37:00 UTC, Paul D Anderson wrote: [...] Should be plusTwo(in BigInt n) instead. Yes

Re: bigint compile time errors

2015-07-05 Thread Kai Nacke via Digitalmars-d-learn
On Friday, 3 July 2015 at 04:08:32 UTC, Paul D Anderson wrote: On Friday, 3 July 2015 at 03:57:57 UTC, Anon wrote: On Friday, 3 July 2015 at 02:37:00 UTC, Paul D Anderson wrote: enum BigInt test1 = BigInt(123); enum BigInt test2 = plusTwo(test1); public static BigInt plusTwo(in bigint n

Re: bigint compile time errors

2015-07-03 Thread Paul D Anderson via Digitalmars-d-learn
On Friday, 3 July 2015 at 02:37:00 UTC, Paul D Anderson wrote: The following code fails to compile and responds with the given error message. Varying the plusTwo function doesn't work; as long as there is an arithmetic operation the error occurs. [...]

bigint compile time errors

2015-07-02 Thread Paul D Anderson via Digitalmars-d-learn
The following code fails to compile and responds with the given error message. Varying the plusTwo function doesn't work; as long as there is an arithmetic operation the error occurs. It seems to mean that there is no way to modify a BigInt at compile time. This seriously limits the usability

Re: bigint compile time errors

2015-07-02 Thread Anon via Digitalmars-d-learn
) using DMD64 D Compiler v2.067.1. It seems to mean that there is no way to modify a BigInt at compile time. This seriously limits the usability of the type. enum BigInt test1 = BigInt(123); enum BigInt test2 = plusTwo(test1); public static BigInt plusTwo(in bigint n) Should be plusTwo(in BigInt

Re: bigint compile time errors

2015-07-02 Thread Paul D Anderson via Digitalmars-d-learn
On Friday, 3 July 2015 at 03:57:57 UTC, Anon wrote: On Friday, 3 July 2015 at 02:37:00 UTC, Paul D Anderson wrote: enum BigInt test1 = BigInt(123); enum BigInt test2 = plusTwo(test1); public static BigInt plusTwo(in bigint n) Should be plusTwo(in BigInt n) instead. Yes, I had aliased

Re: BigInt to binary

2015-04-26 Thread Dennis Ritchie via Digitalmars-d-learn
On Saturday, 25 April 2015 at 21:13:29 UTC, Ali Çehreli wrote: On 04/25/2015 01:23 PM, Dennis Ritchie wrote: which section should apply similar requests? https://issues.dlang.org/ After clicking File and Issue: Component: Phobos Severity: Enhancement Ali Thanks. I reported this: -

Re: BigInt to binary

2015-04-25 Thread Dennis Ritchie via Digitalmars-d-learn
On Saturday, 25 April 2015 at 18:58:50 UTC, Marc Schütz wrote: BigInt only supports %d, %x, %X and %s: http://dlang.org/phobos/std_bigint.html#.BigInt.toString The missing %o and %b were probably an oversight, feel free to file an enhancement request or submit a PR. All right. I will file

Re: BigInt to binary

2015-04-25 Thread Ali Çehreli via Digitalmars-d-learn
On 04/25/2015 01:23 PM, Dennis Ritchie wrote: which section should apply similar requests? https://issues.dlang.org/ After clicking File and Issue: Component: Phobos Severity: Enhancement Ali

Re: BigInt to binary

2015-04-25 Thread via Digitalmars-d-learn
On Saturday, 25 April 2015 at 13:13:10 UTC, Dennis Ritchie wrote: Hi, Is there a way to apply a function format with BigInt? - import std.stdio, std.bigint, std.string; void main() { BigInt n = -10; string s = format(%b, n); // error writeln(s); } BigInt only

BigInt to binary

2015-04-25 Thread Dennis Ritchie via Digitalmars-d-learn
Hi, Is there a way to apply a function format with BigInt? - import std.stdio, std.bigint, std.string; void main() { BigInt n = -10; string s = format(%b, n); // error writeln(s); }

BigInt and xor

2015-03-24 Thread Dennis Ritchie via Digitalmars-d-learn
Tell me, please, how can I replace this code? import std.conv : to; import std.bigint : BigInt; import std.string : format; import std.stdio : writeln; void main() { BigInt[10] bitArr; ulong n = 18_446_724_073_709_551_614U; bitArr[0] = format(%b, n).to!BigInt

Re: BigInt and xor

2015-03-24 Thread Dennis Ritchie via Digitalmars-d-learn
On Tuesday, 24 March 2015 at 17:35:14 UTC, matovitch wrote: xor it with -1 instead of 1. (-1 is store as 0xfff..f with the classic modular arithmetic) Thanks.

Re: BigInt and xor

2015-03-24 Thread matovitch via Digitalmars-d-learn
On Tuesday, 24 March 2015 at 15:45:36 UTC, Dennis Ritchie wrote: Tell me, please, how can I replace this code? import std.conv : to; import std.bigint : BigInt; import std.string : format; import std.stdio : writeln; void main() { BigInt[10] bitArr; ulong n

Re: BigInt and xor

2015-03-24 Thread Dennis Ritchie via Digitalmars-d-learn
On Tuesday, 24 March 2015 at 16:35:04 UTC, Ivan Kazmenko wrote: What exactly is not working? Everything works. I'm just a little forgotten properties of the operation xor. I just wanted to xor 1 each digit in the number of type BigInt, while I would like to store each number in the binary

Re: BigInt and xor

2015-03-24 Thread Ivan Kazmenko via Digitalmars-d-learn
On Tuesday, 24 March 2015 at 15:45:36 UTC, Dennis Ritchie wrote: Tell me, please, how can I replace this code? import std.conv : to; import std.bigint : BigInt; import std.string : format; import std.stdio : writeln; void main() { BigInt[10] bitArr; ulong n

Re: BigInt and xor

2015-03-24 Thread Rene Zwanenburg via Digitalmars-d-learn
On Tuesday, 24 March 2015 at 15:45:36 UTC, Dennis Ritchie wrote: Tell me, please, how can I replace this code? import std.conv : to; import std.bigint : BigInt; import std.string : format; import std.stdio : writeln; void main() { BigInt[10] bitArr; ulong n

Re: BigInt and xor

2015-03-24 Thread matovitch via Digitalmars-d-learn
of type BigInt, while I would like to store each number in the binary representation of the array BigInt. xor it with -1 instead of 1. (-1 is store as 0xfff..f with the classic modular arithmetic)

Re: A specifier readf() for BigInt

2015-02-17 Thread Dennis Ritchie via Digitalmars-d-learn
On Tuesday, 17 February 2015 at 07:20:19 UTC, Ivan Kazmenko wrote: The readf function does not seem to support reading BigInts directly. However, you can read a string and construct a BigInt from it, either by std.conv.to or directly invoking the constructor: import std.algorithm

A specifier readf() for BigInt

2015-02-16 Thread Dennis Ritchie via Digitalmars-d-learn
Hi. And how to read Data from the input stream? import std.stdio; import std.bigint; void main() { BigInt n; readf( %?, n); writeln(n); }

Re: A specifier readf() for BigInt

2015-02-16 Thread Ivan Kazmenko via Digitalmars-d-learn
On Monday, 16 February 2015 at 19:52:20 UTC, Dennis Ritchie wrote: Hi. And how to read Data from the input stream? import std.stdio; import std.bigint; void main() { BigInt n; readf( %?, n); writeln(n); } The readf function does not seem to support reading BigInts

iota and BigInt

2015-01-22 Thread Russel Winder via Digitalmars-d-learn
Using reduce for factorial, seems to require iota, not a bad things per se, with ulongs: reduce!a*b(1, iota(1, n + 1)) works fine. Now switch to BigInt: reduce!a*b(one, iota(one, n + one)) fails to compile, one and n + one are of different types. Problem is that one

Re: iota and BigInt

2015-01-22 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jan 22, 2015 at 05:12:17PM +, Russel Winder via Digitalmars-d-learn wrote: Using reduce for factorial, seems to require iota, not a bad things per se, with ulongs: reduce!a*b(1, iota(1, n + 1)) works fine. Now switch to BigInt: reduce!a*b(one, iota(one, n + one

Re: iota and BigInt

2015-01-22 Thread Russel Winder via Digitalmars-d-learn
On Thu, 2015-01-22 at 10:21 -0800, H. S. Teoh via Digitalmars-d-learn wrote: […] https://github.com/D-Programming-Language/phobos/pull/2895 This is just the tip of the iceberg. The full enhancement is described in: https://issues.dlang.org/show_bug.cgi?id=10762 Sadly, I suspect

Re: BigInt and

2014-12-19 Thread bearophile via Digitalmars-d-learn
Andre: Do you have any idea how to translate the coding correctly? Try: i += long(buffer[3]) 24 0; But I also suggest to add parentheses, to make the code less unreadable for humans. Bye, bearophile

Re: BigInt and

2014-12-19 Thread Andre via Digitalmars-d-learn
Great! Thanks a lot. Kind regards André On Friday, 19 December 2014 at 08:47:50 UTC, bearophile wrote: Andre: Do you have any idea how to translate the coding correctly? Try: i += long(buffer[3]) 24 0; But I also suggest to add parentheses, to make the code less unreadable for humans.

BigInt and

2014-12-18 Thread Andre via Digitalmars-d-learn
returns -1, the previous 3 statements returns the same values like in JavaScript. I tried long and also like in the example BigInt, both do not work correctly. In the documentation it is also mentioned that is not supported for BigInt? void main() { import std.stdio; import

BigInt not integral type?

2013-06-16 Thread Tyro[17]
The following code: void main() { import std.bigint; BigInt x, m; BigInt l = x m; } Result in: andrew@ace:~$ dmd f f.d(6): Error: 'x' is not of integral type, it is a BigInt f.d(6): Error: 'm' is not of integral type, it is a BigInt I'm sure there is plans to resolve

Re: BigInt not integral type?

2013-06-16 Thread Jonathan M Davis
On Sunday, June 16, 2013 05:14:07 Tyro[17] wrote: The following code: void main() { import std.bigint; BigInt x, m; BigInt l = x m; } Result in: andrew@ace:~$ dmd f f.d(6): Error: 'x' is not of integral type, it is a BigInt f.d(6): Error: 'm' is not of integral

Cantor tuple function, BigInt, and integer overflow

2012-12-20 Thread Joseph Rushton Wakeling
to the maximum of their given type. For this reason I've made use of BigInt internally and as a return value. However, it occurs to me that it would be nice to avoid BigInt unless it's necessary, both for speed/memory reasons and for convenience. I'm wondering if anyone has any advice on how

Re: Cantor tuple function, BigInt, and integer overflow

2012-12-20 Thread H. S. Teoh
is fixed (currently 32-bit or 64-bit), we can do better. If we concatenate the elements of the sequence to form a 32*N (or 64*N) bit BigInt, that also gives us a unique index for the sequence. Assuming that the numbers in your sequence cover a good part of the range of a 32-bit (or 64-bit) integer

Re: std.bigint: BigInt conversion

2012-12-03 Thread novice2
Big thank you. I hope, this changes will be included in phobos in future.

Re: std.bigint: BigInt conversion

2012-12-03 Thread bearophile
novice2: I hope, this changes will be included in phobos in future. Sometimes hoping isn't enough. If you have a need that youi think should be in Phobos, then I think you should ask for it in Bugzilla. Asking isn't equal to someone actually implementing it, but in this early stage of the

std.bigint: BigInt conversion

2012-11-25 Thread novice2
How i can convert ubyte[] to BigInt and BigInt to ubyte[] ? Or uint[]... For example, i need RSA crypto. I should get ubyte[] data, ubyte[] key, convert it to BigInt, calculate, then save result as ubyte[] data again. But i see BigInt convertable to string only :(

Re: std.bigint: BigInt conversion

2012-11-25 Thread Stian
On Sunday, 25 November 2012 at 21:36:38 UTC, novice2 wrote: How i can convert ubyte[] to BigInt and BigInt to ubyte[] ? Or uint[]... For example, i need RSA crypto. I should get ubyte[] data, ubyte[] key, convert it to BigInt, calculate, then save result as ubyte[] data again. But i see

Re: bigint - python long

2012-09-11 Thread Ellery Newcomer
On 09/10/2012 10:50 PM, Russel Winder wrote: Python 2 and Python 3 are totally different in this regard. I don't have a obvious proposal to make to avoid having PyD for Python 2 and a different PyD for Python 3, but the six package might have some hints as it is intended to support creating

Re: bigint - python long

2012-09-11 Thread Ellery Newcomer
On 09/05/2012 07:10 PM, bearophile wrote: Ellery Newcomer: Yep. Oh, good. Have any suggestions for supported conversion out of the box? There are several important cases, like: Some D lazy ranges == Python lazy iterators/generators array.array == D arrays NumPy arrays == D arrays

Re: D and SCons [ was Re: bigint - python long ]

2012-09-10 Thread Johannes Pfau
Am Sun, 09 Sep 2012 12:55:19 -0700 schrieb Brad Roberts bra...@puremagic.com: On 9/9/2012 1:15 AM, Johannes Pfau wrote: Am Sat, 08 Sep 2012 16:25:49 +0100 schrieb Russel Winder rus...@winder.org.uk: On Sat, 2012-09-08 at 07:20 -0700, Ellery Newcomer wrote: […] Okay, here:

Re: D and SCons [ was Re: bigint - python long ]

2012-09-10 Thread Johannes Pfau
Am Mon, 10 Sep 2012 14:48:30 +0200 schrieb Johannes Pfau nos...@example.com: Sorry, I should have said 'It'll _probably_ never be supported in gdc'. There are some possible solutions but: * It must be good enough to get approved when gdc is merged into gcc. (remember it must be portable

Re: bigint - python long

2012-09-10 Thread Ellery Newcomer
On 09/05/2012 07:10 PM, bearophile wrote: NumPy arrays == D arrays I've been thinking about this one a bit more, and I am not sure it belongs in pyd. First, the conversion is not symmetric. One can convert a numpy.ndarray to a d array like so: PyObject* ndarray; double[][] matrix =

Re: bigint - python long

2012-09-10 Thread bearophile
Ellery Newcomer: I've been thinking about this one a bit more, and I am not sure it belongs in pyd. I understand. The point of Pyd is to interface D and Python, while NumPy is something external. So if you find difficulties just keep it out. Adding it later is possible. Bye, bearophile

Re: bigint - python long

2012-09-10 Thread Ellery Newcomer
On 09/10/2012 12:11 PM, bearophile wrote: I understand. The point of Pyd is to interface D and Python, while NumPy is something external. So if you find difficulties just keep it out. Adding it later is possible. Thing is, pyd will convert a ndarray to d array already, it just won't do it

Re: bigint - python long

2012-09-10 Thread Russel Winder
On Mon, 2012-09-10 at 15:54 -0700, Ellery Newcomer wrote: […] OT Bugger, I'm going to have to go through pyd and replace all usages of str with unicode. /OT Python 2 and Python 3 are totally different in this regard. I don't have a obvious proposal to make to avoid having PyD for Python 2 and

  1   2   >