modInverse & powMod

2024-06-07 Thread Salih Dincer via Digitalmars-d-learn
I know there is modular exponentiation 
[std.math.exponential.powmod](https://dlang.org/library/std/math/exponential/powmod.html) in the standard library.While it works great in Pyrhon (even with very large numbers), it doesn't work with signed numbers in D. That's why I turned to the alternative below. Don't let it be misunderstood, I don't want to wear out the D language, I use whatever I have, I love D and I don't ask why it works so strangely.


```d
//import std.math.exponential : fpowmod = powmod; /*
T fpowmod(T)(T base, T exponent, T modulus)
{
auto r = T(1);
for (T x = base, y = exponent; y;
x = x * x % modulus, y /= 2)
if (y % 2) r = r * x % modulus;

return r;
}//*/
```

Thanks...

SDB@79

I have only one question: Is there a modInverse() function in the 
standard library for use in RSA? I did research on this subject 
within the relevant modules.  I guess not these?


* 
[std.mathspecial.logmdigammaInverse](https://dlang.org/phobos/std_mathspecial.html)
* 
[std.numeric.inverseFft](https://dlang.org/library/std/numeric.html)


Re: Anybody know about SDL and particularly SDL_TTF initialization?

2024-06-07 Thread solidstate1991 via Digitalmars-d-learn

On Sunday, 12 May 2024 at 20:13:04 UTC, WhatMeWorry` wrote:

This should be trivial, right?
I've been looking at existing D repo code for hours. Can't 
figure why TTF_Init doesn't work?

It would help if I could figure out how to use SDL_GetError()

INFO: SDL loaded v2.30.2
INFO: SDL initialized: 0
INFO: TTF loaded: v2.0.14
Error Program exited with code -1073741819


  loadSDL();
  SDL_version v;
  SDL_GetVersion(&v);
  toStdout("SDL loaded v%d.%d.%d", v.major, v.minor, v.patch);
  auto initSDL = SDL_Init(SDL_INIT_EVERYTHING);  // returns 0 
on success

  toStdout("SDL initialized: %d", initSDL);

  auto loadTTF = loadSDLTTF();
  SDL_TTF_VERSION(&v);
  toStdout("TTF loaded: v%d.%d.%d", v.major, v.minor, v.patch);
  auto initTTF = TTF_Init();  // SDL must be initialized before 
calls to this library


I personally recommend using an alternative TTF library.


How do I install a non-outdated D compiler on Linux? (not in userspace-container)

2024-06-07 Thread solidstate1991 via Digitalmars-d-learn
I **need** to link against various system libraries, and 
otherwise some tools won't be able to access the D compiler 
unless I start them from a command line after an initialization 
script.


I'm using Linux Mint, it's much more stable than Ubuntu (which 
started to completely collapse on me for just looking the wrong 
way at it), but unfortunately some packages are outdated, 
especially the D compilers.


Re: How do I install a non-outdated D compiler on Linux? (not in userspace-container)

2024-06-07 Thread solidstate1991 via Digitalmars-d-learn

On Friday, 7 June 2024 at 23:19:37 UTC, solidstate1991 wrote:
I **need** to link against various system libraries, and 
otherwise some tools won't be able to access the D compiler 
unless I start them from a command line after an initialization 
script.


I'm using Linux Mint, it's much more stable than Ubuntu (which 
started to completely collapse on me for just looking the wrong 
way at it), but unfortunately some packages are outdated, 
especially the D compilers.


Okay, I installed the "curl" versions, how do I edit the 
activating shell scripts of DMD and LDC that they'd work as if 
they were installed "normally"? I don't have the time, not the 
capacity to test my libraries with multiple different compiler 
versions, and document any oddities between them (and I almost 
never need it thanks to D).


Trying to call some C code using Extern(C) but got unexpected linker error

2024-06-07 Thread Xiaochao Yan via Digitalmars-d-learn
Hi, I am new to D and is experimenting with game development 
using D and C.


I had some problem when trying to recreate the
https://dlang.org/spec/importc.html

Environment:
Windows 11
gcc.exe (i686-posix-dwarf-rev0, Built by MinGW-W64 project) 8.1.0

Error Message:
```
lld-link: error: undefined symbol: _D4test4mainFZ12printMessageUZv

referenced by test.obj:(_Dmain)


```

```
// .c file
#include 

void printMessage() {
printf("Hello from C!\n");
}
```

```
// .d file
import std.stdio;
import std.conv;
import test;

void main() {

writeln("Hello, World!");
extern (C) void printMessage();
printMessage();
}
```
Thanks in advance!


Re: Trying to call some C code using Extern(C) but got unexpected linker error

2024-06-07 Thread Steven Schveighoffer via Digitalmars-d-learn

On Saturday, 8 June 2024 at 02:22:00 UTC, Xiaochao Yan wrote:
Hi, I am new to D and is experimenting with game development 
using D and C.


I had some problem when trying to recreate the
https://dlang.org/spec/importc.html

Environment:
Windows 11
gcc.exe (i686-posix-dwarf-rev0, Built by MinGW-W64 project) 
8.1.0


Error Message:
```
lld-link: error: undefined symbol: 
_D4test4mainFZ12printMessageUZv

referenced by test.obj:(_Dmain)


```

```
// .c file
#include 

void printMessage() {
printf("Hello from C!\n");
}
```

```
// .d file
import std.stdio;
import std.conv;
import test;

void main() {

writeln("Hello, World!");
extern (C) void printMessage();
printMessage();
}
```
Thanks in advance!


Put `printMessage` outside the main function. Inside the main 
function, it has C linkage, but not C name mangling.


-Steve


Re: How do I install a non-outdated D compiler on Linux? (not in userspace-container)

2024-06-07 Thread bachmeier via Digitalmars-d-learn

On Saturday, 8 June 2024 at 00:21:59 UTC, solidstate1991 wrote:

On Friday, 7 June 2024 at 23:19:37 UTC, solidstate1991 wrote:
I **need** to link against various system libraries, and 
otherwise some tools won't be able to access the D compiler 
unless I start them from a command line after an 
initialization script.


I'm using Linux Mint, it's much more stable than Ubuntu (which 
started to completely collapse on me for just looking the 
wrong way at it), but unfortunately some packages are 
outdated, especially the D compilers.


Okay, I installed the "curl" versions, how do I edit the 
activating shell scripts of DMD and LDC that they'd work as if 
they were installed "normally"? I don't have the time, not the 
capacity to test my libraries with multiple different compiler 
versions, and document any oddities between them (and I almost 
never need it thanks to D).


For Mint, I'd use the .deb and let it handle that stuff. For LDC, 
I have a bash alias for ldmd2 that points to the ldmd2 binary. Of 
course there are multiple ways to handle this, but I don't 
understand the point of the install script, since it leaves you 
without a working installation.