Skip to content

Preposterous proposition #7

@namark

Description

@namark

Consider the following IEEEish assumption:
The widest floating point type can't exactly represent a bigger range of integers than the widest integer type. (that is, if we exceed the limits of widest int we're in a zone that is definitely not precise enough to have a fractional part, since it's not even good enough for integers)

I understand that this is quite dubious, almost unacceptable and nearly heretical, but look at my glorious trunc!

template <typename IntMax = std::intmax_t, typename Float = float>
[[nodiscard]] constexpr
Float trunc(Float f)
{
	return abs(f) <= std::numeric_limits<IntMax>::max()
		? static_cast<IntMax>(f)
		: f;
}

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