-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
math.big.bitwise_not is wrong #23792
Comments
Connected to Huly®: V_0.6-22203 |
Translating that into a runnable file: import math.big
v_a := big.integer_from_string('42834833')!
println(v_a.str())
v_b := v_a.bitwise_not()
println(v_b.str()) gives output of
|
Bitwise not changes a bit false into true and vice versa. When you print the numbers as hex seems every bit changes accordingly but I assume a smallest number of bytes is used to store a given big number. If you apply twice the bitwise not you get the same number again: import math.big
v_a := big.integer_from_string('42834833')!
println(v_a.hex())
v_b := v_a.bitwise_not()
println(v_b.hex())
v_c := v_b.bitwise_not()
println(v_c.hex())
assert v_a == v_c
import math.big
v_a := big.integer_from_string('428348336495867293045968102834596833948576820394959929312048682375978960')!
println(v_a.hex())
v_b := v_a.bitwise_not()
println(v_b.hex())
v_c := v_b.bitwise_not()
println(v_c.hex())
assert v_a == v_c
Even though, the bits of a negative number are tricky import math.big
v_a := big.integer_from_string('-1')!
println(v_a.hex())
v_b := v_a.bitwise_not()
println(v_b.hex())
v_c := v_b.bitwise_not()
println(v_c.hex())
assert v_a == v_c
How to know last |
what does |
btw, we have a separate .neg() method: import math.big
v_a := big.integer_from_string('42834833')!
println(v_a.str())
println(v_a.neg().str()) printing:
|
what are ruby's and python's equivalents? |
42834833 -> -42834834 |
python and ruby and bigmath from dlang. 42834833 -> -42834834 |
I should have asked a more detailed question, sorry. How do you invoke the corresponding operations, using GMP, and in python and ruby? |
v = 42834833
puts ~v
v = 42834833
print(~v)
void main()
{
import std.bigint;
import std.stdio: writeln;
BigInt b = "42834833";
writeln(~b);
}
package main
import (
"fmt"
"math/big"
)
func main() {
v := big.NewInt(42834833)
fmt.Println(new(big.Int).Not(v))
}
#include <stdio.h>
#include <gmp.h>
int main() {
mpz_t v;
mpz_init(v);
mpz_set_str(v, "42834833", 10);
mpz_com(v, v);
gmp_printf("%Zd\n", v);
mpz_clear(v);
return 0;
} |
|
Describe the bug
My test framework against
gmp
found issue in %subj%.Please check yourself and fix.
Reproduction Steps
Expected Behavior
math and big.math should return the same numbers on small input.
Current Behavior
please check why vlang returns wrong (?) result against python and ruby too.
Possible Solution
No response
Additional Information/Context
No response
V version
V 0.4.9 5376a55
Environment details (OS name and version, etc.)
Note
You can use the 👍 reaction to increase the issue's priority for developers.
Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.
The text was updated successfully, but these errors were encountered: