Skip to content

RealDoubleField: Exponentiation should not raise exceptions #32963

Open
@mkoeppe

Description

@mkoeppe

(from #32779)

RDF contains infinities and NaNs, which can appear as results of arithmetic operations.

sage: RDF(1.0)/RDF(0.0)
+infinity
sage: RDF(0.0)/RDF(0.0)
NaN

This is consistent with RR:

sage: RR(1.0)/RR(0.0)
+infinity
sage: RR(0.0)/RR(0.0)
NaN

(but is in contrast to float, which gives ZeroDivisionError).

However, RealDoubleElement_gsl.__pow__ raises exceptions:

sage: RDF('0.0').__pow__(RDF('-1'))
ZeroDivisionError: 0.0 cannot be raised to a negative power
sage: RDF('-0.0').__pow__(RDF('-1'))
ZeroDivisionError: 0.0 cannot be raised to a negative power
sage: RDF('-1').__pow__(RDF('0.5'))
ValueError: negative number cannot be raised to a fractional power

... in contrast to the other arithmetic operations and in contrast to RR:

sage: RR('0.0').__pow__(RR('-1'))
+infinity
age: RR('-0.0').__pow__(RR('-1'))
-infinity
sage: RR('-1').__pow__(RR('0.5'))
6.12323399573677e-17 + 1.00000000000000*I

Moreover, many RDF element methods do not handle -0.0 correctly.

CC: @sagetrac-tmonteil @dimpase @videlec @tscrim @slel

Component: basic arithmetic

Author: Matthias Koeppe, ...

Branch/Commit: u/mkoeppe/realdoublefield__exponentiation_should_not_raise_exceptions @ cf5a248

Issue created by migration from https://trac.sagemath.org/ticket/32963

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions