mirror of
https://github.com/pgvector/pgvector.git
synced 2026-07-04 11:40:57 +08:00
Added casts between half to double precision [skip ci]
This commit is contained in:
36
src/half.c
36
src/half.c
@@ -298,6 +298,16 @@ Float4ToHalf(float num)
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert a float8 to a half
|
||||
*/
|
||||
static half
|
||||
Float8ToHalf(double num)
|
||||
{
|
||||
/* TODO Convert directly for greater accuracy */
|
||||
return Float4ToHalf((float) num);
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert textual representation to internal representation
|
||||
*/
|
||||
@@ -466,6 +476,32 @@ half_to_float4(PG_FUNCTION_ARGS)
|
||||
PG_RETURN_FLOAT4(f);
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert float8 to half
|
||||
*/
|
||||
PGDLLEXPORT PG_FUNCTION_INFO_V1(float8_to_half);
|
||||
Datum
|
||||
float8_to_half(PG_FUNCTION_ARGS)
|
||||
{
|
||||
float8 d = PG_GETARG_FLOAT8(0);
|
||||
half h = Float8ToHalf(d);
|
||||
|
||||
PG_RETURN_HALF(h);
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert half to float8
|
||||
*/
|
||||
PGDLLEXPORT PG_FUNCTION_INFO_V1(half_to_float8);
|
||||
Datum
|
||||
half_to_float8(PG_FUNCTION_ARGS)
|
||||
{
|
||||
half h = PG_GETARG_HALF(0);
|
||||
float f = HalfToFloat4(h);
|
||||
|
||||
PG_RETURN_FLOAT8((double) f);
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the L2 distance between half arrays
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user