23,265 questions
- Bountied 0
- Unanswered
- Frequent
- Score
- Trending
- Week
- Month
- Unanswered (my tags)
0
votes
3
answers
99
views
If I subclass int, how to make arithmetic methods return the derived type?
I want to construct objects which support arithmetic operations and have extra methods, e.g:
class Timestamp(int):
def as_seconds(self):
return self / 90000
The extra method works:
>&...
4
votes
1
answer
109
views
How to evaluate arithmetic expression in pseudo‐SQL style (Lua 5.1)
In love2D I have a string that represents a mathematical expression, for example:
local expr1 = "[p35] div [p36]"
local expr2 = "((([p35]*100) div [p36]) mod 100)"
local params = {...
-1
votes
1
answer
116
views
Integer or Double vector? [duplicate]
print(krit)
names weight
1 may 36
2 mayer 49
3 mayo 35
4 mali 50
> mean(krit$weight)
[1] 42.5
> typeof(weight)
[1] "double"
> typeof(names)
[1] "character&...
Advice
1
vote
21
replies
407
views
Is there a reason why signed integer is used for the ssize_t?
From the man pages, I found that size_t has the range of 0 to SIZE_MAX, and ssize_t has the range of -1 to SSIZE_MAX. So, after printing those values on a 64bit system, I have the following results:
...
1
vote
2
answers
225
views
How to set int array pointer within for loop in c
The following code is trying to set the test array in the first for loop, but it can't be used in the second for loop.
int main()
{
int *test[3];
/** Try to set the array value one by ...
2
votes
1
answer
119
views
In python is there a way to get len with int data type and not and index-sized integer? [duplicate]
I working on a code where it is necessary to have large integers, here is a simplified version of it (len_class.py):
class BigLen():
def __len__(self):
return 10**100
However I'm running ...
4
votes
2
answers
180
views
How can I convert a char into an int within the range of 0 and 255 in C++
I am trying to make my own file compressor and some of the chars in the file that I am trying to compress are '�'.
I tried:
#include <iostream>
int main(){
std :: cout << (int)'�';
...
3
votes
2
answers
238
views
C treating variable declared to be a double as an int
I am trying to solve a problem posed in this question which asks that a program be written that calculates logarithms of numbers without including <math.h>.
I wrote the following program:
#...
4
votes
2
answers
192
views
integer comparision; difference in behavior between Clang and GCC 12
I'm seeing a strange (to me) difference in behavior between Clang and GCC when comparing an integer with its negation. Also, pre-v12 GCC behaves like Clang.
Code is below, but also here's a live link ...
3
votes
1
answer
109
views
How does Rust lexer handle the integer literal?
The following lex rules are copied from int_literal in docs of rust nightly.
INTEGER_LITERAL ->
( DEC_LITERAL | BIN_LITERAL | OCT_LITERAL | HEX_LITERAL ) SUFFIX_NO_E?
DEC_LITERAL -> ...
5
votes
1
answer
137
views
Conversion to int with Unicode strings
I recognized that int(unicode_string) sometimes gives obscure results.
E.g. int('᪐᭒') == 2.
>>> bytes('᪐᭒', 'utf-8')
b'\xe1\xaa\x90\xe1\xad\x92'
>>> [f'U+{ord(c):04X}' for c in '᪐᭒']
...
-4
votes
2
answers
127
views
In this python script that checks for integer values, why is one entry not removed? It's the letter x. Works for every other line [closed]
This script takes lines from a file of lottery numbers, and is supposed to check for errors. For example, in the following:
week 1;17,19,35,23,8,20,36
week 2;24,28,35,8,3,22
week x;23,29,38,1,35,18,25
...
0
votes
0
answers
62
views
Sum of integer data and numeric data is unexpected numeric value, R [duplicate]
Why is the sum of the iaea_mass_dat_trunc$AM_WN (integer) and iaea_mass_dat_trunc$AM_frac (numeric) 499496.6 for all results? How do I get the appropriate result (for example, the sum of the values in ...
5
votes
5
answers
423
views
Why Zero has no decimal integer spelling in C?
I am reading modern C, and on page 66, I come across following section:
Remember that value 0 is important. It is so important that it has a lot of equivalent
spellings: 0, 0x0, and ’0円’ are all the ...
1
vote
1
answer
148
views
How does typecasting between different sized integers work in C++?
Imagine: int full = static_cast<int>(uint8_t_var);
Does anything actually happen under the hood here? If you're on a machine with 64 bit registers, I assume that the higher bits of uint8_t_var ...