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);
}
i have the ints 4, 7, 0 and 1 how can i Concatenate them into
four thousand seven hundred and one.
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.
S
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. convertin
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
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.
> Howev
So at all the implementation will look something like this:
int opCmp(T, U)(const(T) a, const(U) b) @primitive
if(isIntegral!T && isIntegral!U)
{
alias CommonType!(Signed!T, Signed!U) C;
static if(isSigned!T && isUnsigned!U)
{
return (b > cast(Unsigned!C)C.max) ? -1 : cast(C)a -
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 ta
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 - remai
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
las
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;
ubyte[T
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 (c
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 U
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 u
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 befor
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 = "1000
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
tr
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
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 u
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 a
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 c
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 random
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 => li
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 r
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 t
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;i
With `foreach_reverse` it looks a little better:
```d
int concat_ints(int[] ints)
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 = "1
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 at
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 fun
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 th
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 c
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 c
On 07/10/2014 10:47 PM, "Marc Schütz" " 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();
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
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"
On 10/07/14 22:47, "Marc Schütz" " wrote:
No, this is equivalent to:
void bar (string a)
{
assert(a is "GET");
}
void asd()
{
bar("GET");
}
Enums behave as if their values are copy-n-pasted everywhere they are
used (you probably know that).
Yes, I was thinking that. Then I was thi
On 10/07/14 22:48, anonymous wrote:
I don't think this is a bug.
Remember that enums have copy-paste semantics. So, this is the
same as comparing literals from different modules. Apparently, in
the same module, a duplicate string literal is optimized out. But
that's not done across the module b
On 10/07/14 23:48, "Marc Schütz" " wrote:
Try other immutable variables (int arrays, structs), and non-immutable
ones. They will probably behave differently.
String literals are put directly in the executable and therefore should
be the same. Array literals are dynamically allocated.
--
/Ja
48 matches
Mail list logo