LogoLogo
Actions SDKGiza CLIDatasetsAgents
main
main
  • 👋Welcome
    • Orion
    • Why Validity ML?
  • 🧱Framework
    • Get Started
    • Contribute
    • Compatibility
    • Numbers
      • Fixed Point
        • fp.new
        • fp.new_unscaled
        • fp.from_felt
        • fp.abs
        • fp.ceil
        • fp.floor
        • fp.exp
        • fp.exp2
        • fp.log
        • fp.log2
        • fp.log10
        • fp.pow
        • fp.round
        • fp.sqrt
        • fp.sin
        • fp.atan
        • fp.sign
      • Complex Number
        • complex.acos
        • complex.acosh
        • complex.arg
        • complex.asin
        • complex.asinh
        • complex.atan
        • complex.atanh
        • complex.conjugate
        • complex.cos
        • complex.cosh
        • complex.exp
        • complex.exp2
        • complex.from_polar
        • complex.img
        • complex.ln
        • complex.log2
        • complex.log10
        • complex.mag
        • complex.new
        • complex.one
        • complex.pow
        • complex.real
        • complex.reciprocal
        • complex.sin
        • complex.sinh
        • complex.sqrt
        • complex.tan
        • complex.tanh
        • complex.to_polar
        • complex.zero
    • Operators
      • Tensor
        • tensor.new
        • tensor.at
        • tensor.min_in_tensor
        • tensor.min
        • tensor.max_in_tensor
        • tensor.max
        • tensor.stride
        • tensor.ravel_index
        • tensor.unravel_index
        • tensor.reshape
        • tensor.transpose
        • tensor.reduce_sum
        • tensor.argmax
        • tensor.argmin
        • tensor.matmul
        • tensor.exp
        • tensor.log
        • tensor.equal
        • tensor.greater
        • tensor.greater_equal
        • tensor.less
        • tensor.less_equal
        • tensor.abs
        • tensor.neg
        • tensor.ceil
        • tensor.cumsum
        • tensor.sin
        • tensor.cos
        • tensor.asin
        • tensor.flatten
        • tensor.sinh
        • tensor.asinh
        • tensor.cosh
        • tensor.acosh
        • tensor.tanh
        • tensor.atan
        • tensor.acos
        • tensor.sqrt
        • tensor.or
        • tensor.xor
        • tensor.onehot
        • tensor.slice
        • tensor.concat
        • tensor.gather
        • tensor.quantize_linear
        • tensor.dequantize_linear
        • tensor.qlinear_add
        • tensor.qlinear_mul
        • tensor.qlinear_matmul
        • tensor.qlinear_concat
        • tensor.qlinear_leakyrelu
        • tensor.nonzero
        • tensor.squeeze
        • tensor.unsqueeze
        • tensor.sign
        • tensor.clip
        • tensor.identity
        • tensor.and
        • tensor.where
        • tensor.bitwise_and
        • tensor.bitwise_xor
        • tensor.bitwise_or
        • tensor.resize
        • tensor.round
        • tensor.scatter
        • tensor.array_feature_extractor
        • tensor.binarizer
        • tensor.reduce_sum_square
        • tensor.reduce_l2
        • tensor.reduce_l1
        • tensor.reduce_prod
        • tensor.gather_elements
        • tensor.gather_nd
        • tensor.reduce_min
        • tensor.shrink
        • tensor.reduce_mean
        • tensor.pow
        • tensor.is_nan
        • tensor.is_inf
        • tensor.not
        • tensor.erf
        • tensor.reduce_log_sum
        • tensor.reduce_log_sum_exp
        • tensor.unique
        • tensor.compress
        • tensor.layer_normalization
        • tensor.scatter_nd
        • tensor.dynamic_quantize_linear
        • tensor.optional
        • tensor.reverse_sequence
        • tensor.split_to_sequence
        • tensor.range
        • tensor.hann_window
        • tensor.hamming_window
        • tensor.blackman_window
        • tensor.random_uniform_like
        • tensor.label_encoder
      • Neural Network
        • nn.relu
        • nn.leaky_relu
        • nn.sigmoid
        • nn.softmax
        • nn.softmax_zero
        • nn.logsoftmax
        • nn.softsign
        • nn.softplus
        • nn.linear
        • nn.hard_sigmoid
        • nn.thresholded_relu
        • nn.gemm
        • nn.grid_sample
        • nn.col2im
        • nn.conv_transpose
        • nn.conv
        • nn.depth_to_space
        • nn.space_to_depth
      • Machine Learning
        • Tree Ensemble Classifier
          • tree_ensemble_classifier.predict
        • Tree Ensemble Regressor
          • tree_ensemble_regressor.predict
        • Linear Classifier
          • linear_classifier.predict
        • Linear Regressor
          • linear_regressor.predict
        • SVM Regressor
          • svm_regressor.predict
        • SVM Classifier
          • svm_classifier.predict
        • Sequence
          • sequence.sequence_construct
          • sequence.sequence_empty
          • sequence.sequence_length
          • sequence.sequence_at
          • sequence.sequence_empty
          • sequence.sequence_erase
          • sequence.sequence_insert
          • sequence.concat_from_sequence
        • Normalizer
          • normalize.predict
  • 🏛️Hub
    • Models
    • Spaces
  • 🧑‍🎓Academy
    • Tutorials
      • MNIST Classification with Orion
      • Implement new operators in Orion
      • Verifiable Linear Regression Model
      • Verifiable Support Vector Machine
      • Verifiable Principal Components Analysis
      • Provable MLR: Forecasting AAVE's Lifetime Repayments
Powered by GitBook
On this page
  • Data types
  • Fixed Trait
  • Arithmetic & Comparison operators

Was this helpful?

Edit on GitHub
  1. Framework
  2. Numbers

Fixed Point

PreviousNumbersNextfp.new

Last updated 1 year ago

Was this helpful?

This library has been modified from library by and adjusted to match with other fixed point implementations.

This API provides basic some operations for signed fixed point numbers. Fixed point numbers are represented as a struct with a magnitude and a sign.

The magnitude represents the absolute value of the number, and the sign indicates whether the number is positive or negative.

struct FP8x23 {
    mag: u32,
    sign: bool
}

Data types

Orion supports currently these fixed point types:

Data type
dtype

Q8.23

FP8x23

Q16.16

FP16x16

Q32.32

FP32x32

Q64.64

FP64x64

Fixed Trait

use orion::numbers::fixed_point::core::FixedTrait;

Fixed trait defines the operations that can be performed on a fixed point.

function
description

Constructs a new fixed point instance.

Creates a new fixed point instance with the specified unscaled magnitude and sign.

Creates a new fixed point instance from a felt252 value.

Returns the absolute value of the fixed point number.

Returns the smallest integer greater than or equal to the fixed point number.

Returns the value of e raised to the power of the fixed point number.

Returns the value of 2 raised to the power of the fixed point number.

Returns the largest integer less than or equal to the fixed point number.

Returns the natural logarithm of the fixed point number.

Returns the base-2 logarithm of the fixed point number.

Returns the base-10 logarithm of the fixed point number.

Returns the result of raising the fixed point number to the power of another fixed point number.

Rounds the fixed point number to the nearest whole number.

Returns the square root of the fixed point number.

Returns the arccosine (inverse of cosine) of the fixed point number.

Returns the arccosine (inverse of cosine) of the fixed point number faster with LUT.

Returns the arcsine (inverse of sine) of the fixed point number.

Returns the arcsine (inverse of sine) of the fixed point number faster with LUT.

Returns the arctangent (inverse of tangent) of the input fixed point number.

Returns the arctangent (inverse of tangent) of the input fixed point number faster with LUT.

Returns the cosine of the fixed point number.

Returns the cosine of the fixed point number fast with LUT.

Returns the sine of the fixed point number.

Returns the sine of the fixed point number faster with LUT.

Returns the tangent of the fixed point number.

Returns the tangent of the fixed point number faster with LUT.

Returns the value of the inverse hyperbolic cosine of the fixed point number.

Returns the value of the inverse hyperbolic sine of the fixed point number.

Returns the value of the inverse hyperbolic tangent of the fixed point number.

Returns the value of the hyperbolic cosine of the fixed point number.

Returns the value of the hyperbolic sine of the fixed point number.

Returns the value of the hyperbolic tangent of the fixed point number.

Returns the element-wise indication of the sign of the input fixed point number.

Returns the error function of the input fixed point number computed element-wise.

Arithmetic & Comparison operators

FixedType implements arithmetic and comparison traits. This allows you to perform basic arithmetic operations using the associated operators. (+,+= -,-= *,*= / , /= ), as well as relational operators (>, >= ,< , <= , ==, != ).

Examples

fn add_fp_example() {
    // We instantiate two fixed point from here.
    // a = 1
    // b = 2
    let a = Fixed::new_unscaled(1, false);
    let b = Fixed::new_unscaled(2, false);

    // We can add two fixed point as follows.
    let result = a + b;

    assert(result == Fixed::new_unscaled(3), 'invalid result');
}
fn compare_fp_example() -> bool {
    // We instantiate two fixed point from here.
    // a = 42
    // b = -10
    let a = Fixed::new_unscaled(42, false);
    let b = Fixed::new_unscaled(10, true);

    // We can compare two fixed point as follows.
    return a > b;
}
>>> true

🧱
cubit
influenceth
fp.new
fp.new_unscaled
fp.from_felt
fp.abs
fp.ceil
fp.exp
fp.exp2
fp.floor
fp.ln
fp.log2
fp.log10
fp.pow
fp.round
fp.sqrt
fp.acos
fp.acos_fast
fp.asin
fp.asin_fast
fp.atan
fp.atan_fast
fp.cos
fp.cos_fast
fp.sin
fp.sin_fast
fp.tan
fp.tan_fast
fp.acosh
fp.asinh
fp.atanh
fp.cosh
fp.sinh
fp.tanh
fp.sign
fp.erf