KiCad PCB EDA Suite
Loading...
Searching...
No Matches
wide_int.h File Reference

128-bit integers for exact products of 64-bit coordinate deltas. More...

#include <bit>
#include <cmath>
#include <cstdint>
#include <math/vector2d.h>

Go to the source code of this file.

Namespaces

namespace  KIGEOM_WIDE
 

Typedefs

using KI_INT128 = __int128
 
using KI_UINT128 = unsigned __int128
 

Functions

double KIGEOM_WIDE::WordsToDouble (int64_t aHi, uint64_t aLo)
 Nearest double to hi * 2^64 + lo, ties to even.
 
double ToDouble (KI_INT128 aValue)
 
constexpr KI_INT128 CrossWide (const VECTOR2L &aA, const VECTOR2L &aB)
 Exact aA.x * aB.y - aA.y * aB.x.
 
constexpr KI_INT128 DotWide (const VECTOR2L &aA, const VECTOR2L &aB)
 Exact aA.x * aB.x + aA.y * aB.y.
 

Detailed Description

128-bit integers for exact products of 64-bit coordinate deltas.

Coordinates span 2^32 units, so deltas need 33 bits and their cross and dot products need 66. KI_INT128 holds those products exactly.

Definition in file wide_int.h.

Typedef Documentation

◆ KI_INT128

using KI_INT128 = __int128

Definition at line 91 of file wide_int.h.

◆ KI_UINT128

using KI_UINT128 = unsigned __int128

Definition at line 92 of file wide_int.h.

Function Documentation

◆ CrossWide()

KI_INT128 CrossWide ( const VECTOR2L & aA,
const VECTOR2L & aB )
constexpr

Exact aA.x * aB.y - aA.y * aB.x.

Never overflows for any int64 components.

Definition at line 104 of file wide_int.h.

References VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), CalcArcCenter(), KIGEOM::OrientationSign(), and SEG::SquaredDistance().

◆ DotWide()

KI_INT128 DotWide ( const VECTOR2L & aA,
const VECTOR2L & aB )
constexpr

Exact aA.x * aB.x + aA.y * aB.y.

Overflows only when all four components are INT64_MIN.

Definition at line 113 of file wide_int.h.

References VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), and BOOST_AUTO_TEST_CASE().

◆ ToDouble()