Skip to content

Remove unsafe without sacrificing speed by replacing i64 "exponent" with primitive enum #5

Closed
@Protowalker

Description

@Protowalker

By replacing the exponent field in the Number struct with two fields, one for an enum representing the different possible values and another for if the exponent is negative, you can remove the unsafe in float.rs:

unsafe { *TABLE.get_unchecked(exponent)}

can be replaced with

TABLE[exponent as usize]

with little to no speed change over the unsafe counterpart. In my (quite limited) testing, the unsafe code actually performed slower because of the dereference.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions