Opened 3 years ago

# Function math.log10 fails on large Sage integers while ok on Python ints

Reported by: Owned by: İsmail Dönmez minor sage-9.8 numerical Samuel Lelièvre N/A

Using SageMath version 9.0.beta10 via docker image.

```sage: x=4**10000
sage: from math import log10
sage: type(x)
<class 'sage.rings.integer.Integer'>
sage: log10(x)
inf
sage: log10(int(x))
6020.599913279624
```

Related:

• #29728: Meta-ticket: improve compatibility with the Python library

### comment:1 Changed 3 years ago by Samuel Lelièvre

Cc: Samuel Lelièvre added packages: standard → numerical

Confirmed in Sage 9.0.beta10.

Smallest Sage integers where this fails:

```sage: a = (2^54-1)*2^(1024-54)
sage: aa = int(a)
```

Import `log10` from the `math` module:

```sage: from math import log10
sage: [log10(x) for x in [0.01, 0.1, 1, 10, 100]]
[-2.0, -1.0, 0.0, 1.0, 2.0]
```

Computing `log10(aa)` works, but not `log10(a)`:

```sage: log10(aa)
308.25471555991675
sage: log10(a)
inf
```

No problem with `a - 1` as a Sage integer:

```sage: type(a-1)
<class 'sage.rings.integer.Integer'>
sage: log10(a-1)
308.25471555991675
```

Workaround:

```sage: RR(a).log()/(10.0).log()
308.254715559917
```

Note that Sage has a built-in method for the "number of digits" of an integer (a common reason for taking the base ten logarithm):

```sage: a.ndigits()
309
sage: a.ndigits(base=2)
1024
```
Last edited 3 years ago by Samuel Lelièvre (previous) (diff)

### comment:2 Changed 3 years ago by Samuel Lelièvre

Summary: sage.rings.integer.Integer is problematic → Function math.log10 fails on large Sage integers while ok on Python ints

More descriptive ticket title.

### comment:3 Changed 3 years ago by İsmail Dönmez

More of the same problem:

```sage: math.log2(a)
inf
sage: math.log(a)
inf
sage: math.isinf(a)
True
```

### comment:4 Changed 3 years ago by Erik Bray

Milestone: sage-9.0 → sage-9.1

Ticket retargeted after milestone closed

### comment:5 Changed 3 years ago by Matthias Köppe

Milestone: sage-9.1 → sage-9.2

Moving tickets to milestone sage-9.2 based on a review of last modification date, branch status, and severity.

### comment:6 Changed 2 years ago by Matthias Köppe

Milestone: sage-9.2 → sage-9.3

### comment:7 Changed 20 months ago by Samuel Lelièvre

Description: modified (diff)

### comment:8 Changed 19 months ago by Matthias Köppe

Milestone: sage-9.3 → sage-9.4

Moving to 9.4, as 9.3 has been released.

### comment:9 Changed 16 months ago by Matthias Köppe

Milestone: sage-9.4 → sage-9.5

### comment:10 Changed 12 months ago by Matthias Köppe

Milestone: sage-9.5 → sage-9.6

### comment:11 Changed 7 months ago by Matthias Köppe

Milestone: sage-9.6 → sage-9.7

### comment:12 Changed 2 months ago by Matthias Köppe

Milestone: sage-9.7 → sage-9.8
Note: See TracTickets for help on using tickets.