Skip to content
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

(chore) printing integers as integers instead of fields #2625

Closed
wants to merge 5 commits into from

Conversation

jtfirek
Copy link

@jtfirek jtfirek commented Sep 10, 2023

Description

I am working on a solution to #2401 and I have ran into a blocker on this.
Here is where I am blocked for reference:
https://github.com/jtfirek/noir/blob/6ec4d4aed7127738ac73b01d0ea411859a970bf4/crates/noirc_printable_type/src/lib.rs#L163-L168

Problem*

The implementation for this field element struct doesn't seem to currently have a way to cover field elements into a signed value. should I add an implementation for this?

https://github.com/noir-lang/acvm/blob/0d6656b0784e76047484c17a98d08d6913270cd0/acir_field/src/generic_ark.rs#L223-L238

@jtfirek jtfirek marked this pull request as draft September 10, 2023 23:38
@Savio-Sou
Copy link
Collaborator

Hi @jtfirek, thanks a lot for submitting the PR!

@vezenovm any thoughts on the problems raised?

@jfecher
Copy link
Contributor

jfecher commented Nov 3, 2023

@jtfirek signed integers are represented in two's complement so e.g.

let x: i8 = -1;
let y: i8 = -2;

dep::std::println(x);
dep::std::println(y);
dep::std::println(x as Field);
dep::std::println(x as Field);

Will print:

0xff
0xfe
0xff
0xfe

So if you want to print a signed integer from a field value like 0xff you can grab the integer value directly as a u128 then just cast it to a signed integer of the correct size - or more likely truncate it yourself since there are so many integer types. You can add an implementation for this conversion if you want or include it elsewhere in your PR.

Sorry for the long delay for a response!

@grasshopper47
Copy link
Contributor

grasshopper47 commented Nov 25, 2023

@jfecher @jtfirek see this PR: #3577

@Savio-Sou
Copy link
Collaborator

Superseded by #3577.

Thank you all for the contributions!

@Savio-Sou Savio-Sou closed this Nov 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants