Obtaining Min-Max Values for MLIR Data Types in C++

I’m working with a Type type that can be either a floating-point or an integer type, and my goal is to programmatically obtain arith.constant values representing the minimum and maximum possible values for this type using C++.
Could you please guide me on how to implement this?

Maybe you can find something useful here: ⚙ D156471 [mlir] Support fast-math friendly constants for identity value

1 Like

Thank you! This helps a lot.

Even though it is not related to current work, I’m wondering is there something like this for integer types? I’ve looked through APInt and APIntOps methods and couldn’t find anything like this – I guess because there is no “integer semantic”.

It seems like a general solution for this problem should exist. Like std::numberic_limits from the standard C++ but for MLIR types.

For APInt, you should be able to use something like: getMinValue, getSignedMinValue, getMaxValue, and getSignedMaxValue. (Look there https://github.com/llvm/llvm-project/blob/b59cf211a0965b91ce399aa79442819dfb14657a/llvm/include/llvm/ADT/APInt.h#L194)

1 Like

Yes, you’re right
I’ve overlooked them for some reason…
Thank you!

1 Like