Anonymous
wow it doesnt o.o
Anonymous
[Running ] Test: test_int
[Running OK] Test: test_int
[Running ] Test: test_int_flipped
[Running OK] Test: test_int_flipped
[Running ] Test: test_int_zero
[Running OK] Test: test_int_zero
[Running ] Test: test_long
[Running OK] Test: test_long
[Running ] Test: test_long_flipped
[Running OK] Test: test_long_flipped
[Running ] Test: test_long_zero
[Running OK] Test: test_long_zero
[Running ] Test: test_uint
[Running OK] Test: test_uint
[Running ] Test: test_uint_flipped
[Running OK] Test: test_uint_flipped
[Running ] Test: test_uint_zero
[Running OK] Test: test_uint_zero
[Running ] Test: test_ulong
[Running OK] Test: test_ulong
[Running ] Test: test_ulong_flipped
[Running OK] Test: test_ulong_flipped
[Running ] Test: test_ulong_zero
[Running OK] Test: test_ulong_zero
Anonymous
would probs "overflow" if given zero
Anonymous
since x + 0 is x
Alviro Iskandar
i really suggest you to use builtin, it's fast
the compiler only needs to check for OF (overflow flag) on x86 if you use the builtin
https://godbolt.org/z/rMdxzz1vz
Alviro Iskandar
apart from that, it saves some hassle playing with complicated bit hacks
Vlad
Anonymous
wait, subtraction and division can be implemented via addition and multiplication right?
Anonymous
welp (uint)1 + ~(uint)1 + (uint)1 doesnt work, but (int)1 + ~(int)1 + (int)1 does
Anonymous
https://electronics.stackexchange.com/a/98023
Anonymous
Hello guys, is it possible for a for loop to execute if one variable is undeclared? Btw, I'm still a new in c programming
Vlad
Vlad
Doesn't mean it's gonna be fast
Vlad
Especially division
Anonymous
what would be a better way?
Vlad
Vlad
integer division cant overflow
Vlad
Just check for a zero
Anonymous
apparently it can
Anonymous
INT_MAX / -1
Anonymous
yea
Anonymous
INT_MIN / -1
Vlad
But that's like 2 cases total
Anonymous
-2147483648
Vlad
a / b 😂
It's probably could be made faster if you convert it to float
Vlad
Although some accuracy will suffer
Anonymous
welp, lets ignore division for now
Anonymous
how do i detect a subtraction overflow
Vlad
And you do basically everywhere
Anonymous
how would you detect it
klimi
if a is negative and b is negative but the result is positive
Anonymous
how would i detect that using bit shifting
klimi
oh i thought you wanted to do this in C, are you doing it in hardware?
Anonymous
hmmm
Anonymous
https://rextester.com/YWUQ96880
Anonymous
which one of these SHOULD overflow?
signed 1073741823 + 1073741823 = 2147483646 (overflowed: false)
signed 1073741824 + 1073741823 = 2147483647 (overflowed: false)
signed 1 + 2147483647 = -2147483648 (overflowed: true)
signed 1 + 1 = 2 (overflowed: false)
signed 1 + -1 = 0 (overflowed: false)
signed -1 + -1 = -2 (overflowed: false)
signed -1 + 1 = 0 (overflowed: false)
signed 1 + 2 = 3 (overflowed: false)
signed 1 + -2 = -1 (overflowed: false)
signed -1 + -2 = -3 (overflowed: false)
signed -1 + 2 = 1 (overflowed: false)
signed 2 + 1 = 3 (overflowed: false)
signed 2 + -1 = 1 (overflowed: false)
signed -2 + -1 = -3 (overflowed: false)
signed -2 + 1 = -1 (overflowed: false)
Grigoriy
I write volatile bool* b;. Is b a pointer to volatile boolean variable or it is a volatile pointer to boolean variable?
Pavel
Vlad
Grigoriy
Thanks
.
hi guys, i cant understand where my mistake is. can you fix it?
.
C code to find the sum of the principal diagonal of a 10x10 matrix consisting of random numbers from 1 to 10
.
#include <stdio.h>
#include<conio.h>
#include<time.h>
int main ()
{
srand(time(NULL));
int n, i, j, sum;
sum =0;
int mat[i][j];
for(i=1;i<=n;i++) {
for(j=1;j<=n;j++)
{
n=rand()%100;
printf("%d. satir ,%d.sutun elemani : ",i,j);
mat[i][j]=n;
}}
for(i=0;i<=10;i++)
{
sum= sum+n;
printf("Sum : %d",mat[i][j]);
}
getch();
}
AKI David
AKI David
I tried printing out the values for i and J and this is the size of the matrix you made:
This is i 16 This is j 467
AKI David
so it's a 16x467 matrix
AKI David
AKI David
#include <stdio.h>
#include<conio.h>
#include<time.h>
int main ()
{
srand(time(NULL));
int n, i, j, sum;
sum =0;
int mat[10][10];
for(i=1;i<=n;i++) {
for(j=1;j<=n;j++)
{
n=rand()%100;
printf("%d. satir ,%d.sutun elemani : ",i,j);
mat[i][j]=n;
}}
for(i=0;i<=10;i++)
{
sum= sum+n;
printf("Sum : %d",mat[i][j]);
}
getch();
}
AKI David
.
Anonymous
Hello everyone. What if I going to make an application that should be written many different languages? Is there any alternative environments or applications to do this?
Pavel
Anonymous
abc
How can I read binary format of directory structure in c++? Is there any way?
abc
I trying to make application like winrar to make a single file which contains a directory
Hussein
It would be like this
[number of folders][pointer to folder 1 ][2][3]...
then each folder may have more folders implemented like how I showed you earlier then if there were files in the folder
remember pointer that pointed to folder 1 this will point to a table of the content of the each file then files will be written one after the other
abc
D
Quick question: How doI add two vectors into athird using std::transform? For example: v1{1,2,3}, v2{3,2,1} and after std::transform v3={4,4,4}.
Anonymous
Guys because in the books to avoid are those of Deitel
The
Can I share a project here for feedback?
The
https://github.com/MichaelDim02/lykan
Anonymous
transform(v1.begin(), v1.end(), v2.begin(), back_inserter(v3), [](auto i, auto j){i+j;});
Hussein
ax^2 + bx + c = 0
Hussein
this the mathmatical formula
Iwan
C Program to Find the Roots of a Quadratic Equation
https://www.programiz.com/c-programming/examples/quadratic-roots
Hussein
you just need to apply the formula that is tought in high school and you will get an answer right away
Maverick
hey . sorry I ask for a good and simple frame work for c++
Hussein
solve_equ( double a , double b , double c )
{
return ( -b * pow( pow( b , 2 ) - 4 * a * c , 0.5) ) / 2 * a
}
Hussein
Hussein
Maverick
Iwan