Re: Conversion problem.

2019-06-26 Thread Den_d_y via Digitalmars-d-learn

On Wednesday, 26 June 2019 at 10:49:50 UTC, Den_d_y wrote:

On Wednesday, 26 June 2019 at 05:53:29 UTC, Den_d_y wrote:

On Tuesday, 25 June 2019 at 16:44:28 UTC, H. S. Teoh wrote:
On Tue, Jun 25, 2019 at 12:08:07PM +, Den_d_y via 
Digitalmars-d-learn wrote:

[...]

[...]

Did you try this?

import std.conv : to;

double d = ...;
int i = d.to!int;


T


This does not work. The program hangs at this stage, even the 
code you have proposed also does not work as we would like. 
Maybe I'm doing something wrong?


Something is tracked:
std.conv.ConvOverflowException@C: \ D \ dmd2 \ windows \ bin \ 
.. \ .. \ src \ phobos \ std \ conv.d (1457): Conversion 
Underflow Overflow

What could it be


How stupid ... You just had to assign the value "0" to the value 
0 ... The problem is solved.


Re: Conversion problem.

2019-06-26 Thread Den_d_y via Digitalmars-d-learn

On Wednesday, 26 June 2019 at 05:53:29 UTC, Den_d_y wrote:

On Tuesday, 25 June 2019 at 16:44:28 UTC, H. S. Teoh wrote:
On Tue, Jun 25, 2019 at 12:08:07PM +, Den_d_y via 
Digitalmars-d-learn wrote:
Hello! Here I am again, with my problem ... In my program, I 
cannot manage to convert from "double" to "int". Here is the 
code:

[...]

Did you try this?

import std.conv : to;

double d = ...;
int i = d.to!int;


T


This does not work. The program hangs at this stage, even the 
code you have proposed also does not work as we would like. 
Maybe I'm doing something wrong?


Something is tracked:
std.conv.ConvOverflowException@C: \ D \ dmd2 \ windows \ bin \ .. 
\ .. \ src \ phobos \ std \ conv.d (1457): Conversion Underflow 
Overflow

What could it be


Re: Conversion problem.

2019-06-25 Thread Den_d_y via Digitalmars-d-learn

On Tuesday, 25 June 2019 at 16:44:28 UTC, H. S. Teoh wrote:
On Tue, Jun 25, 2019 at 12:08:07PM +, Den_d_y via 
Digitalmars-d-learn wrote:
Hello! Here I am again, with my problem ... In my program, I 
cannot manage to convert from "double" to "int". Here is the 
code:

[...]

Did you try this?

import std.conv : to;

double d = ...;
int i = d.to!int;


T


This does not work. The program hangs at this stage, even the 
code you have proposed also does not work as we would like. Maybe 
I'm doing something wrong?






Conversion problem.

2019-06-25 Thread Den_d_y via Digitalmars-d-learn
Hello! Here I am again, with my problem ... In my program, I 
cannot manage to convert from "double" to "int". Here is the code:

<< ++
struct Animation - the structure that implements the animation
+ /
struct Animation
{
private List! (Image) img; /// List of pictures in the animation
private double f; /// current picture in animation
private double s; /// speed of animation

/// speed setter (double s)
public void setSpeed ​​(double sp)
{
s = sp;
}

/// Adds a picture to the list
public void addFrame (Image pia)
{
img.add (pia);
}

/// Sets the image to a specific place in the list
public void setFrame (int id, Image pia)
{
img.set (id, pia);
}

/// Returns a picture from the list
public Image getFrame (int id)
{
return img.get (id);
}

/// Returns the list
public List! (Image) getList ()
{
return img;
}

/// The animation event itself. Returns the current animation 
image.

public Image step ()
{
writeln ("Animation :: step start ...");
if (floor (f) == img.length)
{
f = 0.1f;
writeln ("Animation :: f = 0.1f");
} else
{
f + = s;
writeln ("Animation :: f + = s");
}

const int i = roundTo! (int) (f);
writeln ("i set");
writeln ("i:", i);
return img.get (i);
}
} >>
Another code:
<< import std.stdio;

/ ++
The structure that implements the list of objects.
+ /
struct List (TObj)
{
private TObj [] obj;

/// Adds an object to the list
public void add (TObj o)
{
obj ~ = o;
}

/// Returns an object from the list
public TObj get (int id)
{
return obj [id];
}

/// Sets an object in a specific place.
public void set (int id, TObj o)
{
obj [id] = o;
}

/// Returns the length of the list
public int length ()
{
return obj.length;
}

/// Gives the garbage collector a signal to clear the list.
public void free ()
{
obj = null;
}
} >>

"If you don’t understand something, the translator has bricked 
it."


In the moment:
<< public Image step ()
{
writeln ("Animation :: step start ...");
if (floor (f) == img.length)
{
f = 0.1f;
writeln ("Animation :: f = 0.1f");
} else
{
f + = s;
writeln ("Animation :: f + = s");
}

const int i = roundTo! (int) (f); // Error here
writeln ("i set");
writeln ("i:", i);
return img.get (i);
} >> The compiler is silent, but when you start the program, 
reaching this place, it hangs.
 Is there any way to convert a "double" to an "int" without 
errors?




The problem with the conversion.

2019-06-19 Thread Den_d_y via Digitalmars-d-learn
Hello, users of this programming language! I have a question. I 
use in my application Derelict SDL 2 version 2.1.4.

And when I try to specify the path to the image:

void load (const (char *) path)
{
SDL_Surface ab = SDL_LoadBMP (path);
a = SDL_CreateTextureFromSurface (ab);
SDL_FreeSurface (ab);
}

An error occurs:
"function derelict.sdl2.functions.SDL_LoadBMP (const (char) * 
file) is not callable using argument types (string)".
Well, okay, I use in arguments: const (char *) path. Annoyed, the 
program still writes this error. Please help with this problem.
 P.S. If you see errors in spelling and stuff, then note: I am a 
Russian user.

  P.P.S. I am not familiar with this programming language.