On Wednesday, 9 July 2014 at 19:54:47 UTC, H. S. Teoh via
Digitalmars-d-learn wrote:
[...]
The problem is that the function needs to return
int, but given two uints, their difference may be
greater than int.max, so simply subtracting them
will not work. So the best I can come up with is:
Should of course be:
int compare2(uint x, int y)
{
return (x int.max) ? 1 : (cast(int)x - y);
}
On Wednesday, 9 July 2014 at 15:09:08 UTC, Chris wrote:
On Wednesday, 9 July 2014 at 15:00:25 UTC, seany wrote:
I apologize many times for this question, may be this had
already been answered somewhere, but considering today the
last of my nerve is broken, I can not really find the soution.
On 11/07/2014 12:11 a.m., Sean Campbell wrote:
i have the ints 4, 7, 0 and 1 how can i Concatenate them into four
thousand seven hundred and one.
If we talking at compile time definition:
int myint = 4_7_0_1;
Would work.
However I'll assume its at runtime you really want this.
I.e.
Rikki Cattermole:
int myint = to!int(4 ~ 7 ~ 0 ~ 1);
And to concatenate them there is join (joiner is not yet usable
here, because to!() doesn't yet accept a lazy input,
unfortunately).
Now they are not strings, and the positions of 10^ doesn't
change then:
int myint = (1000 * 4) +
On 07/10/2014 02:22 PM, Rikki Cattermole wrote:
On 11/07/2014 12:11 a.m., Sean Campbell wrote:
i have the ints 4, 7, 0 and 1 how can i Concatenate them into four
thousand seven hundred and one.
If we talking at compile time definition:
int myint = 4_7_0_1;
Would work.
However I'll
The others have already given some answers, I just want to point
out that the (free) sample chapter of my D book covers this topic
too:
http://www.packtpub.com/discover-advantages-of-programming-in-d-cookbook/book
Scanning a whole module and getting everything out takes a few
tricks that I
perhaps I'd better state what I'm doing.
i have an array of 4 bytes and a want to convert them to a 32 bit
int
and convert the 32 bit int back into a 4 bytes again.
On Monday, 7 July 2014 at 23:47:26 UTC, Aerolite wrote:
So, if you would be so kind, give me a bullet list of the
aspects of D you believe to be good, awesome, bad, and/or ugly.
If you have the time, some code examples wouldn't go amiss
either! Try not to go in-depth to weird edge cases -
On Thursday, 10 July 2014 at 12:12:20 UTC, Marc Schütz wrote:
On Wednesday, 9 July 2014 at 15:09:08 UTC, Chris wrote:
On Wednesday, 9 July 2014 at 15:00:25 UTC, seany wrote:
I apologize many times for this question, may be this had
already been answered somewhere, but considering today the
On 11/07/2014 1:18 a.m., Sean Campbell wrote:
perhaps I'd better state what I'm doing.
i have an array of 4 bytes and a want to convert them to a 32 bit
int
and convert the 32 bit int back into a 4 bytes again.
Small hack I use in Dakka:
union RawConvTypes(T) {
T value;
I have one file with a lot of numeric data... and I need to sum
all that data...
That is my actual code:
module main;
import std.stdio;
import std.file;
import std.conv : to;
int main(string[] args)
{
auto f = File(oi.txt);
auto r = f.byLine();
auto tot = 0;
Alexandre:
I want to know if have a more better way to make this... maybe
using lambda or tamplates
Your code is not bad. This is a bit better (untested):
void main() {
import std.stdio;
import std.conv: to;
auto lines = oi.txt.File.byLine;
int tot = 0;
foreach
O, real intresting the mode functional style!!!
Like linq!
hahah
Btw, it's work very well, thansk!!!
But, how I can insert an ',' comma to separe the decimal place ?
( the last 2 digits )
I can't find a insert instruction in std.string or std.array
On Thursday, 10 July 2014 at 15:01:52
On Thursday, 10 July 2014 at 13:51:22 UTC, Rikki Cattermole wrote:
On 11/07/2014 1:18 a.m., Sean Campbell wrote:
perhaps I'd better state what I'm doing.
i have an array of 4 bytes and a want to convert them to a 32
bit
int
and convert the 32 bit int back into a 4 bytes again.
Small hack I
A code I'm working on stops working and starts printing an
infinite loop of
core.exception.InvalidMemoryOperationError
to the command line output. The code is quite complex and the bug
seems to present itself almost in random situation so I would
like to try to understand the issue better
Hello,
I may have not understood what you actually want to do, but
aren't std.bitmanip.peek or std.bitmanip.read what you are
looking for ?
http://dlang.org/phobos/std_bitmanip.html#.peek
I have a string X and I need to insert a char in that string...
auto X = 100;
And I need to inser a ',' in position 3 of this string..., I try
to use the array.insertInPlace, but, not work...
I try this:
auto X = 100;
auto N = X.insertInPlace(1,'0');
On Thursday, 10 July 2014 at 16:05:51 UTC, Alexandre wrote:
I have a string X and I need to insert a char in that string...
auto X = 100;
And I need to inser a ',' in position 3 of this string..., I
try to use the array.insertInPlace, but, not work...
I try this:
auto X =
Sorry..
I mean:
auto X = 100;
auto N = X.insertInPlace(3,',');
On Thursday, 10 July 2014 at 16:05:51 UTC, Alexandre wrote:
I have a string X and I need to insert a char in that string...
auto X = 100;
And I need to inser a ',' in position 3 of this string..., I
try
I used that solution:
string InsertComma(string val)
{
return val[0 .. $-2] ~ , ~ val[$-2 .. $];
}
On Thursday, 10 July 2014 at 16:23:44 UTC, John Colvin wrote:
On Thursday, 10 July 2014 at 16:05:51 UTC, Alexandre wrote:
I have a string X and I need to insert a char in that string...
On Thursday, 10 July 2014 at 16:20:29 UTC, Alexandre wrote:
Sorry..
I mean:
auto X = 100;
auto N = X.insertInPlace(3,',');
On Thursday, 10 July 2014 at 16:05:51 UTC, Alexandre wrote:
I have a string X and I need to insert a char in that string...
auto X = 100;
And I
On Thursday, 10 July 2014 at 13:51:22 UTC, Rikki Cattermole wrote:
On 11/07/2014 1:18 a.m., Sean Campbell wrote:
perhaps I'd better state what I'm doing.
i have an array of 4 bytes and a want to convert them to a 32
bit
int
and convert the 32 bit int back into a 4 bytes again.
Small hack I
Oh, I used that letters in upper case, just for a simple sample...
On Thursday, 10 July 2014 at 16:32:53 UTC, Marc Schütz wrote:
On Thursday, 10 July 2014 at 16:20:29 UTC, Alexandre wrote:
Sorry..
I mean:
auto X = 100;
auto N = X.insertInPlace(3,',');
On Thursday, 10 July 2014 at
On Thursday, 10 July 2014 at 15:14:21 UTC, Sean Campbell wrote:
On Thursday, 10 July 2014 at 13:51:22 UTC, Rikki Cattermole
wrote:
On 11/07/2014 1:18 a.m., Sean Campbell wrote:
perhaps I'd better state what I'm doing.
i have an array of 4 bytes and a want to convert them to a 32
bit
int
and
On Thursday, 10 July 2014 at 15:36:53 UTC, francesco cattoglio
wrote:
A code I'm working on stops working and starts printing an
infinite loop of
core.exception.InvalidMemoryOperationError
to the command line output. The code is quite complex and the
bug seems to present itself almost in
PS: that is my code:
import std.stdio, std.algorithm, std.range, std.conv;
string InsertComma(string val)
{
return val[0 .. $-2] ~ , ~ val[$-2 .. $];
}
int main(string[] argv)
{
auto x = oi.txt
.File
.byLine
.filter!(line =
Hi :)
I need to sum a list of numbers... but, when I calculate the sum
of this numbers, I got a simplify representation of sum:
2.97506e+,12
How I can make to get the correctly representation of this number
?
On Thu, 10 Jul 2014 17:16:00 +, Alexandre wrote:
Hi :)
I need to sum a list of numbers... but, when I calculate the sum of this
numbers, I got a simplify representation of sum:
2.97506e+,12
How I can make to get the correctly representation of this number ?
A full decimal
On Thu, 10 Jul 2014 17:17:40 +, Justin Whear wrote:
On Thu, 10 Jul 2014 17:16:00 +, Alexandre wrote:
Hi :)
I need to sum a list of numbers... but, when I calculate the sum of
this numbers, I got a simplify representation of sum:
2.97506e+,12
How I can make to get the
On Thursday, 10 July 2014 at 15:51:11 UTC, Olivier Pisano wrote:
Hello,
I may have not understood what you actually want to do, but
aren't std.bitmanip.peek or std.bitmanip.read what you are
looking for ?
http://dlang.org/phobos/std_bitmanip.html#.peek
std.bitmanip.peek and std.bitmanip.read
On Thursday, 10 July 2014 at 17:30:17 UTC, Sean Campbell wrote:
if I need to Concatenate ints I'l just use a recursive pow
based on length
int ConcatInt(int[] anint){
int total = 0;
for(int i=0;ianint.length;i++){
total += anint[i]*10^^(anint.length-i-1);
On 07/10/2014 06:05 PM, Alexandre wrote:
I have a string X and I need to insert a char in that string...
auto X = 100;
And I need to inser a ',' in position 3 of this string..., I try to use
the array.insertInPlace, but, not work...
I try this:
auto X = 100;
basically format
I read a cobol struct file...
From pos X to Y I have a money value... but, this value don't
have any format..
0041415
The 15 is the cents... bascally I need to put the ( comma ), we
use comma to separate the cents, here in Brazil...
On Thursday, 10 July 2014
Here's a code example:
module main;
import foo;
enum Get = GET;
void bar (string a)
{
assert(a is Get);
}
void main ()
{
asd();
}
module foo;
import main;
void asd()
{
bar(Get);
}
Running the above code will cause an assert error in the function bar.
But if I move the
On 07/10/2014 09:58 PM, Alexandre wrote:
basically format
I read a cobol struct file...
From pos X to Y I have a money value... but, this value don't have any
format..
0041415
The 15 is the cents... bascally I need to put the ( comma ), we use
comma to separate the cents,
On Thursday, 10 July 2014 at 20:27:39 UTC, Jacob Carlborg wrote:
Here's a code example:
module main;
import foo;
enum Get = GET;
void bar (string a)
{
assert(a is Get);
}
void main ()
{
asd();
}
module foo;
import main;
void asd()
{
bar(Get);
}
Running the above code will
On Thursday, 10 July 2014 at 20:27:39 UTC, Jacob Carlborg wrote:
Here's a code example:
module main;
import foo;
enum Get = GET;
void bar (string a)
{
assert(a is Get);
}
void main ()
{
asd();
}
module foo;
import main;
void asd()
{
bar(Get);
}
Running the above code will
On 07/10/2014 10:47 PM, Marc Schütz schue...@gmx.net wrote:
On Thursday, 10 July 2014 at 20:27:39 UTC, Jacob Carlborg wrote:
Here's a code example:
module main;
import foo;
enum Get = GET;
void bar (string a)
{
assert(a is Get);
}
void main ()
{
asd();
}
module foo;
On Thursday, 10 July 2014 at 20:59:17 UTC, simendsjo wrote:
Strings behaves a bit odd with is(). The following passes:
import std.stdio;
void f(string a, string b) {
assert(a is b); // also true
}
void main() {
string a = aoeu;
string b = aoeu;
assert(a is b); // true
f(a,
I've been trying to set a date for my program (a small struct):
import std.datetime;
auto date = cast(DateTime)Clock.currTime();
setDate(date.day, date.month, date.year);
Problem is that day month are not integers. And date.day.to!int
doesn't work either.
On 07/11/2014 01:08 AM, sigod wrote:
On Thursday, 10 July 2014 at 20:59:17 UTC, simendsjo wrote:
Strings behaves a bit odd with is(). The following passes:
import std.stdio;
void f(string a, string b) {
assert(a is b); // also true
}
void main() {
string a = aoeu;
string b =
42 matches
Mail list logo