Skip to content

Conversation

aayush0325
Copy link
Member

Resolves #3336

Description

What is the purpose of this pull request?

This pull request:

  • adds constants/float32/max-safe-nth-lucas

Related Issues

Does this pull request have any related issues?

This pull request:

Questions

Any questions for reviewers of this pull request?

No.

Other

Any other information relevant to this pull request? This may include screenshots, references, and/or implementation notes.

No.

Checklist

Please ensure the following tasks are completed before submitting this pull request.


@stdlib-js/reviewers

@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label Dec 5, 2024
@stdlib-bot
Copy link
Contributor

stdlib-bot commented Dec 5, 2024

Coverage Report

Package Statements Branches Functions Lines
constants/float32/max-safe-nth-lucas $\color{green}51/51$
$\color{green}+100.00\%$
$\color{green}1/1$
$\color{green}+100.00\%$
$\color{green}0/0$
$\color{green}+100.00\%$
$\color{green}51/51$
$\color{green}+100.00\%$

The above coverage report was generated for the changes in this PR.

@aayush0325
Copy link
Member Author

aayush0325 commented Dec 8, 2024

I arrived at this value using the following code

function lucas(n) {
    if (n < 0) return null;
    if (n === 0) return 2;
    if (n === 1) return 1;
    
    let a = 2;
    let b = 1;
    let c;
    
    for (let i = 2; i <= n; i++) {
        c = a + b;
        a = b;
        b = c;
    }
    return b;
}

const MAX_SAFE_FLOAT32 = 16777215; // taken from @stdlib/constants/float32/max-safe-integer

for (let n = 0; n < 100; n++) {
    const lucasValue = lucas(n);
    
    if (lucasValue > MAX_SAFE_FLOAT32) {
        console.log(`Max safe n: ${n-1}`);
        console.log(`Last safe Lucas value: ${lucas(n-1)}`);
        console.log(`First unsafe Lucas value: ${lucasValue}`);
        break;
    }
}

which gave the output

Max safe n: 34
Last safe Lucas value: 12752043
First unsafe Lucas value: 20633239

@kgryte kgryte added the Feature Issue or pull request for adding a new feature. label Dec 13, 2024
Signed-off-by: Athan <kgryte@gmail.com>
Copy link
Member

@kgryte kgryte left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks, @aayush0325!

@kgryte kgryte added Ready To Merge A pull request which is ready to be merged. and removed Needs Review A pull request which needs code review. labels Dec 13, 2024
@stdlib-bot
Copy link
Contributor

PR Commit Message

feat: add `constants/float32/max-safe-nth-lucas`

PR-URL: https://github.com/stdlib-js/stdlib/pull/3337
Closes: https://github.com/stdlib-js/stdlib/issues/3336

Co-authored-by: Athan Reines <kgryte@gmail.com>
Co-authored-by: aayush0325 <aayush25khanna@gmail,com>
Reviewed-by: Athan Reines <kgryte@gmail.com>
Signed-off-by: Athan <kgryte@gmail.com>

Please review the above commit message and make any necessary adjustments.

@kgryte kgryte merged commit ed63505 into stdlib-js:develop Dec 13, 2024
19 checks passed
@aayush0325 aayush0325 deleted the max-safe-nth-lucas branch December 13, 2024 05:04
@aayush0325 aayush0325 restored the max-safe-nth-lucas branch December 13, 2024 11:28
/**
* Macro for the maximum safe nth Lucas number when stored in single-precision floating-point format.
*/
#define STDLIB_CONSTANT_FLOAT64_MAX_SAFE_NTH_LUCAS 34
Copy link
Member Author

Choose a reason for hiding this comment

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

There is a typo here that must be fixed, should i reopen this PR and make a commit to fix this or should i make a new PR here @kgryte, I'm really sorry for this.

@aayush0325 aayush0325 deleted the max-safe-nth-lucas branch February 16, 2025 08:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature Issue or pull request for adding a new feature. Ready To Merge A pull request which is ready to be merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[RFC]: add constants/float32/max-safe-nth-lucas

3 participants