12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667(* SPDX-License-Identifier: MIT *)(* Copyright (C) 2023-2024 formalsec *)(* Written by the Smtml programmers *)typet=|F32ofint32|F64ofint64typeprinter=[`Pretty|`Hexadecimal|`NoType]lettype_of(n:t)=matchnwithF32_->Ty.(Ty_fp32)|F64_->Ty.(Ty_fp64)letcomparen1n2=match(n1,n2)with|F32i1,F32i2->Float.compare(Int32.float_of_bitsi1)(Int32.float_of_bitsi2)|F64i1,F64i2->Float.compare(Int64.float_of_bitsi1)(Int64.float_of_bitsi2)|F32_,F64_->-1|F64_,_->1letequal(n1:t)(n2:t):bool=comparen1n2=0letpp_numfmt=function|F32f->Fmt.pffmt"(f32 %F)"(Int32.float_of_bitsf)|F64f->Fmt.pffmt"(f64 %F)"(Int64.float_of_bitsf)letpp_hexfmt=function|F32f->Fmt.pffmt"(f32 0x%08lx)"f|F64f->Fmt.pffmt"(f64 0x%016Lx)"fletpp_no_typefmt=function|F32f->Fmt.pffmt"%F"(Int32.float_of_bitsf)|F64f->Fmt.pffmt"%F"(Int64.float_of_bitsf)letprinter=ref`NoTypeletset_default_printer:printer->unit=(:=)printerletget_default_printer():printer=!printerletppfmtv=match!printerwith|`Pretty->pp_numfmtv|`Hexadecimal->pp_hexfmtv|`NoType->pp_no_typefmtvletto_string(n:t):string=Fmt.str"%a"ppnletof_string(cast:Ty.t)value=matchcastwith|Ty_fp32->(matchfloat_of_string_optvaluewith|None->Fmt.error_msg"invalid value %s, expected float"value|Somen->Ok(F32(Int32.bits_of_floatn)))|Ty_fp64->(matchfloat_of_string_optvaluewith|None->Fmt.error_msg"invalid value %s, expected float"value|Somen->Ok(F64(Int64.bits_of_floatn)))|_->Fmt.error_msg"invalid value, expected num"letto_json(n:t):Yojson.Basic.t=`String(Fmt.str"%a"pp_no_typen)