Skip to content
This repository has been archived by the owner on Jan 12, 2024. It is now read-only.

Ceiling(NaN()) causes an overflow #1107

Open
weucode opened this issue Oct 24, 2022 · 2 comments
Open

Ceiling(NaN()) causes an overflow #1107

weucode opened this issue Oct 24, 2022 · 2 comments
Labels

Comments

@weucode
Copy link

weucode commented Oct 24, 2022

Describe the bug
The result of Lg with a non-positive parameter is NaN, so running the following program will cause overflow. The part of the output is shown below:

Unhandled exception. System.OverflowException: Arithmetic operation resulted in an overflow.

To Reproduce

namespace NameSpace {
	open Microsoft.Quantum.Intrinsic;
	open Microsoft.Quantum.Math;


	@EntryPoint()
	operation main() : Unit {
		let nIdxRegQubits = Ceiling(Lg(-1.0));
		// same as:let nIdxRegQubits = Ceiling(NaN());
		Message($"{nIdxRegQubits}");
	}
}

Expected behavior
Maybe a range check can be used to avoid it.

System information
operating system : Ubuntu 22.04 LTS

dotnet version : 6.0.400

QDK : 0.25.228311

@weucode
Copy link
Author

weucode commented Nov 14, 2022

It seems this API effect other APIs, one can be seen in microsoft/QuantumLibraries#570; if give targetError a value of 0.0, an overflow behavior will occur. It might be better to fix Ceiling rather than other high-level APIs.

@msoeken
Copy link
Member

msoeken commented Nov 15, 2022

Thanks @weucode for filing this. It would be better to return NaN in this case. The function is implemented in Microsoft/qsharp-runtime (see

function Ceiling(value : Double) : Int {
), so I am transferring the issue to that repository.

@msoeken msoeken transferred this issue from microsoft/QuantumLibraries Nov 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants