[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
/dpt/ daily programming thread
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 255
Thread images: 15
File: dpt.jpg (198 KB, 720x720) Image search: [Google]
dpt.jpg
198 KB, 720x720
old thread: >>54630928


What are you working on, /g/?
>>
>>54638110
Who is this fluid druid?
>>
>>54638110
who is this testicle molester?
>>
Who is this cock dock?
>>
>>54638110
researching streaming using basic web languages (PhP, JS)
>>
File: 1453131105808.jpg (119 KB, 720x717) Image search: [Google]
1453131105808.jpg
119 KB, 720x717
>>54638131
>>54638169
>>54638180
>>
>>54638110
Is that a good book to learn how to use C in if i really know the syntax, have experience in c++, c# and coding in overall?
>>
>>54638209
that's not the original ya dip, the original has no hand
>>
>>54638131
>>54638169
>>54638180
just some camwhore
>>54638110
learning python
>>
Is this cum dump a photoshopped dude or what ?
>>
>>54638209
>Amateur game development general
That's an 8 board I haven't checked in a while. Thanks for reminding me.
>>
>>54638225
>he prefers girls without a hand
jesus, autism levels are through the roof
>>
File: 1443460001301.png (42 KB, 177x236) Image search: [Google]
1443460001301.png
42 KB, 177x236
New to programming here, how can I reverse a string without string.h?
>>
nothing
>>
>>54638243
It's a general in /vg/, you mong.
>>
>>54638258
Pajeet learn to solution first.
>>
>>54638258
That's a hard problem.
>>
>>54638258
select a pivot and xor swap
>>
How the fuck do I create a console application in C using this piece of shit Eclipse?.

>inb4 pajeet-tier retardery faggots.
>>
In the year 2016, does it ever make sense to use float instead of double in C?
>>
File: joy of php.jpg (54 KB, 400x567) Image search: [Google]
joy of php.jpg
54 KB, 400x567
>>
>>54638333
Yes, RAM is slow and float is smaller
>>
>>54638363
Can't a 64-bit CPU deal with it natively?.
>>
>>54638348
>joy
>>
>>54638363
Okay, with the exception of saving RAM (which is basically never an issue these days)?
>>
>>54638385
>which is basically never an issue these days
RAM is slow, no matter how much you have.
>>
What is a good book for a total beginner to programming to learn C#?
>>
>>54638333
In the year 2016, does it ever make sense to use int instead of long long in C?
>>
>>54638258
Pajeet pls
>>
>>54638258
store string in LIFO
create second LIFO
stack second LIFO with top of 1st LIFO
unstack first LIFO
repeat
add the ending character
done
>>
So I have a vector of chars, like so:
std::vector<char> data{};


It contains a few kB of data in total, now I have a few isntances of std::string and I'd like to search for these sequences in data, what function do I use?

For instance:
std::vector<char> data{'a', 'b', 'c', 'd', 'e'};
std::string s{"bc"};
something_find(data, s); // returns iterator to second element or something
>>
>>54638333
Are you fucking retarded?
>>
>>54638452
#include <stack.h>
:^)
>>
>>54638404
Go learn the C syntax and then learn how to program simple programs in C++ after that you are ready to learn C++ classes and such, then move to OOP Java and Java in general, after you are done with that look up for C# videos on youtube, by that time you will master C# in no time (at most one week)

Thats the right approach.
>>
>>54638258
reverseString :: String -> String
reverseString = reverse
>>
>>54638399
>>54638408
>>54638433
Jesus fuck, just try it:

    tic ();

size_t N = 1000000000;
double p;
for ( size_t n = 0; n < N; ++n )
p = sin ( ( double ) n / ( double ) N );

toc ();


and

    tic ();

size_t N = 1000000000;
float p;
for ( size_t n = 0; n < N; ++n )
p = sin ( ( float ) n / ( float ) N );

toc ();


At least on my machine the first one is faster than the second one. And not just a little bit, it's 12 seconds vs 18 seconds.
>>
>>54638416
Half-assed, but that's the first thing that came to my mind:

auto chars = std::vector<char>{'a', 'b', 'c', 'd'};
auto str = std::string(chars.begin(), chars.end());
auto found = str.find("bc");

std::cout << chars[found] << std::endl;
>>
>>54638110
>mfw a physical copy of that book costs 67$ in my country
>mfw i have no face
>>
>>54638624
if you are going to learn to program, you either gonna git gud or gonna fail, if you fail, you fail you suck etc. if you git gud $ 67 is your hour wage and you should care, so my conclusion is that you are retarded.
>>
File: temp2.png (3 MB, 1920x1080) Image search: [Google]
temp2.png
3 MB, 1920x1080
been screwing around with images still
<--- the latest thing i have made a mess
>>
>>54638594
Nevermind, this one-liner does a better job:

auto chars = std::vector<char>{'a', 'b', 'c', 'd'};
auto str = std::string("bc");

auto it = std::search(chars.begin(), chars.end(), str.begin(), str.end());
>>
>>54638677
What exactly are you trying to do?
>>
File: temp.png (2 MB, 1920x1080) Image search: [Google]
temp.png
2 MB, 1920x1080
>>54638677
original one
>>
>>54638696
i tried doing RGB to HSV conversion - but i just put the values back as RGB
so H->R
S->G
V->B

im not sure the HSV stuff is correct though...
>>
>>54638665
Who's talking about learning how to program? I was just pointing the price of that book
Besides i already have it in pdf but it's comfier to have a physical copy
>>
Hey, uhm, sorry for interrupting, but I need to ask. I have read in your wiki that " the C programming language, second edition" is the best for learning C. However, I don't have any concepts nor experience in programming. So, is this book still good even for me as a beginner? I'm studing Mech Engineering, so you may have an idea. Thanks.
>>
>>54638737
It's outdated. "C Programming: A Modern Approach" is a better choice, and great for a beginner as well.
>>
>>54638737
C prog. By Kochan, helped me alot when i first started
>>
>>54638737
K&R doesn't teach programming, it teaches the C language to people assumed to already have some programming experience

not saying you can't learn from it, but it is not the best book if you've absolutely never programmed before
>>
Has anyone here tried using
https://facebook.github.io/reason/
yet?
>>
>>54638763
>>54638766
>>54638775
Thank you guys. I'll check those.
>>
>>54638812
definitely check out the book that other anon mentioned, A Modern Approach, also 'Pointers on C' is a really good textbook
>>
Dubs decide something trivial for me to program
>>
>>54638330
pro-tip: it's never worth trying to use a non native IDE to use a different language unless you are super duper power user. Use Eclipse for Java.
>>
>>54638523
Double is about 1 second slower for me compiling with MSVC (2015/14.0). The difference in size will matter if you're ever doing anything similar to this with SIMD intrinsics, since you'll be performing that instruction on twice as many floats at once.
>>
>>54638926
Given a number x, print the biggest prime number that is less than x.
>>
>>54638926
discrete fourier transform
>>
>>54638926
rolling for data visualization of average cock length by race.
>>
>>54638926
Interpreter for a dynamically typed lazily evaluated purely functional programming language.
>>
Just been making little experiments with the Phaser game library:
http://demos.neocities.org/matrix.html

>>54638928
Eclipse is fine languages other than Java
>>
>>54638926
a basic web server without gui...


...in assembly
>>
>>54638926
TRIANGLE FILL
>>
>>54638926
A simple function plotter
>>
>Want to learn vulkan
>AMD drivers don't support my laptop's gpu
Well fuckballs.
Software implementation when?
>>
[c#] why the fuck is this true?
inventory[i][j] = new Item(other.name, false, 1, false);
if (inventory[i][j]. == null)
Debug.Log("it's null");


It shouldn't ever write "it's null" but somehow it does,
why is this null?
>>
File: 14636837752050.jpg (43 KB, 604x603) Image search: [Google]
14636837752050.jpg
43 KB, 604x603
>>54638258
#include <stdio.h> 
int _strlen(char *str)
{
int res = 0;
char *temp = str;
while(*temp)
{
res++;
temp++;
}
return res;
}
void reverse(char *str)
{
printf("Normal: %s\n", str);
char temp;
int len = _strlen(str);
int halfLen = len/2;
for(int x = 0,y = len-1;x<halfLen;x++,y--)
{
temp = str[x];
str[x] = str[y];
str[y] = temp;
}
printf("Reversed: %s\n",str);
}

int main(void)
{

char inputString[] = "oh shit waddup";
reverse(inputString);
return 0;
}
>>
>>54639759
What's that extra dot for?
>>
>>54639759
I that a dot in the second line after [j]?
>>
>>54639805
accident, imagine it's not there
>>
a program to help people queuedodge cheaters in the world of warcraft.
>>
>>54638665
not the best investment to blow $67 on a stupid book if you're a poorfag
>>
>>54638926
liberal news site rss feed in python that also aggregates certain buzzwords from headlines and stores the stats
>>
>>54639824
precursor to buzzword bingo?
>>
>>54639819
Pastebin, please. Enough so that the error actually happens.
>>
Implementing a programming language. It's pretty complicated so I don't think I'll be self-hosted until Christmas.
>>
File: 1420773887075.jpg (52 KB, 640x480) Image search: [Google]
1420773887075.jpg
52 KB, 640x480
Ideas for a summer project? 1st year CS student looking to start some projects to pad my resume.
>>
>>54639898
fart mobile app
>>
>>54639889
what backend?
>>
File: sad_frog.jpg (7 KB, 316x202) Image search: [Google]
sad_frog.jpg
7 KB, 316x202
>ace first two interviews
>completely bomb the third
>to my surprise I get told that I did well and they want another interview on wednesday, they just need to check the interviewer's schedule first
>that was an hour and a half ago, I still have no time
>>
>>54639862
http://pastebin.com/eZ32720A

here you go.
btw inventoryCtrl.updateInventory(); checks inventory[][] and there that position is not null
>>
>>54639918
Is there anything but LLVM?
>>
>>54639920
>she
>>
>>54639938
call them back on monday
>>
I am trying to add my java mongo driver to the java class path from Eclipse. How do you do that?
>>
>literally nothing is being done to contain /pol/ anymore.
>literally every other post is pajeet this or poo-in-the-loo that

well, this board is done for.
>>
Novice trying to understand the rounding methods in Java. rint() and round() are easy enough but from what I understand, ceil() will round up to the nearest integer no matter what, so 1.2 will round up to 2.0. floor() is just the opposite, with something like 1.6 rounding down to 1.0.

However, the book I'm using shows the following:
Math.ceil(2.1) returns 4.0
Math.ceil(2.0) returns 2.0
Math.ceil(-2.0) returns -2.0
Math.ceil(-2.1) returns -2.0
Math.floor(2.1) returns 2.0
Math.floor(2.0) returns 2.0
Math.floor(-2.0) returns –2.0
Math.floor(-2.1) returns -4.0


The negatives I kind of understand, but why does ceil(2.1) return 4.0 if ceil(2.0) returns 2.0? Shouldn't the former return 3.0? Shouldn't they look more like http://www.javacodex.com/Math-Examples/Floor-and-Ceiling-Example ?
>>
Currently reading how to get a ray from OpenGL.

>>54639553
>neocities
Neat. I didn't know about this.

>>54638523
Try this test:
#define _GNU_SOURCE
#include <stdio.h>
#include <time.h>

double dubs[1000];
float floats[1000];
int main() {
struct timespec time;
clock_gettime(CLOCK_MONOTONIC,&time);
printf("%i.%li\n",time.tv_sec,time.tv_nsec);
for(int i = 0; i < 1000; i++)
dubs[i] = 1.0 / i;
clock_gettime(CLOCK_MONOTONIC,&time);
printf("%i.%li\n",time.tv_sec,time.tv_nsec);
for(int i = 0; i < 1000; i++)
floats[i] = 1.0 / i;
clock_gettime(CLOCK_MONOTONIC,&time);
printf("%i.%li\n",time.tv_sec,time.tv_nsec);
return 0;
}

Floats are 3 times faster on my machine.
>>
>>54639989
Probably errors in the book
>>
Why java is the best programming language?
>>
>>54640050
It's not.
>>
>>54640049
>Google book
>Homepage, Errata
>Page 122, line 2, Math.ceil(2.1) should return 3.0. Line 9, Math.floor(-2.1) should return -3.0. Line 7 in Section 4.2.4, Math.max(2.5, 3) should return 3.0.

Guess so, thought I was losing it. This book's really been letting me down in odd places the more I work through it.
>>
>>54639989
I think that book might be doing binary floor and ceiling for doubles -> doubles. 2.0 is exactly representable in binary as are all powers of 2 times any magnitude.
>>
>>54639940
Where is inventory defined? Is another thread fucking with it?
>>
>>54640050
It's an absolutely shit programming language. It's got nice tooling, infrastructure, libs, well-tuned and fast-performing virtual machine and all that though.
>>
>>54638258
def reverse_string(string): return string[::-1]

:^)
>>
>>54640114
found the solution.
Class Item was inheriting from MonoBehaviour, I forgot to remove that
>>
>>54640050
it's the best for large enterprise applications with many developers working on projects simultaneously because it has great support for OOP and is simple and easy to use so that all programmers can adhere to a consistent style with great ease. it's very safe while still being one of the highest performance languages.
>>
>>54638812
I learned programming on edX with the CS50 course from HarvardX. The teaching language is C (at least for the most part) and it's way more motivating than a book, with videos, shorts, and weekly assignments, which are all really well done.
You should really check it out.
>>
>>54638258
.data
str .word "git gud faggot"
.text
Lea Si, str //message itself
Mov Cx, 14 //length
Mov Bx, Cx
loop:
Mov AL,[Bx+Si]
Mov AH,0Eh
Int 10h
Dec Bx
Loop loop
Mov Ah, 0
Int 16h
Ret

import this to your code by doing __asm{code}. Change .data section into a variable ofc lel. You can thank me later
>>
>>54640201
.data should be "str .ascii "git gud faggot" sorry my bad
>>
>>54638523
The first one is faster because sin() takes a double, so the float version has to do a float -> double conversion before passing the argument in.
Use sinf() for a fair comparison.

Although calculating a single sine is not a particularly useful case.
Where you get speed ups from floats is when you're dealing with arrays of them - they will use half the memory (i.e double the cache utilization) and double the amount of simd work.

And doubles are essenrially useless, the cases where double orecision would be needed over floats are exceedingly rare, if you find yourself needing more precision than float you're most likely gonna want either fixed-point integers or arbtrary precision floats/fixed-point.
>>
why exactly does linus not want people to typedef structs?
>>
>>54640033
>Floats are 3 times faster on my machine.
It's not floats (at least on my machine). If you swap dubs[i] and floats[i] assignments the doubles will be faster. Caching gets into the game probably. Or branch prediction training or some other shit. But it's just the second loop that's faster.
>>
>PLEASE don't typedef structs in C, it needlessly pollutes the global namespace which is typically very polluted already in large C programs.
lol and Ctards don't want namespaces
>>
File: vomiting-guy.jpg (39 KB, 600x450) Image search: [Google]
vomiting-guy.jpg
39 KB, 600x450
>>54640033
>#define _GNU_SOURCE
>>
>>54640232
because people are stupid
>>
Why doesn't C have separate namespaces?
I'm pretty sure there's only 4, and that really sucks.

You got the structs, enums, which are all global, the global variables and the local block variable names.
>>
>>54639938
>an hour and a half
calm the fuck down my toad friend. the recruiter is probably busy painting her nails and online shopping.
>>
>>54638523
mobile devices don't even have cpu instructions for doubles
>>
>>54640232
Why don't you just read his fucking email?
One of the reasons afair was that he wants it to be explicit that an argument is a struct and not a *_t typedef over some scalar type or w/e.
>>
>>54640232
Autism, there is literally nothing wrong with typedef struct
>>
>>54640255
>using namespaces in C++ anyway
nice meme
>>
>>54640232
He wants to reserve typedefs for small opaque/handle types, so when he sees a typedefed non-standard type he knows it's only 4-8 bytes.
structs can be be large, and you need to be aware of how much stack space you use in kernel code.
>>
>>54640307
DKMM_dank_meme_kTard
>>
>>54640288
>doesn't C have separate namespaces
>there's only 4
/g/
>>
is a lisp machine better at executing lisp than say a >1990 cpu?
>>
>>54640265
Compile it without _GNU_SOURCE or _X_OPEN_SOURCE = some arbitrarily high enough number and see what happens boy.
>>
>>54640303
>literally
kids should leave /g/
>>
>>54640326
lol ktard cmen cshart
>>
>>54640288
Please say you're baiting.
>>
>>54640201
Good god that's garbage.
>>
>>54640342
no
>>
>>54640354
Give me something wrong then
>>
>>54640326
>not emulating namespaces in C with structs
stay pleb
>>
>>54640364
How?
>>
>>54640390
It's not Python
>>
>>54640288
Namespaces would fuck up the nice property of 1:1 mapping of binary symbol names which is what makes C so popular for system level libraries other languages can easily bind to.
>>
>>54640382
you still need a name prefix for the struct name and the functions
>>
>>54640406
>he can't into 8086
J U S T
>>
>>54640382
>>54640421
Just use a preprocessor hack
>>
>>54640288
Namespaces are useless.
>>
>>54640390
>8086-era shit on a fucking modern machine
>CAPITALIZING THE FIRST FUCKING CHARACTER OF EACH OPERATOR AND OPERAND
Really, you're the MOST autistic.
>>
>>54640457
your mother
>>
unsigned int foo = i != 0U ? bar[i - 1U] : 0U;


is this safe? bar[~0U] will not get dereferenced if i is 0U?
>>
>>54638926
AES algorithm
>>
>>54640618
it's safe
>>
>>54638926
Invert a binary tree
>>
>>54640618
Yeah. Is that default to 0 required behavior or a hack? You could do the subtraction and then check the unsigned offset for OoB.
size_t index = i - 1;
assert(index < len);
unsigned int foo = bar[i];
>>
>>54640457
Abstractions are useless, why don't we all just develop in ASM?
>>
>>54640731
>and then check
>assert
you don't know C, do you?
>>
>>54640549
Don't talk to my 8086 or my son 65c816 again
>>
>>54640759
>wife's son
ftfy
>>
>>54640752
What's wrong with assertions?
>>
>>54638926
Come on fags gimme something
>>
File: 2016-05-19-144136_802x631_scrot.png (523 KB, 802x631) Image search: [Google]
2016-05-19-144136_802x631_scrot.png
523 KB, 802x631
I've been making an image viewer where you can set and search for tags. Possibly not the most amazing program out there, but I enjoy it.
>>
>>54640837
do a fizzbuz without modulo operation
>>
hey /g/ i have a question:

in C++, how do i zero out a vector ?

i have this
std::vector <int> *my_array;


i tried this but it doesnt work

 memset(array, 0, array_size * sizeof(int)); 
>>
>>54640890
http://www.cplusplus.com/reference/algorithm/fill/
>>
>>54640253
You're right. Revised the test a little bit. With this test floats are twice the speed when compiled with -Ofast as one would expect. The order of the tests also don't seem to affect things.
#define _GNU_SOURCE
#include <stdio.h>
#include <time.h>
#define K 262144

double dubs[K];
float floats[K];
int main() {
struct timespec time;
clock_gettime(CLOCK_MONOTONIC,&time);
printf("%i.%li\n",time.tv_sec,time.tv_nsec);
for(int i = 0; i < K; i+=16) {
floats[i] = 1.0f / i;
floats[(i+1)] = 1.0f / (i+1);
floats[(i+2)] = 1.0f / (i+2);
floats[(i+3)] = 1.0f / (i+3);
floats[(i+4)] = 1.0f / (i+4);
floats[(i+5)] = 1.0f / (i+5);
floats[(i+6)] = 1.0f / (i+6);
floats[(i+7)] = 1.0f / (i+7);
floats[(i+8)] = 1.0f / (i+8);
floats[(i+9)] = 1.0f / (i+9);
floats[(i+10)] = 1.0f / (i+10);
floats[(i+11)] = 1.0f / (i+11);
floats[(i+12)] = 1.0f / (i+12);
floats[(i+13)] = 1.0f / (i+13);
floats[(i+14)] = 1.0f / (i+14);
floats[(i+15)] = 1.0f / (i+15);
}
clock_gettime(CLOCK_MONOTONIC,&time);
printf("%i.%li\n",time.tv_sec,time.tv_nsec);
for(int i = 0; i < K; i+=8) {
dubs[i] = 1.0 / i;
dubs[(i+1)] = 1.0 / (i+1);
dubs[(i+2)] = 1.0 / (i+2);
dubs[(i+3)] = 1.0 / (i+3);
dubs[(i+4)] = 1.0 / (i+4);
dubs[(i+5)] = 1.0 / (i+5);
dubs[(i+6)] = 1.0 / (i+6);
dubs[(i+7)] = 1.0 / (i+7);
}
clock_gettime(CLOCK_MONOTONIC,&time);
printf("%i.%li\n",time.tv_sec,time.tv_nsec);
return 0;
}
>>
>>54640890
>zero out
Do you mean set the vector back to 0 length or set all members to 0?
>>
>>54640860
I made something similar to that. It was a tree view of tags where you could combine AND and OR in a filter. I used it to sort porn. Yeah, I have deleted it and my porn folder since though.
>>
>>54640910
>twice as fast
>floats are twice as unrolled
wtf.
>>
>>54640928
>memset
>Do you mean set the vector back to 0 length
>>
>>54640928

i mean set all members to 0.

i tried std::fill but no chance
error: request for member ‘begin’ in ‘((Graph*)this)->Graph::my_array’, which is of non-class type ‘std::vector<int>*’
>>
>>54640910
Is that code supposed to be a joke or something?
>>
>>54640939
That's why it's twice as fast. L1 cache is 64 bytes. I unrolled that shit to utilize the entire L1 cache. i is just a value in registers so we got room for 16 floats.
>>
>>54640950
>non-class type ‘std::vector<int>*
Either replace .begin with ->begin or dereference whatever shit you're calling begin on like this (*shit).begin()
>>
>>54640953
No it's called loop unrolling. It's an optimization technique.
>>
>>54640890
fill(begin(*my_array), end(*my_array), 0);
>>
>>54638219
Yes. It is essentially a reference. If you have experience in c++ and c# then you pretty much know C.
>>
>>54640995
Don't compilers do that anyway? I mean, if there is a program constant that surely it shouldn't be difficult for a compiler to generate code to that effect.
>>
>>54638926
open source alternative to techsmith screen capture codec, when you have time left over also build a streaming app and platform for 60fps 1080p/4k with it
>>
>>54641014
thanks!
>>
>>54640949
Seems like he is new, asking a question like that. He probably doesn't know what he wants.

>>54640950
How about a fucking loop? Simple enough.

>>54640974
>L1 cache is 64bytes
What.... You mean a cache line? Also that's a retarded assumption. You do know unrolling increases performance? How about limiting the float loop to 8 just like the doubles. Also using -Ofast might vectorize your code, of course you'll be processing floats twice as fast. After you fix those issues retest. Or is that the point? XMMs and YMMs can hold two times the floats?
>>
>>54640890
Why the fuck would anyone want a pointer to a vector?

Do you understand the concept of managed resources?
>>
Writing a ray tracer in c++. Finding the normals on a cube is giving me a headache. I managed to implement recursive raytracing with refraction and reflections but I can't find which fucking side a point on a cube is on.
>>
>>54641054
That is the point. Floats are better because they're smaller.

And L1 cache is definitely 64 bytes on most home computers.
>>
>>54640860
>tfw I was planning on doing something similar but never got around to it
Do you mind sharing the source code? I'd like to see what method you used to store the tags.
>>
>>54641078
>64 bytes
kilobytes dude.
>>
>>54641077
Also add that I'm writing this all on a chromebook. Because fuck windows I don't have more than $200.
>>
>>54641091
This is the 90s pal
>>
>>54641108
I'm not your pal brah
>>
>>54641078
No... L1 cache lines are 64 bytes on x86_64 computers. The L1 cache is usually a few KB.
>>
>>54638333
Greater precision means greater error. Use only as much precision as you need.
>>
>>54641116
pal is a colour format dumbass
>>
>>54640910
This one actually has a difference between -mno-sse and -msse2. The speed difference seems pretty consistent with:

https://software.intel.com/sites/landingpage/IntrinsicsGuide/#techs=SSE,SSE2&text=_mm_div
>>
>>54641089
https://github.com/lehitoskin/ivy.git

It's written in Racket and it uses Racquel to access a sqlite database. Essentially I have a table for images and their associated tags so that I can grab the tags and display them in that text field you see in the screenshot. Then there's a second table for the tags themselves and a list of images that are associated with them, for easy tag searching.

If you'd like to see some specifics, I'd suggest looking at the db.rkt file.
>>
>>54641199
Also he is testing this with division. Which is one of the only operations where there is a difference in execution time between single and double precision on the x87.
>>
>>54638258
reverse :: [a] -> [a]
reverse [] = []
reverse (x:xs) = reverse xs ++ [x]


You're using Haskell, right? I mean it's 2016, who isn't...
>>
>>54641199
What differences are you seeing? I'm seeing the exact same output. I'm also using a 5 year old amd cpu though.
>>
>>54641280
that's a shitty reverse, even by haskell standards
>>
>>54641281
-mno-sse gives:
>1528553, floats
>1636849, doubles
-msse2 gives:
>673979, floats
>1336475, doubles

I'm using a Haswell CPU.
>>
>>54641281
One is using XMM registers and the other is using the x87 stack. XMM registers are an order of magnitude faster. You've obviously fucked something up.
>>
>>54641280
reverse' fold1 (flip (:)) []
>>
>>54641349
Neat. I guess -mno-sse makes the performance computation bound rather than memory bound.
>>
>>54641280
fucked that up
reverse' = foldl (flip (:)) []
>>
Is it possible to write this in one line in python 3:

import os
from os import path
>>
>>54638256
>girls
>>
I have a C++ question.

I have a function something like

template <typename T>
int foo(T *__restrict x, T*__restrict y){...}


I give it a C wrapper:

int foo_int(int *__restrict x, int *__restrict y){
return foo<int>(x, y);
}


Naturally I pass two int*'s into foo_int. But for some insane reason, T gets interpreted as double. Even more confusingly, if I add

printf("%d\n", x[0]);
std::cout << typeid(x).name() << '\n';


to foo, the printf statement generates a warning about T being interpreted as double, but the typeid shows Pi.

What the hell?
>>
>>54641443
import os.path
>>
>>54641507
Does this import the os namespace too?
>>
>>54641519
no. import os brings in both but you have to type os.path every time you want to use path
>>
>>54641502
It isn't a c++ issue as much as a C issue. C doesn't transform data when you cast pointers. You just get permission to reinterpret them as another data type.
>>
>>54641519
no in which case
import os
import os.path
[\code]

which reads as i need two modules. One called os and the other os.path
>>
/dpt/ how often to you actually code to make your life easier
>>
>>54641502
Expected behaviour? %d kind of means expect a double no?
>>
>>54641075
to use iterators
>>
>>54641581
No data is meant to be transformed? I don't understand what you're saying.

>>54641614
No, %d for int.
>>
Can somebody here explain this to me in english?

https://en.wikipedia.org/wiki/Fortune%27s_algorithm
>>
>>54641646
Oh I'm confused then. Post your code. I thought you were passing pi to foo_int, which when you cast (*int)(&pi) you're not truncating it to 3.
>>
>>54641646
Use %i
>>
>>54641674
No no, Pi is "pointer to int". It's the value printed by the typeid line (which I add to the foo function). Basically I pass int* to x and y in the C wrapper, but when they make it to the template function, they're suddenly both interpreted as double*.

Can't paste the real code because it's open source and I can't be identified as a person who posts on 4chan, unfortunately.
>>
>>54641223
Interesting, thanks.
>>
>>54641673
Ooh that one is hard to explain. That line is used with the points to the left of it to construct parabolas, and boundaries are marked where the parabolas intersect is the gist.
>http://jwilson.coe.uga.edu/EMAT6680Fa09/Gonterman/Gonterman6/Gonterman6.html

>>54641675
%i and %d are the same thing you idiot.

>>54641718
Oh rip.
>>
>>54640953
it looks stupid but it actually works. every iteration of a for loop takes three operations - i<k, (i<k) == true and i++ - in addition to their contents. fewer iterations means fewer operations, in this case 45 fewer operations per 16 iterations
>>
>>54638110
#include <stdio.h>

int main(){

int c = 5, d;
d = ++c + ++c + ++c + ++c + ++c + ++c + ++c + ++c + ++c + ++c + ++c + ++c;

printf("%d\n", d);

return 0;

}


How much is d?
>>
>>54641765
3
>>
>>54641765
17 * 12 no? x++ and ++x are stupid operators anyway. Their only use is saving 1 character of typing in a loop.
>>
>>54641765
17 * 18 / 2 - 5 * 6 /2 = 17 * 9 - 15 = 15 * 8 + 18 = 138
>>
>>54641803
No. They call the increment assembly instruction rather than setting up an addition.
>>
>>54641809
+1 it's 139
>>
>>54641735
Thanks for the link, I didn't get how to construct parabolas
>>
>>54641765
Stop posting this, you fucking retard.
It's undefined behaviour so any result is completely meaningless.
>>
>>54641822
That's what -Ofast is for.
>>
>>54641861
>Ofast
but if we're talking ansi c here plus the fact that not everybody is using gcc
>>
>>54641844
It's perfectly valid c. and the answer is 139.
>>
>>54641902
no, see >>54641798
>>
>>54641890
>ansi c
>increment assembly operation
Why are you assuming everything C is compiled to has an increment operation?
>>
>>54641822
>They call
>>
>>54641765
>undefined behavior meme
:^)
>>
>Known, compile-time UB should result in an compilation error
Y/N?
>>
>>54641902
>It's perfectly valid c
You clearly don't know anything about C.
http://www.open-std.org/jtc1/sc22/WG14/www/docs/n1570.pdf
>J.2 Undefined behavior
>Page 559
>A side effect on a scalar object is unsequenced relative to either a different side effect on the same scalar object or a value computation using the value of the same scalar object
>>
What language will let me read a MIDI stream and figure out which note is being played?

I use VB, Python and a bunch of web dev stuff.

Can VB do it?
>>
>>54641995
there's no such thing
>>
>>54642029
try the weeb dev stuff
>>
what's the best beginner python textbook?
>>
>>54640033
>double dubs[1000];
>0033
>1000
>>
File: Screenshot_128.jpg (42 KB, 447x483) Image search: [Google]
Screenshot_128.jpg
42 KB, 447x483
How would I handle reading '>>' vs. '>' ?
Like, how would I get it to read the next character whenever it first reads '>' ?
>>
>>54642237
Do you know what you are doing? Maybe try researching a bit.
>>
>>54642237
Maximum munches mi muchacho
>https://en.wikipedia.org/wiki/Maximal_munch
>>
>>54642237
You need a lookahead.
>>
>>54642237
there are tools that can turn grammars into parser code, no need to reinvent the whee. if you really want to do it yourself look into LL(k) parsing, long story short your grammar is not LL(1) so you need to do look-ahead
>>
I'm trying to create some PCM music using C, and I want to import some samples.

How do I convert several 1.25s samples from 44100/24-bit stereo to 8000/8-bit mono?
>>
>>54642309
Careful not to fall for this. Writing parsers is one of the best things out there. Nobody is using parser generators for serious compilers.

pub fn lex(chars: &mut CharStream) -> Result<Option<S<Token>>> {
let next = &[chars.peek_or_nil(0),
chars.peek_or_nil(1)];

macro_rules! lex {
($size:expr, $token:ident) => {
return lex_sized(chars, $size, Token::$token);
}
}

match next {
b"::" => lex!(2, ColonColon),
b"&&" => lex!(2, AndAnd),
b".." => lex!(2, DotDot),
b"=>" => lex!(2, DoubleArrow),
b"==" => lex!(2, EqEq),
b">=" => lex!(2, GreaterEq),
b"<=" => lex!(2, LessEq),
b"!=" => lex!(2, NotEq),
b"||" => lex!(2, OrOr),
b"->" => lex!(2, SingleArrow),
_ => { },
}

match next[0] {
b'[' => lex!(1, LeftBracket),
b']' => lex!(1, RightBracket),
b'{' => lex!(1, LeftBrace),
b'}' => lex!(1, RightBrace),
b'(' => lex!(1, LeftParen),
b')' => lex!(1, RightParen),
b';' => lex!(1, Semicolon),
b',' => lex!(1, Comma),
b'*' => lex!(1, Star),
b'/' => lex!(1, Slash),
b'@' => lex!(1, At),
b'%' => lex!(1, Percent),
b'+' => lex!(1, Plus),
b'#' => lex!(1, Hash),
b':' => lex!(1, Colon),
b'&' => lex!(1, And),
b'.' => lex!(1, Dot),
b'=' => lex!(1, Eq),
b'>' => lex!(1, Greater),
b'<' => lex!(1, Less),
b'-' => lex!(1, Minus),
b'!' => lex!(1, Exclamationmark),
_ => Ok(None)
}
}

fn lex_sized(chars: &mut CharStream, skip: usize,
token: Token) -> Result<Option<S<Token>>> {
let span_lo = chars.span_pos();
chars.skip(skip);
let span_hi = chars.span_pos();
let span = Span::new(span_lo, span_hi);
Ok(Some(S::new(span, token)))
}
>>
>>54642335
Why not use a tool when it is available to you? Why don't "serious compilers" use parser generators? Only downside I can think of is if you want to do something that cant be carried out by a context free grammar.
>>
>>54642442
>Why don't "serious compilers" use parser generators?
Supposedly because they don't generate good error messages. Writing parsers is very easy. Once you've written one, you can write another one in your sleep.
>>
>>54642442
LALR grammars give terrible error messages.
>>
>>54642459
Ok that might be fair. When I played with them, I didnt bother with error messages. Though I think that you can still edit the code to generate the messages you wan't.
>>
>>54638209
Is that Vine?
>>
700+ lines into this ast.c file, and I haven't used a single for loop or while loop!
>>
>>54642816
That's good. Careful not to overflow your stack.
>>
>>54638110
As a C programmer who has no experience with OOP whatsoever how am I supposed to approach C++?
>>
>>54642816
could you post the source code?
>>
>>54642816
>haven't used a single for loop or while loop!

so you're just calling methods ? or what?
>>
How do I play 2 PCM audio samples simultaneously?

/* this produces static */
unsigned char byte = (beat[i] & rhythm1[i]);
fwrite(&byte, 1, 1, stdout);

/* this produces a high pitched whining noise */
unsigned char byte = (i % 2) ? beat[i] : rhythm1[i];
fwrite(&byte, 1, 1, stdout);
>>
>>54642973
ALSA does not provide a mixer. If you need to play multiple audio streams at the same time, you need to mix them together on your own.

The easiest way this can be accomplished is by decoding the WAV files to float samples, add them, and clip them when converting them back to integer samples.

Alternatively, you can try to open the default audio device (and not a hardware device like "hw:0") multiple times, once for each stream you wish to play, and hope that the dmix ALSA plugin is loaded and will provide the mixing functionality.
>>
>>54642973
you need to use threading anon. If that's C++ it should be easy, if not it's you're on your own
>>
>>54640746
Abstractions are not useless.
Namespaces are useless.
>>
Is Go a bad language to learn for general programming?
>>
>>54642962
>methods
>>
>>54643051
it's not the most harmful but it's not as useful as java or C++
>>
>>54643051
No. Go is an audaciously simple language. It can be considered a work of art for that reason alone.
>>
>>54643051
i'm starting to get interested in Go I have to admit
>>
>>54643062
xD
>>
>>54640228
>And doubles are essenrially useless, the cases where double orecision would be needed over floats are exceedingly rare
I'm mainly writing physical simulations and I simply never use floats, ever. When I try to be smart about it I usually end up with worse performance, god knows why.
>>
I still have no idea how I didn't blow this last interview.

I forgot whether range(0, x) goes from 0 to x or 0 to x - 1 and I failed the first SQL question by mixing up ORDER BY and GROUP BY
Thread replies: 255
Thread images: 15

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

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.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.