[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

/dpt/ - Daily Programming Thread

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 346
Thread images: 44

File: dpt_flat.png (102KB, 1000x1071px) Image search: [Google]
dpt_flat.png
102KB, 1000x1071px
Old thread: >>57017238

What are you working on /g/?
>>
First for Hardoop
>>
File: Capture.jpg (52KB, 347x356px) Image search: [Google]
Capture.jpg
52KB, 347x356px
def salary_sort(thing):
def importantparts(thing):
for i in range(1, len(thing)):
a=thing[i].split(':')
output = (a[1],a[0],a[8])
print(output)
return importantparts(thing)


So far my output looks like pic related, I want it to be sorted from highest numerical value to lowest however.

How would I achieve that using a lambda function?
>>
Any nice intermediate book on assembly programming (either in general of specifically about ARM (v6))?

I'm done a little bit of programming on MIPS and 8021 and I'm playing around on a raspberry pi now.
>>
fourth for the discord https://discord.gg/eG2Vk
>>
"You should not use the unsigned integer types such as uint32_t, unless there is a valid reason such as representing a bit pattern rather than a number, or you need defined overflow modulo 2^N. In particular, do not use unsigned types to say a number will never be negative. Instead, use assertions for this."
>>
>>57023127
what the fuck is the point of writing your function like that here
>>
>>57023135
No thanks, I'm socially awkward. No way I join this sort of things
>>
File: Capture.jpg (193KB, 919x481px)
Capture.jpg
193KB, 919x481px
>>57023173
It's homework
[spoiler];-;[/spoiler]
>>
>>57023169
Still doesn't give any reason to do so
>>
>>57023187
You are literally brainwashing yourself with unnecessary boring memes
>>
>>57023189
t. Programmer
>>
File: 2016-10-11-192537_644x660_scrot.png (14KB, 644x660px) Image search: [Google]
2016-10-11-192537_644x660_scrot.png
14KB, 644x660px
>perlfags, pythonfags and rubyfags find this acceptable
#!/bin/bash

# $1 'a's
input=$(printf "%$1s" | tr " " "a")
# $1 'a?'s followed by $1 'a's
regex="$(sed "s/a/a?/g" <<< $input)$input"

echo awk
time awk "/$regex/" <<< $input
echo

echo grep
time grep -E "$regex" <<< $input
echo

echo perl
time perl -wnE"say /$regex/g" <<< $input
echo

echo python
time python3 -c "import re; print(re.findall('$regex', '$input')[0])"
echo

echo ruby
time ruby -e "puts /$regex/.match('$input')"
>>
>>57023225
now do C++ D Ocaml Haskell Lisp
>>
how hard would it be to make a wm in c?
>>
>>57023273
I can't be bothered.
It's pretty much a case of "if it supports back references, it will be slows as fuck".
>>
How to get into verilog?
>>
>>57023390
isn't awesome written in c?
>>
>>57023483
What's not to get into
>>
>>57023169
Wrong. I have several cases in the code I'm working on where values do not exceed 65535, and are never signed. I represent them as uint16_t, so that I can do struct packing.
>>
Should I even bother learning angularJS if angular 2.0 is already out?

God I hate 2.0, why did they make this so much more complicated than it needs to be. object-oriented javascript is cancer
>>
>>57023509
My professor said to download quartus ii by altera. I can't tell if it's an ide, or what. And when I compile, I don't know what to expect, will it print a truth table to console or something? I find it overly complicated for my needs, like Visual Studio is.
I was just wanted to hear what people use to write verily programs, or what other resources they might recommend.
>>
>>57023535
>angular
fuck off >>>/g/wdg

you're right about OO though
>>
>>57023550
Well you compile 2 things, your testbench and your model. The testbench will run the code and give you output. Depending in your ide you can also look internally into your modules to see values.
>>
File: HFT-1.jpg (564KB, 1203x607px)
HFT-1.jpg
564KB, 1203x607px
Anyone have experience in high frequency trading and/or programming an automated trading algorithm?
>>
>>57023522
Hopefully you don't add them together
>>
>>57023177

Mate, there's only a couple of us in there. Just come on over and sperg out.

>>57023225

You're comparing feature complete programming langauges to a C program designed solely for doing regex parsing, and a very minimalist single purpose programming language.
>>
File: Capture.png (9KB, 1252x106px) Image search: [Google]
Capture.png
9KB, 1252x106px
Getting into Endless Sky development.
Speaking of which, somehow my mingw64 folder is completely empty.

Also I'm wondering if in GLSL, it's better to draw a circle with fancy math or a simple if statement.
If statements are slow I hear, but so is fancy math.
>>
>>57023623
>You're comparing feature complete programming langauges to a C program designed solely for doing regex parsing, and a very minimalist single purpose programming language.
That is no excuse for their regex implementations to be so slow. It's a case of those languages being fucking retarded and not following the CS literature,
Try running the script itself, with 50 as the argument. Post when it's done.
>>
>>57023623
>>57023177
plus nobody's even used the voice channels yet lmao
>>
>>57023593
There's no money to be made there unless you can afford space literally next to the exchange, it comes down to literal cpu cycles because everybody is trying to do the same arbitrage
>>
>>57023623
>>57023659
Just a frame of reference when passing a larger argument to my script.
You gotta love that exponential scaling.

I seriously don't understand how anyone can defend this or think it's a good idea.
>>
>>57023758
Scuse me as I just... ctrl+c that regex_benchmark.sh 50 process...
>>
>>57023504
i don't know
probably lua or something
>>
>>57023735
cpu cycles, latency, and bandwidth

>>57023593
I think a lot of hft work is done on FPGAs, but I have no idea about the algorithms involved
>>
>>57023758
defend what?
python is not designed for high performance, there's more to a programming language than speed benchmarks, otherwise everyone would be using assembly
>>
>>57023135
>Discord
All the cool kids start an IRC.

>>57023169
This is a matter of style - many feel that the type itself should alert one to what should or should not be done. Some will also say, "make objects easy to use correctly and hard to use incorrectly," noting that an unsigned integer literally cannot be negative. Unfortunately, it can still be assigned a negative value.
Also who are you quoting

>>57023522
>using std::uint16_t
Non-portable code. std::uint8_t, ..., std::uint64_t are not guaranteed to exist. Use std::uint_fast16_t or std::uint_least16_t instead.
>>
>>57023806
I think the plug-ins/extensions are in lua but the actual core is c.

>>57023735
https://en.wikipedia.org/wiki/Tradebot
5% of total stock market trading, based in Kansas City
>>
>>57023827
It's a quote from Google's c++ style guide
>>
>>57023853
Google's C++ style guide is shit, FYI.
>>
>>57023827
>All the cool kids start an IRC.
I started one ages ago and nobody fucking joined except for Ruby
>>
Ruby will burn time like no tomorrow if you use /a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/ as a regex, but seems to get some decent performance if you use /a?{50}a{50}/ instead... which is the same regex, just expressed differently.
>>
>>57023857
It's hard to make a good style guide for a shit language
>>
>>57023824
>defend what
Defend using an algorithm which scales exponentially in the worst case when extremely efficient quadratic algorithms exist.
There is a difference between "not caring about performance" and "being fucking retarded".

Just look at this chart. Source: https://swtch.com/~rsc/regexp/regexp1.html
Note the logarithmic scale of the Y-axis.
>>
>>57023873
1v1 me

also let's here your complaints. last time i got into with a guy he was whining about having to remember semicolons. do you have anything better to ask for?
>>
Hmm
GLSL is tricky mathematically, and I suck at math.
Unless I put time through a modulus, it quickly gets too large and floating point errors occur.
But if I put it through a modulus, few things can have a seamless loop.

Any ideas how I can make clouds radiate away from a point?
>>
>>57023827

If I remember correctly, the fixed width types are guaranteed to exist on any platform where they can exist. So you won't see uint16_t on any 36 bit platform, but will on any 16 bit, 32 bit, or 64 bit platform (except for Tru64 Unix on the DEC Alpha)
>>
>>57023892
http://en.cppreference.com/w/cpp/types/integer
>Provided only if the implementation directly supports the type
>>
>>57023875
okay, so why not implement the better algorithm
and log it in the bugtracker?
>>
>>57023881
I just want a typing system that's not completely garbage.
>>
>>57023913
Why is it garbage?
>>
#!/bin/bash

# $1 'a's
input=$(printf "%$1s" | tr " " "a")
# $1 'a?'s followed by $1 'a's
regex="$(sed "s/a/a?/g" <<< $input)$input"

echo awk
time awk "/$regex/" <<< $input
echo

echo grep
time grep -E "$regex" <<< $input
echo

#echo perl
#time perl -wnE"say /$regex/g" <<< $input
#echo

#echo python
#time python3 -c "import re; print(re.findall('$regex', '$input')[0])"
#echo

echo ruby
time ruby -e "puts /a?{$1}a{$1}/.match('$input')"


Produces

rubyist@Overmind:~/scratch$ ./regex_benchmark.sh 50
awk
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

real 0m0.018s
user 0m0.000s
sys 0m0.004s

grep
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

real 0m0.006s
user 0m0.000s
sys 0m0.000s

ruby
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

real 0m0.059s
user 0m0.044s
sys 0m0.000s


Not perfect, but not nearly as terrible, so long as the regex is written in a way that, I guess, Ruby can optimize around.

Hopefully 3.0 will fix the issue for the other regex.
>>
>>57023910
It's because they support backreferences, and those cannot be implemented on a state machine.
Backreferences are actually more powerful than normal regular expressions, but that power comes at a huge computational cost in the worst case.

Regular expressions are a good example of good computer science leading to good programs.
Then it became a good example of ignoring computer science leading to bad programs.
>>
>>57023919
>You can bit shift int
>It lets you input negative numbers into functions with unsigned int arguments
>No range definitions
>People simulating positive range with the dangerous unsigned int
>>
>>57023187
can you text post the input pls
>>
File: output.webm (3MB, 320x568px) Image search: [Google]
output.webm
3MB, 320x568px
r8 the background effect
>>
>>57023974
>You can bit-shift int
This is not a bad thing, especially when you're bit-packing and want to avoid the non-portable use of bitfields.

>It lets you input negative numbers into functions with unsigned int arguments
Hard to defend that one, but most modern compilers will warn you about it.

>No range definitions
I'm not entirely sure what you mean by this. Have you heard of range-based for-loops? The following code compiles:
for (auto val : {5,6,7,8,12,2345})
std::cout << val << '\n';

I think that's what you're looking for. Also, C++17 is going to buff up range-based for-loops even more.

>People simulating positive range with the dangerous unsigned int
All the cool kids use std::size_t to simulate positive ranges, and you're overstating the inherent dangerousness. If you end up with a negative value somehow when you're iterating over a positive range, that's a problem with your design.
>>
>>57024075
"Not touhou"/10
>>
>>57023827
>Non-portable code. std::uint8_t, ..., std::uint64_t are not guaranteed to exist. Use std::uint_fast16_t or std::uint_least16_t instead.
C++ is non-potable.
>>
>>57023930
reading about this shit is way above my head

awk and grep are written in C, which are a class of automata above python and the rest?
C is pushdown automata while Python is a finite state machine?
>>
>>57024077
Bit packing should be a standardized feature. You shouldn't need to use bit shifts to pack a value.

I was talking about constraining valid variable ranges.

Size_t is just a renamed unsigned int. And it's pretty dangerous if you add or subtract more than 1 from an unsigned value. God forbid you multiply one.
>>
>>57024163
>And it's pretty dangerous if you add or subtract more than 1 from an unsigned value. God forbid you multiply one.
What nonsense are you talking about? If there is such a danger then it is even more prevalent with signed integers.
>>
>>57024082

This desu. Anyone can make a scrolling shooter. Only Zun can make a good one, however.
>>
>>57024199
>talking shit about gradius or the watch mini-game in Spy Fox
>>
>>57024147
The language of implementation isn't important at all. It's just to do with the algorithm itself that implements the regex.
You could write a DFA algorithm in brainfuck and it would still scale better than the perl/python/whatever one.

If you look at the Chomsky hierarchy (https://en.wikipedia.org/wiki/Chomsky_hierarchy), there are several levels of grammars, each with a corresponding automaton (i.e. computer) which can recognise it.
Regular grammars can be recognised by a FSM. This is really nice, because you can implement and execute FSMs extremely efficiently, so you can recognise regular expressions extremely efficiently.
However, the """regular""" expressions that perl/python/whatever implement are actually more powerful than regular grammars, because they support back references. There might be other non-regular shit they do too, but back references are the most obvious.
Since they are more powerful than regular expressions, they need a more powerful automation to recognise them, meaning we lose that extremely nice ability to implement them with FSMs.

This might be a little too much theoretical computer science, but the point is, FSMs are good, and back references kill FSMs.
>>
>>57024182
It's pretty easy to tell if an int representing a positive number overflowes from addition or subtraction since it becomes negative. Not so much for the unsigned counterpart.
>>
>>57024260
Wrong. If a signed arithmetic operation overflows the behavior is undefined in C++.
>>
>>57024232
So the algorithm is the automata?
And implementing the more powerful automata is drastically less efficient for smaller inputs?
>>
File: Udklip.png (1MB, 1366x768px)
Udklip.png
1MB, 1366x768px
I'm currently in the progress of making a rainmeter kinda deal in c#.
>>
>>57024271
In c yes, which is also complete trash. But on most hardware it's pretty well defined.
>>
>>57024298
Most hardware allows you to detect unsigned arithmetic overflow without overhead.
>>
>>57024312
I know
>>
File: sdf.png (451KB, 723x683px) Image search: [Google]
sdf.png
451KB, 723x683px
>>57024294
And may i add that it is fully costumizable
>>
quite proud of this little snippet

///CROSS PRODUCT CALCULATION

//Given 3 3d coordinates calculate height at any [X,Z] coordinate

int[] f = {0,0,0};
int[] g = {1,2,1};
int[] h = {3,0,1};

int[] a = new int[3];
int[] b = new int[3];
int[] c = new int[3];

a[0] = f[0] - g[0];
a[1] = f[1] - g[1];
a[2] = f[2] - g[2];

b[0] = h[0] - g[0];
b[1] = h[1] - g[1];
b[2] = h[2] - g[2];

c[0]=a[1] * b[2] - a[2] * b[1];

c[1] = a[2] * b[0] - a[0] * b[2];

c[2] = a[0] * b[1] - a[1] * b[0];

int d = c[0] * a[0] + c[1] * a[1] + c[2] * a[2];

Console.WriteLine(c[0]); //a
Console.WriteLine(c[1]); //b
Console.WriteLine(c[2]); //c
Console.WriteLine(d); //d

float answer = (float)((d - c[2] * .5 - c[0] * .5) / c[1]);
Console.WriteLine(answer);
>>
>>57024316
Looks neat.
>>
>>57024319
That comment makes no sense.
>>
>>57024283
>So the algorithm is the automata?
An algorithm is just a list of instructions for how to do something, so I don't really get what you're trying to say here.
If you're interested in learning about regex implementations, the series of articles I linked before (https://swtch.com/~rsc/regexp/regexp1.html) has a lot of good information.
>And implementing the more powerful automata is drastically less efficient for smaller inputs?
More powerful automata just harder to implement and may take more computational time.
For the regex (with back references) case, you can construct pathological regexs which will absolutely kill the algorithm in terms of performance, which a FSM implementation will handle just fine (which that linked article talks about).
>>
>>57024325
Thanks, it is my first acturally "good" project, i have made many programs over the years but this one is preaty nice
>>
>>57024163
Bit packing cannot be a standardized feature due to endianness and standardizing it now would break a lot of code. Bit-shifting isn't hard, just use that instead. In any case, your original complaint was just "bit-shifting" with no mention of bit-packing and I'm still not sure why you brought it up in the first place.
As far as constraining valid variable ranges though, you're complaining that the types given by the standard aren't given in some more obtuse way. Define your own type with that restricted variable range, it's super easy.
std::size_t is not just a renamed unsigned int. You don't know what you're talking about.
As far as your final point about the dangerousness of unsigned integral types goes, it seems like you've already had a discussion about that.
>>
>>57024341
Thank you, this is a good read thus far.
>>
>>57024339
oh, well cross product calculation is an incorrect title

as for the second bit

Imagine I have 3 points in space a few miles apart from eachother

They form a plane. If I wanted to find where this plane intersects a reference at 1,1 on earth (if we had a flat mapping system) I could plug in the 3 points I know in the sky and get precisely where that plane formed crosses directly above 1,1

I also suck at explaining stuff but whatever
>>
>>57023127
>>57023187
First off. Name your functions and variables legibly. Eg. `thing` -> `employees` I guarantee your teacher has some style guide. Read it. And if not, read https://www.python.org/dev/peps/pep-0008/

Second, to answer your question. If you have learned lambda expressions, this is easy.

employees = map(lambda e: e.split(':'), employees)
for employee in sorted(employees, key=lambda e: e[8]):
print(employee[1], [employee[0], employee[8])


It could probably be simplified further
>>
File: 1468619912939.jpg (36KB, 482x427px)
1468619912939.jpg
36KB, 482x427px
How do I get to the level where I can work on things in my own time instead of just doing uni assignments? I can never think of anything to make and anything I might want to is way too difficult for me. I just want to know how to get to the level where I can make stuff I want. I'm not bad at programming or anything, I get full marks easily in the shitty OOP and data structure assignments and things but I feel like I am not moving forward. I just want to make cool and useful things.
>>
Is hackerrank a good website? Is it worth trying to do some of their stuff even if they are all probably too difficult for me? Is there something better I could be doing?
>>
>>57024410
What language do you write in?
And what kind of stuff do you want to make?
>>
Could someone help me with an issue I have in Scheme please? Neither me or my teacher (I know...) can find the solution to this:

;; writes the word n times
(define (copies n word)
(if (= n 0)
""
((print word)
(copies (- n 1) word))))

As said in the comment, it is meant to write n times the second argument. For some reason, Racket (I don't have any other interpreter on my current machine) tells me that:
 [name of my file]: application: not a procedure; expected a procedure that can be applied to arguments
given: #<void>
arguments...:
>>
>>57024406
First line should be
employees = map(lambda e: e.split(':'), employees[1:])
>>
>>57024415
I'm best with C++ but could easily go back to python or java. I don't really know what I want to make which is kind of a problem but most of the things I'd probably make would be GUI applications which seems really annoying to do in C++ so maybe I shouldn't use it for those things.
Maybe a program where I can easily pick and select images form a 4chan thread to download and save them easily, if I think of something off the top of my head. I'm not really sure
>>
File: japanimebymichaelbay.webm (3MB, 864x480px) Image search: [Google]
japanimebymichaelbay.webm
3MB, 864x480px
/dpt/-chan, daisuki~

>>57024425
shouldn't you use a (begin ...) in the if expression ?

>>57024414
https://leetcode.com/

>>57023390
~50 lines of code
https://github.com/mackstann/tinywm

>>57023169
It's rare when you need a uint32 over a int32 since they holds the same number of digits. uint32 is usually used for addresses and bit manipulations.

>>57023135
What's that ?

>>57023130
Professional Assembly Language is the reference for x86. Dunno for arm.

>>57023127
build a list with all tuples then
list.sort(key = lambda x: int(x[2]))
to sort the list based on the third element of each tuples converted to int

>>57023079
Thank your for using an anime image.
>>
>>57024438
If you want to make a lot of GUI applications, then you should try using c# instead.
>>
>>57024366
I didn't bring up bit packing. Also other languages have standardized packing.
>>
>>57024425
>Neither me or my teacher (I know...) can find the solution to this:
Haha fuck, drop out if they let literal retards teach you. I seriously hope you're not paying for that 'education'.
>>
>>57024452
>/dpt/-chan, daisuki~

>shouldn't you use a (begin ...) in the if expression ?
I haven't yet heard of it, I'll take a look at it.
>>
File: Capture.png (1KB, 341x34px)
Capture.png
1KB, 341x34px
>>57024366
>>
>>57023169
x86_64 has implicit zero extend for 32->64 bit registers so using unsigned 32 bit over signed 32 bit leads to smaller code in most cases (no rex prefix for the 8 old 32 bit regs, less sign extend instructions)
>>
>>57024489
>Hurr an unsigned int is size_t in my implementation so the standard must have mandated it that way
Again, you don't know what you're talking about.
>>
>>57024467
The teachers are good overall here, except this one (I've already corrected him a couple of times during his career in three weeks), and no I'm not paying for education
>>
>>57024489
>32 bit in the current year
post history discarded
>>
>>57024509
Also the other students here are pretty impressive
>anon-kun, could you help me with this?
>since, so create a new file and...
>how do I create a new file?
>...
>>
File: when_anime_eat_pizza.webm (3MB, 800x450px) Image search: [Google]
when_anime_eat_pizza.webm
3MB, 800x450px
>>57024484
Begin allows to have multiple expression as one

(begin <exp> <exp> ...)

The value of the last expression is then returned.

In your code, you have

 ((print word)
(copies (- n 1) word))


Which does mean that you want to call a procedure returned by (print word) with the value returned by (copies (- n 1) word) as argument. begin fixes that

(begin (print word)
(copies (- n 1) word))


note that some expressions in scheme have an implicit begin.
note that racket and scheme are not really the same programming language.
this will help for scheme https://ds26gte.github.io/tyscheme/
this will help for racket https://learnxinyminutes.com/docs/racket/
>>
>the best first programming language to learn computer science is Python

ignore this post if true
>>
>>57024507
Really making a good argument on how good of a type system c/c++ had.
>>
>>57024587
FUCK OFF ANON
PURE FUNTIONAL LANGUAGES ARE THE BEST WAY TO LEARN ACTUAL COMPUTER SCIENCE
>>
IONIC boyz, why i cant load angular, tell me why
>>
>type size_t = Int32
Show's how good of a type system Haskell has.
>>
>>57024545
Thank you very much!

>note that racket and scheme are not really the same programming language.
I know, but alas that's the only interpreter we have on our machines at uni, I hope both will be compatible enough

Still, thanks for your help, and I'll check out these links.
>>
>>57024612
rtfm
>>
This thread brought to you by Ada. Supporting all of >>57023974 and overflow detention since 1983. And recently packing, as some would put it, an importable feature. ;^)
>>
>>57024594
I've addressed the stuff you've said as best as I can. You're making an issue now out of something that was not in your original complaints either; hopefully this means your original complaints have been assuaged.
But you've been making ignorant posts for the majority of this chain, and while I've tried to help you out, some of the things you said are downright stupid and probably symptomatic of a deeper-rooted, irrational disdain for the language.
For example, you're now insinuating that std::size_t being implementation-defined is a point for why the type system of C++ is bad. But why don't we take a look at why this is? Straight from the reference:
>std::size_t can store the maximum size of a theoretically possible object of any type
Sounds to me that, given the platform-dependent purpose of std::size_t, an implementation-defined solution is the best bet. Sounds like this is an argument for why C++ has a good type system.
Perhaps C++ has a bad type system, but you've given no good reason as to why it does.
>>
>>57024692
That was my only legitimate shitpost itt. Any idiot could make a pretty accurate guess of what size_t is defined as in the standard. I said that because arguing what exactly size_t is unimportant since it's almost definitely going to be a typedef of some unsigned int. Also I didn't even bring it up either.
>>
>>57024625
>using signed integers for size_t
absolutely haram
>>
File: dad_of_the_year.webm (2MB, 1335x720px) Image search: [Google]
dad_of_the_year.webm
2MB, 1335x720px
>>57024670
>ada
>overflow detection
ariane flight 501

>>57024628
>Thank you very much!

No need to thank, the /dpt/ community is welcoming and respectful to all participants. We focus on helping to resolve issues and learning from mistakes, programming literacy is too precious not to share.
>>
>>57024731
>damage controlling this hard
>>
>>57024692
>Sounds to me that, given the platform-dependent purpose of std::size_t, an implementation-defined solution is the best bet.
I don't even.
>>
>>57024783
Show me the post where I brought it up. Some idiot(probably you) said it's what people use instead of unsigned int. Too bad on almost all implementations it's a typedef of unsigned int or long unsigned int.
>>
>>57024760
>Arian flight 501
I'm surprised you admitted you don't understand engineering and exactly what happened.
>>
>>57024760
>the /dpt/ community is welcoming and respectful to all participants
Ha! No we're not.
We do like to help when we can though.
>>
>>57024817
i know very well what happened since i have read the original reports (i am fluent in french)
>>
>>57024845
Zut alors!
>>
I feel like ncurses is the only gui library a leenux user should learn
>>
>>57024845
Then you know they turned off checking for a set of variables? That's not Ada's fault.
>>
>>57024861
I feel like your mom is the only gui library a leenux user should learn.
>>
>>57024862
they turned off because the said checks are slow and a pain in the ass. That's one of the biggest issues i have with Ada; it's so overly engineered that everything in that language is painful; you always turn to use pragmas to get rid of those damn constraints. at the end, you keep none of the advantages of the language but still all its crap. programming in ada is like programming handcuffed.
>>
>>57024804
>Show me the post
>Implying you won't just go "t-that wasn't me"
>>
>>57024898
t. Someone who's never used it.
They turned them off because they proved they won't overflow on the Arian 4 and they didn't want to overload the cpu. They forgot to check for the 5, which indecently would overflow the variables.
>>
File: you.jpg (114KB, 1204x680px) Image search: [Google]
you.jpg
114KB, 1204x680px
>>57024912
If you didn't jump in halfway through you would know who brought it up.
>>
ded fred
>>
Anyone ever want to program stuff but then not feel like programming?
>>
>>57025294
me right nonj
>>
>>57025383
>nonj
*now
>>
what's our guy steve yegge up to
>>
>>57024319
Please learn to comment and name variables correctly
>>
Which is better as a lightweight GUI toolkit, ImGUI or Nuklear ?
>>
>>57025485
eh, a b c and d are the actual names you're supposed to use in the formula so I'm not terribly beat up over it
>>
if I were to have a struct within a struct like this
struct thing {
struct childofthing {
int a; //contents
int b; //contents
}
}


is it a good idea to have a pointer to the structs parent, like this:
struct thing {
struct childofthing {
struct thing *parent; //parent of childofthing
int a; //contents
int b; //contents
}
}

???
>>
>>57023225

I think for Python you are also measuring the complete time (with the "import" statement), not only the actual regex search..

But still, I couldn't believe it and tested it myself:

require 'benchmark'

input = 'a'*30
reg_ex = Regexp.new ('a?'*30 << 'a' * 30)

Benchmark.bm do |bm|
bm.report { reg_ex.match input }
end



Seems your test was right, but nevertheless, what does this prove?

Awk was the "inspiration" for Perl, (just like Bash was the "inspiration" for Python), but Perl/Python/Ruby are much more powerfull.

Awk is a "special purpose" tool, it's not a full-fledged power scripting tool. Yes, low level coding beats dynamic languages, just like a ferrari beats an SUV in speed. But if you drive through the rovky mountains maybe you will prefer the SUV though..?
>>
>>57025648
unless you're planning to pass the child struct directly to functions then no
you shouldn't anyway, just always pass thing and dereference the child instead
>>
>>57025678
>unless you're planning to pass the child struct directly to functions
I am since I have functions to allocate and initialize each of the child structs in my main struct

I could either pass the parent as a separate argument into the function, or I have an extra member as a pointer to the parent.
I was wondering which method was better
>>
>>57025648
>is it a good idea to have a pointer to the structs parent, like this:
No
>>
>>57025723
why
>>
>>57025728
Because the address of the parent is not fixed and can easily be calculated from the address of the child.
>>
>>57025737
>calculated from the address of the child.
using the cast from 0 method?

sure, but what if my struct hierarchy is more than two layers deep? How would I get to the main struct (which has some 'global' info that all the children need) from say 6 children deep?
>>
Where do i start learning about machine learning? Any books/articles/blogs /g/ can recommend?

I'm not a novice to software development but i'm still just a junior front end dev
>>
>>57024452

Hate to be that guy, but which anime is that?
Kinda want..
>>
>>57025675
>I think for Python you are also measuring the complete time (with the "import" statement), not only the actual regex search..
That is negligible compared to the regex search itself.
>Seems your test was right, but nevertheless, what does this prove?
It proves that the algorithms for regexes that many popular programming languages use is complete garbage, and scales exponentially.
There is NO reason to use an O(2^n) algorithm when an O(nm) algorithm exists. This isn't a case of "python being kind of slow". I'm talking about inputs that will take literally hundreds of years to complete.
It's like having your language's sort function be implemented with bogosort or something.
>Awk is a "special purpose" tool, it's not a full-fledged power scripting tool. Yes, low level coding beats dynamic languages,
This has absolutely nothing to do with the languages. It's to do with the algorithm. Recursive backtracking is a shit algorithm, even if you implemented it with perfectly optimised assembly. But if you drive through the rovky mountains maybe you will prefer the SUV though..?
>just like a ferrari beats an SUV in speed
Car analogies are the cancer of computing.

I have more discussion about this in some of my other posts. Follow the reply chain.
>>
>>57025766
The same way.
>>
>>57025806
>>But if you drive through the rovky mountains maybe you will prefer the SUV though..?
I pasted that sentence into the wrong place. Ignore that.
>>
C is like a custom-tuned car form the 50s, but python is a ferrari with automatic shifting
>>
>>57025792
it's a movie
https://en.wikipedia.org/wiki/Royal_Space_Force:_The_Wings_of_Honn%C3%AAamise
the animation of the explosions is impressive, especially when you know that they were made by hand without any computer assistance.
>>
>>57025829
>Python
>Ferrari
More like a full option medium priced skoda or some shit.
>>
>>57025848
The art in that movie is elder god tier.
>>
>>57025848
That was certainly a strange film.
>>
>>57025588
Then explain it through comments mate
>>
File: maxresdefault.jpg (352KB, 2000x1120px)
maxresdefault.jpg
352KB, 2000x1120px
>>57025829
>python
>ferrari
top kek, more like this
>>
>>57025806

>It proves that the algorithms for regexes that many popular programming languages use is complete garbage, and scales exponentially.

Well, most RegEx searches are not "aa??a?a?.." if you know what I mean. You are optimizing at a part which is not critical (or even important) for most programms. And if you really have a special purpose programm, i.e. doing a full-text search for code plagiatism..

Well, in Ruby you can simply use a differnt RegEx generator (i.e. "re2") and include it as gem. Or you could also just call awt directly:

result = %x ( 'awk /' + reg_ex + '/ ' + input )


>I'm talking about inputs that will take literally hundreds of years to complete.

You're are asking about a very special topic, I don't know why chose a certain engine or not. If it bothers you, open a request on GitHub or something...

>Recursive backtracking is a shit algorithm

There is never a silver bullet in computing, each option has pros and cons.

In other words:
I can easily create an (artificial) exmaple which makes a language look bad or good, depending on the parameters. "Lying with statistics" 101..

The bottom line is:
You are right, but it's just not important.

If you feel like getting into this kind of stuff, here are further optimizations:
>http://engineersamuel.github.io/dbits/blog/2013/10/16/speeding-up-ruby-regular-expressions/
>>
>>57025848

Thanks so much!
>>
>>57026020

Sorry, messed up the code exmaple a little bit.. Anyway, you get the point.
>>
OSDev Anon here, I just finished FAT12 support for my operating system. It doesn't support file extensions yet but it will soon. https://github.com/Penot1/FutureOS
>>
>>57026020
>Well, most RegEx searches are not "aa??a?a?.." if you know what I mean
Yes, it's a pathological regex designed to fuck with the algorithm. However, the "correct" algorithm has no such cases and runs in a predictable time.
I seriously don't understand how you can try to defend O(2^n) algorithms.
>There is never a silver bullet in computing, each option has pros and cons.
For regular expressions, there are much better algorithms. Read the fucking article I linked in my other posts.
>I can easily create an (artificial) exmaple which makes a language look bad or good, depending on the parameters. "Lying with statistics" 101..
There is no case where a DFA algorithm will go exponential.
>You are right, but it's just not important.
How is good algorithm design not important? I would probably consider it the most important thing.
>http://engineersamuel.github.io/dbits/blog/2013/10/16/speeding-up-ruby-regular-expressions/
You don't need to "optimise" regular expressions on a DFA. What you have there is a shitty crutch for your shitty algorithm.

Seriously, some of you fags need to learn some computer science.
>>
>test passes
>copy paste test code into main, right at the start
>code doesn't work
Well this is fucking dumb. What was the point of the test then? How do I even fix this... fuck.
>>
>>57026140
What error are you getting?
What have you tried?
What is the code in question?

What the fuck is the point of this post?
>>
>>57026098

>I seriously don't understand how you can try to defend O(2^n) algorithms.

I just don't know enough about the topic. There has to be a reason for this, because people are not stupid and if there was a way to speed up RegEx without any disadvantage, they would have chosen it. Common sense, right?

>For regular expressions, there are much better algorithms. Read the fucking article I linked in my other posts.

Still give no insights about the "why"..
Java, Ruby, Python.. they run more than half of the internet sites, so if there was a "free lunch" they would have taken it. Especially Java.

>Seriously, some of you fags need to learn some computer science.

You don't knwon the reasons yourself, right?
So what did you want to prove? That the majority of programmers is just too supid to chose the correct algorithm? There's a metric fuckton of money that was put into Java and some considerable effort for Ruby and Python, so there is definately a reason for that (even if we both don't know).

Thangs aren't always as simple as they may seem.
>>
thoughts on this?

https://zedshaw.com/2015/01/04/admitting-defeat-on-kr-in-lcthw/
>>
>>57026207
I think there is a 10000 word blog post showing that Zed Shaw doesn't know anything about C.
>>
#defines only work in their translation unit right?
they aren't global?
>>
>>57026157
>What error are you getting?
None, the DB just goes to execute the statement and the thread locks.

>What have you tried?
Don't even know where to begin. Can't debug the test to see what's different because of this retardation: https://github.com/go-lang-plugin-org/go-lang-idea-plugin/issues/1855

>What is the code in question?
        localDB, err := sql.Open("sqlite3", filepath)
if err != nil {
log.Fatal(err)
}
if localDB == nil {
log.Fatal("no db")
}

sqlTable := `
CREATE TABLE IF NOT EXISTS users(
Id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
Username TEXT
);
`
_, err = db.Exec(sqlTable)
if err != nil {
log.Println(err)
}


>What the fuck is the point of this post?
Just wanted to complain is all.
>>
>>57026179
>I just don't know enough about the topic
It's to do with the scaling on the size of the input in the worst case.
Compare my images in >>57023225 and >>57023758 for an increase in 1.
>if there was a way to speed up RegEx without any disadvantage, they would have chosen it
Right, they should.
There is one "disadvantage" (Not really, because they're useless), where you cannot implement back references on a state machine. They should do what grep does and use a DFA if back references are not present, and fall back to recursive backtracking otherwise.
Or just not support back references because they shit. Back references aren't even regular, and show a flaw in the way some people think about regexes.
>Still give no insights about the "why"..
Because they're stupid. No, really.
People added all sorts of stupid features to regular expressions (no longer making them regular), for which there is no known efficient implementation (and is NP-complete), and they can't remove them for backwards-compatibility reasons.

>>57026221
Right.

>>57026207
It's just that hack being butthurt. You should really ignore that guy, he doesn't know anything.
>>
>>57026250
Made a mistake while copypasting, db.Exec is of course localDB.Exec
>>
Is structured programming a meme?
>>
>>57026293
wat
>>
>>57026331
https://en.wikipedia.org/wiki/Structured_programming
>>
>>57026293
Everything is a mem if you force it hard enough.
>>
>>57026207
Well, Zed Shaw's a terrible teacher and has no business writing Learn [X] the Hard Way (who the fuck thinks that endless print statements are the way to teach people?) but there's some truth to the man:

>They talk all day long of how, “We’re all in this together” but if you don’t bow to the great altar of their vast knowledge and beg them for permission to question what they believe you are suddenly the enemy.

For instance, StackOverflow is absolutely abysmal as anything more than an intelligence archive at this point for a laundry list of reasons; new users can't be assed to write properly/politely and provide a code snippet, old users can't stop sucking 200 dicks for their daily ego boost, etc. It's generally the same for all of the StackExchange websites where you can tell who's using the site for internet karma points based on whether or not you can remember someone's username (i.e., there's some "lillenthal" guy I see on every other question """upholding rules""" for points) that isn't someone published like Jon Skeet.

But then you come to the line

>But C? C’s dead. It’s the language for old programmers who want to debate section A.6.2 paragraph 4 of the undefined behavior of pointers. Good riddance.

and you just start fucking laughing because you realize that Zed Shaw is a monkey.
>>
File: 1453303001612.png (362KB, 700x700px)
1453303001612.png
362KB, 700x700px
>>57026394
>section A.6.2 paragraph 4
What? The standard isn't even structured like that.
Unless he's referring to Annex A, but that's just a language syntax summary.

If you're going to try and insult people like that, at least make it correct.
>>
>>57026444
Hyperbole.
>>
>Prakash Kumar Singh

I can't wait for the rest of today to happen.

>>57023079
>What are you working on /g/?
If I told you, I'd have to kill you.
>>
Post your pajeetiest code
>>
>>57026820
private int[] SortThreeInts(int a, int b, int c)
{
return new int[]
{
Math.Max(a, Math.Max(b, c)),
Math.Min(Math.Min(Math.Max(a, b), Math.Max(b, c)), Math.Max(a, c)),
Math.Min(a, Math.Min(b, c))
};
}
>>
>>57026820
String line = br.readLine();
for (int i=0; i<result.length; i++) {
line = br.readLine();
index = line.indexOf(" ");
int number = Integer.parseInt(line.substring(0,index));
result[i] = number;
}
>>
Can /dpt/ calculate the average of two ints?
>>
>>57026986

int c = a + b
print (double) c / 2.0
>>
>>57026986
(a + b) / 2

My language implementation compensates for all potential issues related to averaging two ints.
>>
>>57027011
>int c = a + b
Retard alert.
>>
>>57026986
2 and 6

the average is 4
>>
>>57027023
>the average of 2 and 6 is 4
American math, everyone.

>>57023079
working on a kernel in C, the one true language.
>>
>>57027035
>American math, everyone.
Err.. what is the average of 2 and 6 in your universe?

>>57027011
doesn't handle overflow
>>
File: yp.webm (433KB, 640x360px) Image search: [Google]
yp.webm
433KB, 640x360px
>>57026986
int average (const int x, const int y) 
{
if ((x < 0) ^ (y < 0))
return (x + y) / 2;
const int xh = x / 2;
const int yh = y / 2;
const int xhr = x % 2;
const int yhr = y % 2;
return xh + yh + (xhr && yhr);
}
>>
>>57027020

It was pseudocode.


>>57027048

>doesn't handle overflow

I was using... ..uhm.. yes, Erlang.
So I don't have to worry about overflows.

:^)
>>
>>57026986
import intAverager
>>
File: 1465654935521.jpg (76KB, 500x751px)
1465654935521.jpg
76KB, 500x751px
I want to do something in C
gimme ideas
>>
The integers in my language spec can contain values greater than 2,147,483,647.

Checkmate.
>>
>>57027068
>average(-1, -1)
hmmm
>>
File: screen.png (3KB, 459x98px)
screen.png
3KB, 459x98px
>>57023079
rewriting the 4chan kernel in gopher
>>
>>57027129
Calculate the average of two ints.
>>
>>57027129

a Scala compiler
>>
>>57027129
Mobile application that uses the camera and determines if what you're pointing at is anime or not.

Bonus points for finding the source.
>>
>>57027144
>asking the impossible
>>
>>57027134
fixed
int average (const int x, const int y) 
{
if ((x < 0) ^ (y < 0))
return (x + y) / 2;
const int xh = x / 2;
const int yh = y / 2;
const int xhr = x % 2;
const int yhr = y % 2;
return xh + yh + (xhr & yhr);
}
>>
>>57027134
0?

they're integers, what do you expect?
>>
HelloWorld
>>
>>57023593
Kona would be worth looking at as a starting point, I've seen it used a few times for HFT stuff on the DB side of things.
>>
>>57027035
>>the average of 2 and 6 is 4
>American math, everyone.
African math everyone
>>
>>57027185
the average of -1 and -1 is -1 you retard.
>>
File: 1462665702455.png (54KB, 311x311px)
1462665702455.png
54KB, 311x311px
>>57027184
>returns an int
>>
File: 3pnkbuj.jpg (32KB, 720x405px)
3pnkbuj.jpg
32KB, 720x405px
>>57027238
what's the problem ?
>>
File: 1463936625812.jpg (89KB, 668x696px)
1463936625812.jpg
89KB, 668x696px
unsigned int x = 0;
x--;
printf("%d", x);
// x = -1
>>
>>57027251
printf is interpreting it as a signed int
you need to tell printf that it is unsigned
>>
>>57027251
lmao
>>
>>57027238
>>57027249
>Cute boys doing cute things
>>
>>57027251

literally why?
>>
>>57027251
>use the wrong formatting parameter
>blame the language
>>
File: 1454907903461.png (638KB, 4760x4986px) Image search: [Google]
1454907903461.png
638KB, 4760x4986px
>>57026820
>>
Instead of posting pajeetisms, post some great, insightful code that will make me think.
>>
>>57027347
It's a trap.

She's going to make fun of you, no matter what you post.
>>
>>57027365
>she
Humor value doesn't increase with repetition
>>
>>57027251
%u
>>
>Scalafags will defend this
>>
File: 1472387477368.jpg (74KB, 430x653px)
1472387477368.jpg
74KB, 430x653px
github or gitlab?
>>
File: zBb23so.jpg (172KB, 800x1195px)
zBb23so.jpg
172KB, 800x1195px
>>57027347
https://en.wikipedia.org/wiki/Duff%27s_device
>>
>>57026986
double avg = a + 0.5*(b-a);


>>57027068
wtf is going on here?
>>
>>57027407
both and bitbucket
>>
>>57027407
neither.

https://gitgud.io/
https://gitla.in/
>>
>>57027427
>
double avg = a + 0.5*(b-a);

"no"
>>
>>57027407
github for portfolio project
gitlab for private projects
>>
>>57027407

tfw will never be a qt thin female programmer wearing qt clothes instead im a fat white male who wears cargo shorts
>>
>>57026986

int a = 5,
b = 4;

double avg = (float)a + b / 2;

>>
File: 1443500977688.png (835KB, 1200x1080px)
1443500977688.png
835KB, 1200x1080px
>>57027456
>wearing qt clothes
it's not necessary to be a female for doing that.
>>
>>57027437
>>https://gitgud.io/
>associating with GG
>>57027470
That's undefined behavior.
>>
File: 1451607092658.png (257KB, 1920x1080px)
1451607092658.png
257KB, 1920x1080px
>>57027397
>>
>>57027485
exactly
>>
>>57027485
yep, that's expected
learn about binary numbers
you'll understand it when you learn how the bits flip
>>
>>57027485
Learn about the ring with 4294967296 elements.
>>
>>57027482
>associating with SJWs
>>
>>57027485
https://en.wikipedia.org/wiki/Integer_overflow
>>
>>57027516
>the
>>
File: hqdefault.jpg (17KB, 480x360px)
hqdefault.jpg
17KB, 480x360px
>python, lua, ruby, perl
>programming
>>
>>57027530
They're all isomorphic.
>>
File: 1460503769252.jpg (270KB, 450x600px)
1460503769252.jpg
270KB, 450x600px
How can I make my code more feminine?
>>
>>57027530
I don't know enough about ring theory to confirm or deny this.
>>
File: 1476120841677.jpg (107KB, 768x1024px) Image search: [Google]
1476120841677.jpg
107KB, 768x1024px
>>57027558
use Haskell
>>
>>57027558
Write shitty code.
>>
>>57027446
"yes"
>>
>>57024425
((print word)
(copies (- n 1) word))))


That looks like a function call, where the function is the result of (print word), which is probably not what you want. You probably want progn or the scheme equivalent.
>>
>>57027383
What did she mean by this
>>
File: 1453992003779.jpg (204KB, 1920x1080px)
1453992003779.jpg
204KB, 1920x1080px
What's the name of this kind of program that recovers urls from sites? Web scrapper?
>>
>>57027593
dumb phoneposter
>>
>>57027599
>Tatami Galaxy
patrician taste
>>
>>57027539
it's a power of 2 -- already there are four rings of order 4. you probably know three already: Z/4, Z/2 x Z/2, and the field with 4 elements. i think there are more if i don't require the ring to have a 1
>>
>>57027427
>wtf is going on here?
average of two int while avoiding overflow.
>>
>>57027628
nerd
>>
>>57027628
How do you construct a field with n elements where n is not prime?
>>
>>57027536

>what is ansible, puppet, chef, TACTIC, Metasploit, Bricolage, Rails, Django..
>>
>>57027663
https://en.wikipedia.org/wiki/Finite_field#Non-prime_fields

>>57027666
buzzwords
>>
>>57027666
>satan promotes scripting languages
well i dont need to say anymore i guess
>>
File: Kcj7opncq.png (186KB, 936x590px)
Kcj7opncq.png
186KB, 936x590px
>tfw not smart enough to understand >>57027628
>>
>>57027692
It's just basic abstract algebra really.
>>
>>57027687
I don't know enough about algebra to know if anything written there is actually true.
>>
>>57027663
lots of ways to do this from general principles. i could also just give you the multiplication table. the most compact way is probably to start with F_2 and find an irreducible polynomial of degree 2 over it. in this case there's only one: q(X) = X^2 + X + 1. take F_2[X] and impose q(X) = 0

you can play around with this in sage
http://doc.sagemath.org/html/en/reference/finite_rings/sage/rings/finite_rings/finite_field_constructor.html
>>
Is it worth to use unsigned instead of int for performance?
>>
>>57027752
what performance?
>>
>>57027752
STOP
>>
>>57026986
signed int_average(signed a, signed b)
{
unsigned sum;
signed avg;
int sign = 1; // sign of the average: 0 means negative, anything else is positive

if (a < 0 && b < 0) sign = 0;
else if (a < 0 && abs(a) > b) sign = 0;
else if (b < 0 && abs(b) > a) sign = 0;

if (sign) {
sum = (unsigned)a + (unsigned)b; // casting to unsigned since signed a+b may overflow
} else {
sum = (unsigned)-a + (unsigned)-b; // equivalent to "-(a+b)"
}

// the corner case: int_avg(-128,-128) = -(128+128)/2 = -0/2 in unsigned arithmetic!
if (sum == 0 && !sign) {
avg = a;
} else {
int odd = sum & 1; // equivalent to "sum % 2"
avg = sum >> 1; // equivalent to "sum / 2"
if (odd) {
avg++; // round away from zero
}
if (!sign) {
avg = -avg;
}
}

return avg;
}

Basically, using the property that avg(a,b) = -avg(-a,-b) if a+b < 0, so I can make use of the sign bit in unsigned arithmetic. The avg(-128,-128) case is a little bit special, though, but since their sum is unsigned, overflowing is that case is not undefined.
Maybe not the fastest implementation, but mathematically correct.
>>
File: 1475148896737.png (2MB, 750x1334px)
1475148896737.png
2MB, 750x1334px
Retard here, python is the only useful language I know, and I want to make a dynamic site. What's the best framework?
>>
>>57027760
>>57027763
I... Yes
>>
>>57027752
No, one of the other developers on your team might have put a check to see if the object is an unsigned int, and if it does, it sleeps the thread for 30 seconds.
>>
>>57027776
ASP.NET
>>
>>57027776
html5
>>
>>57027776
MVC.NET
>>
>>57027731
How curious.
>>
>>57027773
*by avg(-128,-128), that is, if you were calculating the average of two signed chars. Should read as "avg(INT_MIN,INT_MIN)" in the case of signed ints.
>>
https://open.kattis.com

for people who want problems
might be run by furries; not sure
>>
>>57026444
autist spotted
>>
>>57026986
// Note: This function has a significant margin of error
int avg(int a, int b)
{
return (rand() % (a + 1 - b)) + b
}
>>
So, what color skirt should I buy if I want to maximize critical thinking?
>>
>>57027852
watch rust conference videos to find out
>>
>>57026986
(int)((double)a+(double)b)/2

Nuh uh, I won't use patented code.
>>
>>57027852
black/red checked
>>
>>57027852
Stop false flagging, normie.
>>
>>57027870
That's undefined behavior senpai.
>>
>running nonfree javascript
>>
>>57027886
>running javascript
>>
>>57027877
Are you retarded? Little fix:
(int)(((double)a+(double)b)/2)
>>
>>57027905
That's still undefined behavior.
>>
>>57027913
Casting is defined behavior. Maybe you're confusing it with reinterpreting, in either case you're wrong.
>>
>>57027913
it's not
>>
>>57027935
>Casting is defined behavior.
If an integer is cast to a floating point value and the integer lies outside the (real) range of representable values, the behavior is undefined.
>>
I wanted to program a bit today but I'm tired and my penis is erect right now.
>>
>>57027950
When does int lie outside of double's range?
>>
>>57027950
>casting double to int is undefined behavior

You are noise. Paying attention to you is detrimental to mental well-being.
>>
>>57027950
That's loss of precision, not UB. And even then it shouldn't happen with casting ints into doubles
>>
>>57027950
Floating point is ALWAYS outside of integer's range. But it can have less meaningful digits, which is not the case in my code.
>>
#include <iostream>
#include <cmath>
using namespace std;
int main(){
double x0; //point start
double x1; //point end
double y; // total area
double z; // step size
double y0, y1;
double e= 2.7182818;
cout << "Enter start x: ";
cin >> x0;
cout << endl << "Enter end x: ";
cin >> x1;
cout << endl << "Enter step size: ";
cin >> z;

for (double i; i=x0, i<x1, i+=z;){ //doesn't like that I declare a double, but if I need to increment by z, a decimal, Im fucked


y0=x0*pow(e, x0)*sin(x0);

y1=x1*pow(e, x1)*sin(x1);

y=(x1-x0)* ((y1+y0)/2);

}

cout << "Area estimate from "<< x0 << " to " << x1 << " = " << y;
return 0;
}

trying to make trapezoid rule integration program, one line keeps failing and Im not sure why...
>>
>>57027979
When int is a very large type.
>>57027988
No, it's undefined behavior. If you open your copy of the C standard you'll find that it explicitly lists this as a case of undefined behavior. Maybe you're thinking of cases where the integer still lies in the range of represnentable values but cannot be represented exactly.
>>
>>57028004
The reason, of course, is that you forgot to use code tags.
>>
>>57028070
What that is?
>>
>>57028095
https://www.4chan.org/rules
>>
>>57028095
read the sticky
>inb4 "what's the sticky?"
>>
>>57028004
>
for (double i; i=x0, i<x1, i+=z;)
>>
>>57028004
I don't know about the maths behind this, but your "for" loop declaration seems a little wonky to me.

for (initial statement; condition; increment) {...}

Your condition
 i=x0, i<x1, i+=z
doesn't check much, it will be always true.
>>
Does someone know why microsound is using escape(c) instead of escape[c]?

https://github.com/microsounds/akari-bbs/blob/master/src/utf8.c
const char *const escape[UCHAR_MAX] = {
['\n'] = "&#013;", /* change '\n' to '\r' */
['\"'] = "&quot;",
['\''] = "&apos;",
['<'] = "&lt;",
['>'] = "&gt;",
['&'] = "&amp;"
};


Also, how do you call those kind of char maps?
>>
>>57028095
Lurk moar, you dumb fucking faggot.

>>57023079
Why are enterprise tools so expensive?

I just got off a call for an ETL stack I need for my project, and they were proud that they were $300,000 less than the last client expected.

They were not amused when I replied
>That's great! I was expecting the monthly to be around $301,000, so this should work out just fine.
>>
>>57028154
>Also, how do you call those kind of char maps?
Array
>>
>>57028006
Man, I wish I had an NSA machine like you, with 2048-bit ints so they can lie outside of the range of doubles
>>
>>57028181
Maybe if we start making assumptions we can end the meme once and for all with
int avg(int a, int b)
{
return (int)(((long long)a + (long long)b) / 2);
}
>>
>>57028203
>long long
fuck off
>int result
fuck off
>>
>>57028154
>escape(c)
how does this even compile
>>
>>57026986
template <typename  T>
inline T avg(T &a, T &b) {
return (a+b)/2;
}
>>
>>57028232
>I have no idea what I'm doing!
>>
>>57028232
I don't even.
>>
>>57026986
avg :: Integer -> Integer -> Integer
avg x y = (x + y) `div` 2
>>
>>57028154
>>57028229
#define escape(c) escape[(unsigned char) (c)]

In utf8.h
>>
>>57027690

go away, terry.
>>
>>57028232
You should have added:
>with "+" being a properly overloaded binary operator that insures that "a+b" is defined for every value of a and b in T
There you would be correct.
>>
>>57028313
>overloading int::operator+
I don't even.
>>
>>57028333
int doesn't have a well-behaved operator+ so that remark doesn't apply
>>
File: smug bateman.jpg (62KB, 600x327px) Image search: [Google]
smug bateman.jpg
62KB, 600x327px
>>57028333
And yet you can. Sepples is magic.
>>
File: 53794.png (31KB, 402x297px)
53794.png
31KB, 402x297px
any qt devs here? im about to create context menu with two sides, just like pic related, how am i supposed to do this? theres no such thing build in, should i create my own menu from scratch?
>>
>>57028358
>can /dpt/ average two ints
>here is a solution that works for some types but not int
hmmm
>>
>>57028361
>any qt devs here?
I wish ;_;
>>
>>57028361
make it from scratch
>>
>>57028156
>not knowing the rules of some obscure chink board is lacking intelligence
have a tampon
>>
>>57028378
well, you finally got your answer
>>
https://github.com/microsounds/akari-bbs/blob/master/src/utf8.c#L225-L228

I don't even.
>>
File: 1451373267878.png (129KB, 314x278px) Image search: [Google]
1451373267878.png
129KB, 314x278px
>>57028313
T-This?

inline int operator +(int &a, int &b) {
return a+b;
}


sorry anon, i feel stupid.
>>
>>57028400
>implying you can write safe code in C
>>
>>57028361
Yeah just create a custom widget.
>>
>>57028422
Maybe you can't. But I'm a cute girl.
>>
>>57028361
I just realized you were talking about the Qt GUI framework, and not cute humans.
>>
>>57028400
yeah the author of that code is a big shitter
it's not a news really
>>
>>57028422
>he can't write safe C code
>>
>>57028463
>he
>>
>>57028154
It's a lookup table (LUT). Most of the table is empty, but lookup is O(1) with the only constant being pointer dereferencing
>>
Anyone here familiar with kNN with kd-trees?
So you go to a target by traversing the tree, and that's cool.
But what if the target is an inner node (because the median is set to be the element at the node, and its leaves are whatever's left or right of the median)?
A lot of people say you should at this point, start unrolling and checking other branches of the tree, but why wouldn't you go further down the tree?
>>
>>57028468
protip: it would still be O(1) even if she didn't use a lookup table.
>>
>>57028463
How do you write safe C, aside from writing Clight and compiling using CompCert or something?
>>
>>57028475
greater constant though
>>
>>57028508
>safe
>C

Pick one. You don't.
>>
>>57028361
specifically qt4/5? I'm only a qt 3.14 dev
>>
>>57028519
That's what she said.
>>
>>57028508
How do you write safe X if you haven't verified that the compiler doesn't contain a backdoor?
>>
>>57028529
What do you mean by "safe"?
>>
>>57028529
>CompCert is a compiler that generates PowerPC, ARM and x86 assembly code from CompCert C, a large subset of the C programming language. The particularity of this compiler is that it is written mostly within the specification language of the Coq proof assistant, and its correctness --- the fact that the generated assembly code is semantically equivalent to its source program --- was entirely proved within the Coq proof assistant.
>>
>>57028533
Safe from the NSA and Russian Hackers.
>>57028543
Does Coq have an NSA backdoor?
>>
/!\ A L E R T /!\

New thread

>>57028549
>>57028549 >>57028549
>>57028549 >>57028549 >>57028549
>>57028549 >>57028549
>>57028549

/!\ A L E R T /!\
>>
>>57028533
What about "doesn't crash during runtime"?
>>
File: Selection_563.png (8KB, 361x92px)
Selection_563.png
8KB, 361x92px
>>57027214
Thread posts: 346
Thread images: 44


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.