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

[feat/fix/docs]: Improved on conversion code , length variable , asserts added #840

Open
wants to merge 45 commits into
base: master
Choose a base branch
from

Conversation

lazy-dude
Copy link

@lazy-dude lazy-dude commented Jul 8, 2021

Description of Change

References

Checklist

  • Added description of change
  • Added file name matches File name guidelines
  • Added tests and example, test must pass
  • Relevant documentation/comments is changed or added
  • PR title follows semantic commit guidelines
  • Search previous suggestions before making a new one, as yours may be a duplicate.
  • I acknowledge that all my contributions will be made under the project's license.

Notes:

@Panquesito7 Panquesito7 added the enhancement New feature or request label Jul 9, 2021
Copy link
Member

@Panquesito7 Panquesito7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution and for your time in making this PR. 👍
Please add documentation and tests as seen in the typical structure of a program.

@Panquesito7 Panquesito7 added Changes requested Proper Documentation Required requested to write the documentation properly labels Jul 9, 2021
@lazy-dude
Copy link
Author

I changed the code. Added tests and basic documentation. How should I send the file ?

@lazy-dude
Copy link
Author

I pushed the commit.

Copy link
Member

@Panquesito7 Panquesito7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make a PR per change. Also, your code is still not up to the repository standards.
Take your time, have a seat, and read them carefully. 🙂

@Panquesito7 Panquesito7 changed the title Improved on conversion code , length variable , asserts added [feat/fix/docs]: Improved on conversion code , length variable , asserts added Jul 16, 2021
Copy link
Member

@Panquesito7 Panquesito7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! 😄👍

conversions/binary_to_decimal.c Outdated Show resolved Hide resolved
conversions/binary_to_decimal.c Outdated Show resolved Hide resolved
conversions/binary_to_decimal.c Outdated Show resolved Hide resolved
conversions/binary_to_decimal.c Outdated Show resolved Hide resolved
conversions/binary_to_decimal.c Outdated Show resolved Hide resolved
conversions/binary_to_decimal.c Outdated Show resolved Hide resolved
conversions/binary_to_decimal.c Outdated Show resolved Hide resolved
conversions/binary_to_decimal.c Outdated Show resolved Hide resolved
*/
bool is_binary(intmax_t num)
{
int remainder = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using uint64_t for non-negative values (or their appropriate size: uint32_t, uint16_t, uint8_t) or int64_t for negative values. Requires adding the inttypes.h library. Check other parts of the code (reference). 🙂

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uintmax_t has the biggest length for machine running the code. I would prefer it over uint64_t which has a fixed size.

Comment on lines 14 to 19
// includes
#include <assert.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a one-line description of what the library/header is for (see the example below).

#include <stdio.h>    /// for IO operations
#include <assert.h>  /// for assert

lazy-dude and others added 11 commits July 17, 2021 13:21
@details
Added ", the"

Co-authored-by: David Leal <[email protected]>
Removed a line

Co-authored-by: David Leal <[email protected]>
Removed:
* Modified

Co-authored-by: David Leal <[email protected]>
Suggested:
main(void) -> main()

Co-authored-by: David Leal <[email protected]>
static void test

Co-authored-by: David Leal <[email protected]>
test arg doc

Co-authored-by: David Leal <[email protected]>
Comment for test()

Co-authored-by: David Leal <[email protected]>
Removed prototypes

Co-authored-by: David Leal <[email protected]>
Copy link
Member

@Panquesito7 Panquesito7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check the suggestions I made above if they're correct. If so, you can accept them. 🙂

conversions/binary_to_decimal.c Outdated Show resolved Hide resolved
Comment on lines 102 to 103


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

conversions/binary_to_decimal.c Outdated Show resolved Hide resolved
conversions/binary_to_decimal.c Outdated Show resolved Hide resolved
conversions/binary_to_decimal.c Outdated Show resolved Hide resolved
unsigned remainder;
uintmax_t decimal_number = 0, temp = 1;

int length = num_len(UINTMAX_MAX) - 1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using uint64_t for non-negative values (or their appropriate size: uint32_t, uint16_t, uint8_t) or int64_t for negative values. Requires using the inttypes.h library. Check other parts of the code (reference). 🙂

lazy-dude and others added 3 commits July 18, 2021 13:30
Removed space

Co-authored-by: David Leal <[email protected]>
Removed
// includes

Co-authored-by: David Leal <[email protected]>
Copy link
Member

@Panquesito7 Panquesito7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost there! 😄

conversions/binary_to_decimal.c Outdated Show resolved Hide resolved
Comment on lines 58 to 65
uint8_t remainder;
uintmax_t decimal_number = 0;
uint32_t temp = 1;

uint16_t length = num_len(UINTMAX_MAX) - 1;

assert(num_len(number) <= length);
assert(is_binary(number));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong indentation. Please fix it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's see if it works.

conversions/binary_to_decimal.c Outdated Show resolved Hide resolved
conversions/binary_to_decimal.c Outdated Show resolved Hide resolved
conversions/binary_to_decimal.c Outdated Show resolved Hide resolved
@Panquesito7 Panquesito7 removed the Proper Documentation Required requested to write the documentation properly label Jul 21, 2021
Copy link
Member

@Panquesito7 Panquesito7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost there! 😄

conversions/binary_to_decimal.c Outdated Show resolved Hide resolved
conversions/binary_to_decimal.c Outdated Show resolved Hide resolved
conversions/binary_to_decimal.c Outdated Show resolved Hide resolved
lazy-dude and others added 4 commits July 23, 2021 14:03
conversions/binary_to_decimal.c Outdated Show resolved Hide resolved
conversions/binary_to_decimal.c Outdated Show resolved Hide resolved
conversions/binary_to_decimal.c Outdated Show resolved Hide resolved
conversions/binary_to_decimal.c Outdated Show resolved Hide resolved
lazy-dude and others added 4 commits July 26, 2021 11:31
Removed a word

Co-authored-by: David Leal <[email protected]>
it to that

Co-authored-by: David Leal <[email protected]>
Added number

Co-authored-by: David Leal <[email protected]>
printf indent

Co-authored-by: David Leal <[email protected]>
Copy link
Member

@Panquesito7 Panquesito7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost there! 😄

conversions/binary_to_decimal.c Outdated Show resolved Hide resolved
conversions/binary_to_decimal.c Outdated Show resolved Hide resolved
Comment on lines 27 to 34
remainder = num % 10;
if (remainder == 0 || remainder == 1) {
num /= 10;
continue;
} else
return false;
}
return true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a bit of documentation here of what this code does.

Copy link
Member

@Panquesito7 Panquesito7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing work! Thank you for your dedication and contributions to our community! 😄🎉👍

@Panquesito7 Panquesito7 added approved Approved; waiting for merge and removed Changes requested labels Jul 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Approved; waiting for merge enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants